User:Mjb/FreeBSD on VirtualBox

From Offset
Jump to navigationJump to search

VirtualBox emulates IBM PC-compatible hardware. It's like an imaginary rack of PCs. Each PC is a Virtual Machine (VM) with its own pretend hardware (motherboard, RAM, keyboard, mouse, display, networking, storage). Your real computer running VirtualBox is the "host". The VMs are "guests".

I'm running FreeBSD in a VirtualBox VM. The host system is Windows 7. Here are some of my notes about it. Any questions/comments, email me directly at root (at) skew.org.

See also:


Install VirtualBox

I already had VirtualBox 4.3.20 installed for other projects. I don't recall if there was anything special I did to set it up.

BIOS must enable hardware virtualization if CPU supports it

Once I got FreeBSD working in a VM under VirtualBox 4.3.x, I upgraded to VirtualBox 5.0.6. The FreeBSD VM continued to work, but some other VMs (Windows XP and Archive Team Warrior) would not fully boot.

It seems the newer versions of VirtualBox don't like it if you have an Intel CPU with VT-x (Intel's hardware virtualization features), but this support is not enabled in your motherboard's BIOS settings. The symptoms are strange crashes during the guest OS's bootup. The crash report may or may not seem to be related to what's going on. In one case I was getting an assertion failure for something quite obscure, but in another the VBox.log file mentioned there was an issue with hardware virtualization support.

So before running the 5.x versions of VirtualBox, be sure to enable the all your hardware virtualization support settings in your BIOS. If your motherboard or BIOS has no such settings, you may be out of luck!

Windows custom theme app incompatibility

On Windows, VirtualBox 4.3.14 and up has a "hardening" improvement which checks the integrity of Windows DLL processes to make sure nothing is hijacking or extending them. If you are running software which modifies any core Windows features, like certain theme/font/skinning apps, your VMs will all fail to start in these newer builds of VirtualBox. You need to either disable that software or configure it to ignore the VirtualBox.exe process. In MacType, for example, add VirtualBox.exe to the [UnloadDlls] section of the current profile (.ini file).

Decide what to run

Since it's (almost) just like having a separate PC, you have a choice of what to do:

  • You can get a "live" CD/DVD image file and have a VirtualBox VM boot and run FreeBSD from it. This is mainly just for trying out the OS; changes won't be saved.
  • You can get a FreeBSD snapshot and put it onto a virtual hard drive, then use a VirtualBox VM to boot FreeBSD from that drive.
  • You can have a VirtualBox VM boot from a FreeBSD installer CD/DVD image, and use the installer to put FreeBSD onto the VM's virtual hard drive.

I chose the latter option (using the installer).

Download a FreeBSD installer DVD image

You need an uncompressed ISO-format image of an i386 release version of FreeBSD. Go to ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/i386/ISO-IMAGES/ and pick the latest version available. In my case it was 10.2, and the file I wanted was FreeBSD-10.2-RELEASE-i386-dvd1.iso.

Download and save the .iso file somewhere.

Create a Virtual Machine for FreeBSD

  • Name: whatever you want, e.g. FreeBSD 10.2-RELEASE
  • Type: BSD
  • Version: FreeBSD (32-bit)
  • Memory size: 128 MB is recommended but that's the bare minimum. I chose 1024 MB (1 GB). It will be using the host's RAM, so you have to decide how much you can spare.
  • Hard drive: Create a virtual hard drive now, file type VDI, Dynamically allocated. The size can be whatever you can spare. It will live in a file on one of your host's drives.

Now click on the Settings icon; don't turn on your VM yet.

  • System > Motherboard > [X] Hardware Clock in UTC Time
  • Storage > under Controller: IDE, there's a CD/DVD icon and the word "Empty". Click on it. Now on the right side, under Attributes, click on the new CD/DVD icon that's next to "IDE Secondary Master", and choose "Choose a virtual CD/DVD disk file...". Find the .iso you saved (see previous section) and point it to that. You have just done the equivalent of putting a DVD into the VM's drive! Click OK.
  • Network > Attached to: Bridged Adapter. This defaults to NAT, but you want Bridged Adapter so that it will be visible and fully accessible to other machines on your LAN, including your host machine (i.e. they can establish inbound connections to the VM). If you choose NAT, then the VM is hidden "behind" your host machine and is only capable of outbound connections.

OK, now you're ready. Click Start to power on the VM. The DVD should boot and you're ready to install. Just follow the prompts.

Before rebooting at the end of the install process, you will need to "remove" the DVD from the drive, or it will boot back into the DVD. If that happens, it's OK just to power off the VM.

Poudriere

Poudriere is a package repository creator. You run it on a fast machine and tell it what ports to build (from the ports collection), and for which architectures (i386, armv6, etc.). It then, at your command or via cron, builds those ports in jails and puts the resulting package tarballs into a non-jail directory. If you make the directory web-accessible, or just copy it somewhere, then all the FreeBSD boxes you manage can use it for installing software from packages rather than ports.

I thought it would be interesting to see if it can run in VirtualBox, so I can use my Windows home computer to build packages for my FreeBSD machine. It was frustrating and didn't work.

Here were the steps I took:

Install and boot into FreeBSD

  • Follow the directions above to install FreeBSD on a virtual hard drive in a VirtualBox VM.
    • The version of FreeBSD must be for the same branch you're building for—e.g., if you want to build for 10-STABLE, make sure you install 10-STABLE, and make sure it's a version/revision the same or newer than the target machine.
    • Configure the file system to use UFS, like normal. Some poudriere guides say you must use ZFS, but that's no longer true. I'm not sure ZFS works as well as it should in VirtualBox, anyway.
  • Boot into FreeBSD on the VM.
  • Log in as root, or log in as a regular user and then su to root.

Install & configure poudriere

  • pkg install poudriere qemu-user-static (allow it to install pkg as well)
  • echo 'qemu_user_static_enable="YES"' >> /etc/rc.conf
  • service qemu_user_static start (ignore warnings)
  • service qemu_user_static list (confirm armv6 is mentioned)
  • Edit /usr/local/etc/poudriere.conf and uncomment NOLINUX=yes. If you are using ZFS, also set ZPOOL=zroot (or set it to any other pool mentioned in the output of zpool list). Otherwise, uncomment the NO_ZFS line.
  • poudriere ports -c -m svn+https -p svn
[00:00:00] ====>> Creating svn fs... done
[00:00:00] ====>> Checking out the ports tree...Error validating server certificate for 'https://svn.freebsd.org:443':
 - The certificate is not issued by a trusted authority. Use the
   fingerprint to validate the certificate manually!
Certificate information:
 - Hostname: svn.freebsd.org
 - Valid: from Jun 22 00:00:00 2015 GMT until Jun 22 23:59:59 2016 GMT
 - Issuer: Gandi, Paris, Paris, FR
 - Fingerprint: E9:37:73:80:B5:32:1B:93:92:94:98:17:59:F0:FA:A2:5F:1E:DE:B9
(R)eject, accept (t)emporarily or accept (p)ermanently? p
 done

This takes ~90 minutes before "done" appears.

Create the build environment

You must create a jail containing the base system for the builds. Essentially it's like another instance of FreeBSD, possibly for another architecture, that's isolated from the main system. Fetching and building this environment takes a couple of hours. Here's how to do it if building for the armv6 platform:

For 11-CURRENT:

  • poudriere jail -c -j 11armv6 -v head -a arm.armv6 -m svn+https

For 10-STABLE:

  • poudriere jail -c -j 10armv6 -v stable/10 -a arm.armv6 -m svn+https

Unfortunately the VM locked up on me during this step. When I rebooted, it was unable to mount the ZFS pool, so would just keep rebooting in a loop. I couldn't figure out how to get it to work, so I gave up and deleted the VM. I intend to retry with UFS instead of ZFS.

Make list of ports to build

Now put a list of ports to build in a file ~/foo. I recommend starting small:

editors/nano
mail/mutt

Configure port options

There are several ways to choose the 'make configure' options for the ports you will be building:

You can configure all of the ports in the list:

  • poudriere options -cf ~/foo

You can configure just one port's options: poudriere options -c www/nginx

You can pre-configure options based on the target machine's previous builds from the ports collection by copying the /var/db/ports hierarchy (on the target machine) to /usr/local/etc/poudriere.d/options (on the poudriere machine):

  • scp -pr example.org:/var/db/ports ~
  • mv ~/ports/* /usr/local/poudriere/data/packages/
  • chown -R root:wheel /usr/local/poudriere/data/packages

Build all the ports

Now build all the ports in the list (this is for 10-STABLE):

  • poudriere bulk -f ~/foo -j 10armv6

Look for the packages in whatever POUDRIERE_DATA points to in /usr/local/etc/poudriere.conf: ls /usr/local/poudriere/data/packages/

This is the directory you can make web-accessible. Or you could copy it to the target machine and use a 'file:///path/to/the/packages' URL to get to it from pkg or portmaster. (Details forthcoming).

Update the ports

When you want to update the ports tree used by poudriere: poudriere ports -u

Then run the bulk build command again and it will build whatever it needs to.