Sunday, March 8, 2009

Getting FreeBSD to shutdown gracefully in VMware

FreeBSD hasn't been officially supported as a Guest OS by VMware Server for some years. As of the official VMware Server User's Guide as of Nov 2008, it isn't listed in the "Supported Guest Operating Systems" section. Strangely, the same document does include instructions for installing VMware Tools for FreeBSD.

So it works. Sort of. Except that the FreeBSD guest cannot shut down gracefully (empirically tested on some combinations of FreeBSD 6.x/7.x with VMware Server 1.x and 2.x).

Let me elaborate. By that I mean that:
  • "Power Off" or "Reset Guest" from the host is equivalent to yanking the power cord cord. It works.
  • "Shut Down Guest" from Host, or "shutdown -h" from Guest will end will gracefully shutdown the FreeBSD process, but not power-off the machine.
The trick is to use "shutdown -p" instead.

However, this is just a partial solution. It means that everytime you want to shutdown a FreeBSD Guest gracefully, you need to fire up a VMware console (and we all know how slow that is) or ssh to the guest. I also set run my VMware Server shutdown default and the Virtual Machines Power Controls to "Shut Down Guests".

In order to make that work elegantly, you have to do a little bit of "vi" work, and edit vmware-guestd to use "shutdown -p" instead of "shutdown -h".

Important Notes:
  • This is a workaround, and unsupported by VMware (at least until whenever VMware fixes this problem)
  • Presumably ACPI needs to be enabled in the FreeBSD guest.
  • This needs to be done everytime you update VMware Tools.
1. Locate the vmware-guestd binary

# locate guestd | grep sbin | grep local
/usr/local/lib/vmware-tools/sbin32/vmware-guestd
/usr/local/lib/vmware-tools/sbin32/vmware-guestd-wrapper
/usr/local/lib/vmware-tools/sbin32-6/vmware-guestd
/usr/local/lib/vmware-tools/sbin32-6/vmware-guestd-wrapper
/usr/local/lib/vmware-tools/sbin64-6/vmware-guestd
/usr/local/lib/vmware-tools/sbin64-6/vmware-guestd-wrapper
/usr/local/sbin/vmware-guestd

# ls -l /usr/local/sbin/vmware-guestd
lrwxr-xr-x  1 root  wheel  58 Nov  9 00:53 /usr/local/sbin/vmware-guestd -> /usr/local/lib/vmware-tools/sbin32-6/vmware-guestd-wrapper

2. Back up the vmware-guestd binary

(Ok, this part is very important. You're working on vmware-guestd, and not vmware-guestd-wrapper, which is just a wrapper for the real 'vmware' binary to ensure that the binary will find all the shared libraries.)

# cp -p /usr/local/lib/vmware-tools/sbin32-6/vmware-guestd /root/vmware-guestd.bak

3. Kill the vmware-guestd process

# ps awxx | grep guestd
  866  ??  Ss     0:46.86 /usr/local/lib/vmware-tools/sbin32-6/vmware-guestd --background /var/run/vmware-guestd.pid
 2066  p0  S+     0:00.01 grep guestd

# kill 866

# ps awxx | grep guestd
 2092  p0  S+     0:00.01 grep guestd

4. Use "vi" to edit the vmware-guestd binary

# vi /usr/local/lib/vmware-tools/sbin32-6/vmware-guestd

5. Search for "shutdown -h" in the vmware-guestd binary

http://www.vmware.com/support/reference/common/info_tools.html.

^@^@^@^@Could not get path to Tools configuration file.
^@^@^@^@Could not get path to Tools installation.
^@^@/build/mts/release/bora-122956/bora-vmsoft/lib/conf/conf.c^@^@C
onf file out of date; reloading...
^@tools.conf^@%s%c%s^@/sbin/shutdown -p now^@/sbin/shutdown -r now^
@/hgfs^@mount-point^@poweron-vm-default^@poweroff-vm-default^@resum
e-vm-default^@suspend-vm-default^@512^@max.wiperfile.size^@640^@res
olution.min.width^@480^@resolution.min.height^@^@HgfsBd_Dispatch: R
pcOut_send returned failure
^@^@HgfsBd_GetChannel: Failed to allocate an RpcOut
^@^@^@^@HgfsBd_GetBuf: Failed to allocate a bd buffer
/shutdown -h

6. Replace "shutdown -h" with "shutdown -p" in the vmware-guestd binary

http://www.vmware.com/support/reference/common/info_tools.html.

^@^@^@^@Could not get path to Tools configuration file.
^@^@^@^@Could not get path to Tools installation.
^@^@/build/mts/release/bora-122956/bora-vmsoft/lib/conf/conf.c^@^@C
onf file out of date; reloading...
^@tools.conf^@%s%c%s^@/sbin/shutdown -p now^@/sbin/shutdown -r now^
@/hgfs^@mount-point^@poweron-vm-default^@poweroff-vm-default^@resum
e-vm-default^@suspend-vm-default^@512^@max.wiperfile.size^@640^@res
olution.min.width^@480^@resolution.min.height^@^@HgfsBd_Dispatch: R
pcOut_send returned failure
^@^@HgfsBd_GetChannel: Failed to allocate an RpcOut
^@^@^@^@HgfsBd_GetBuf: Failed to allocate a bd buffer

7. Save and quit "vi"

http://www.vmware.com/support/reference/common/info_tools.html.

^@^@^@^@Could not get path to Tools configuration file.
^@^@^@^@Could not get path to Tools installation.
^@^@/build/mts/release/bora-122956/bora-vmsoft/lib/conf/conf.c^@^@C
onf file out of date; reloading...
^@tools.conf^@%s%c%s^@/sbin/shutdown -p now^@/sbin/shutdown -r now^
@/hgfs^@mount-point^@poweron-vm-default^@poweroff-vm-default^@resum
e-vm-default^@suspend-vm-default^@512^@max.wiperfile.size^@640^@res
olution.min.width^@480^@resolution.min.height^@^@HgfsBd_Dispatch: R
pcOut_send returned failure
^@^@HgfsBd_GetChannel: Failed to allocate an RpcOut
^@^@^@^@HgfsBd_GetBuf: Failed to allocate a bd buffer
:wq!

8. Restart FreeBSD

# shutdown -r now



Please do leave comments if I was inaccurate in any way, and let me know how I can make this post clearer and more helpful.

No comments: