Installing NUT on ESXi 4.1

The final battle in my quest for properly integrated UPS Monitoring was to get my ESXi 4.1 box into the mix.

Some rummaging around online turned up a NUT Client for ESXi 5 (french) which doesn’t work for ESXi 4, fortunately the same guy has also done a NUT Client for ESXi 4 (french) which will work, but takes some effort.

The tricky part is that it seems that the only way to customise an ESXi 4 install is via oem.tgz, whereas in ESXi 5 we have the concept of “packages”, I broke my ESXi box several times figuring out how to actually do this properly so I figure I might as well write it up for others (also it’s probably good to have a native English version rather than having to go through the peril of Google Translate.)

    Enable SSH access on your ESXi box;

  • Login to vSphere
  • Select host
  • Configuration -> Security Profile
  • Firewall -> Properties…
  • Remote Tech Support (SSH) -> Options…
  • Click Start

SSH into your ESXi box and do the following;

~ # cp /bootbank/* /altbootbank/ # not necessary but recommended, backs up your bootbank
~ # cp /bootbank/oem.tgz /bootbank/oem.tgz.orig
~ # cd /tmp
/tmp # mkdir oem
/tmp # cd oem
/tmp/oem # tar -zxf /bootbank/oem.tgz
/tmp/oem # cd ..
/tmp # wget
Connecting to (
oem.tgz              100% |*******************************| 40871  00:00:00 ETA
/tmp # cd oem/
/tmp/oem # tar -zxf ../oem.tgz

Once that’s done you’ve got a “merged” tree of the existing oem.tgz and the NUT oem.tgz, next step is to go edit etc/ups/upsmon.conf to add a MONITOR clause for your UPS, and then update etc/ups/ if you want email notifications (If you don’t want notifications, just comment out the NOTIFYCMD line in upsmon.conf).

Once you’re happy with the config you need to re-pack the oem.tgz, the trick here (took several attempts and one ESXi rebuild to get this right…) is that your .tgz must NOT have leading ./ in the paths, the way to do this is pretty simple;

/tmp/oem # tar -zcf /bootbank/oem.tgz bin/ etc/ lib/ oem.txt sbin/ usr/ var

Now reboot, and if all’s well ESXi will boot up happily, if it doesn’t consult the troubleshooting section below.

Once ESXi has booted up, SSH back in and run;

 ~ # upsmon
Network UPS Tools upsmon 2.4.3
UPS: compaq3kva@lodestone (slave) (power value 1)
Using power down flag file /etc/killpower

It you’re seeing that then it looks like you’re all good, now to test the shutdown script issue the following;

 ~ # upsmon -c fsd

ESXi should shut itself down shortly thereafter.

If that all works then you’re done.

If your ESXi box pink screens, you probably cocked up the oem.tgz, at the loading screen do a “Shift+O” and give the additional option “noOem”, this will prevent ESXi from loading the oem.tgz, then you can SSH back in and try again.

If the above doesn’t work then you’ve REALLY screwed something up (like say, when I DELETED the oem.tgz file… Protip: DON’T DO THAT) for that “Shift+R” will switch you over to the “altbootbank” (actually it swaps the contents of bootbank and altbootbank), which will revert you to the original state (assuming you did the backup as suggested in the above code), SSH in and try again.

If that doesn’t work you can boot the install CD, switch to a console with “Alt-F1” and copy the oem.tgz.orig file back to oem.tgz.

If that doesn’t work then you’ve done something REALLY special and I can’t help 😉

Morgan / 2016-11-09 / Uncategorized / 0 Comments

NUT for Windows – Gracefully Shutting Down VMWare Guests

After I got NUT sorted out on my *nix fleet it was time to bring my Windows box into the mix, I frequently run VM Guests on my workstation for various different tasks, basically unless it’s something that’s going to be providing an active service for an extended period I run it up in VMWare Player, any “servers” go on the ESXi box.

Because VMWare doesn’t gracefully shut down or suspend VM Guests when the host gets shut down there was the possibility of badness as a result of an abrupt windows shutdown in the event of a power failure, as such I wanted any Guests which happened to be running on my workstation to be gracefully shutdown (or rather suspended).

Initially I’d planned to do this with the VMWare VIX API, but in doing some digging into it and trying a few things I decided it was too much bother for the moment (it’s also, frankly, a pretty damn ugly interface), so we went to Plan B which was to screenscrape the output of vmrun to determine what VMs were active, then issue a suspend to each of them prior to shutting down the host.

This is what I ended up with (It’s called from a batch file which is called by upsmon), I’m kinda new to this PowerShell stuff, so this is pretty horrific, but it does the job.

cd "C:\Program Files (x86)\VMware\VMware VIX"
$vms = .\vmrun.exe -T player list
foreach($v in $vms)
	if ($v -like "*.vmx") {
		$stat = "Suspending " + $v;
		echo $stat;
		$vm = '"' + $v + '"';
		echo $vm;
		.\vmrun -T player suspend $vm

The only other minor hitch was that in order to be able to see the active VMs I needed to switch the Network UPS Tools service over to using my account rather than LocalSystem, but I figure that’s probably better anyway, least (or rather lesser) privilege and all of that.

Morgan / 2016-11-08 / Uncategorized / 0 Comments