Stabilizing FreeBSD as a guest under VirtualBox

One of the things virtualization allowed me to do is retire old hardware by imaging the hard drives and booting it up under VirtualBox. This works great, and is often better than trying to extract everything that might be worthwhile later.
Unfortunately, one of the first things I encountered was some instability in the FreeBSD guest. Once the system crashed spectacularly, I found I could no longer make it through compiling a port or updating the ports tree, and in some cases, it crashed on boot a few times before settling down.

By reviewing logs and experimentation, I settled on a configuration that appears to be rock-solid. With the caveat that I did not specifically identify the problem and that it’s possible my hardware and issues differ from others, here it is:

First, after the FreeBSD guest crashes, ufs can be left in a state where it thinks it can restore consistency using the journal, but that’s insufficient. The approach that works is to force a remount, then fsck twice:

mount -fur /
fsck -y /
fsck -y /

Once the errors are settled down, update fsck so that the “sync” flag is added to any mounts in the virtual container:

/dev/gpt/rootfs   /   ufs   rw,sync    1    1

Reboot, which will help stabilize things, because the next thing you’ll need is the emulators/virtualbox-ose-additions-nox package. (If you plan on using X, you can go for same package without the “nox” extension.) You might want to start with “pkg install” rather than building the port, since the port does require kernel source code. If your system isn’t yet stable, it can be challenging to retrieve this and complete the build — each time your system crashes, go back and fsck as above.

Once this package is installed, activate it in rc.conf:

vboxservice_enable="YES"
vboxguest_enable="YES"

Shut down the guest and go back to its settings. Set the Storage->Controller Type to “virtio-scsi” and ensure that the guest boots properly. Once I’ve complete these steps, my FreeBSD guests have experienced no instability.

Share
Bookmark the permalink.

Leave a Reply

Your email address will not be published.

By submitting this form, you accept the Mollom privacy policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.