| VirtualBox on Headless Gentoo |
|
|
| Written by Markus Ewald | |||
| Monday, April 05 2010 17:51 | |||
|
Being an adherent of Continuous Integration, I need a build machine that runs round the clock even when my workstation is turned off. As I'm running a small home server, this wouldn't be an issue -- if it weren't for the fact that my home server runs Linux and 99% of my development happens in Windows. So I use virtualization to run a small Windows system on top of my home server. In the past I used VMware for this job. VMware worked well for me and performance was quite good, but now that I've switched to a fully headless system, I noticed that the vmware-server package pulls in most of the X11 libraries - which I'm not particularly keen on having on my system due to their compile times.
So I went shopping for some alternatives. KVM sounded interesting (and was the leanest virtualization solution I could find), but the Gentoo Wiki stated that Windows didn't work in qemu with recent kernels, so I went looking on - and found VirtualBox. This article explains how to set up VirtualBox on a headless Gentoo system. 1. Install VirtualBoxVirtualBox can be trimmed down so it builds without a graphical client, thereby avoiding any X11 dependencies. Here are the USE flags I set in my /etc/portage/package.use to get rid of most of VirtualBox' dependencies: After that is taken care of, emerge VirtualBox on your system: 2. Create a Virtual MachineLet VirtualBox create a new VM. VirtualBox puts the VM and later its hard drives in the home directory of the user that invoked VBoxManage, so make sure you're logged in as the user you later want to run your VMs with. The Gentoo ebuild for VirtualBox' commercial distribution currently neglects to set up symlinks, so you might have to run the commands (eg. VBoxManage) by specifying their full path (eg. /opt/VirtualBox/VBoxManage instead) Next step: configure it. I'm using 512 MB of RAM and built-in NAT networking because it's way easier to configure than bridged networking and you might not want to expose additional IP addresses through your network adapter in a server environment. VirtualBox' built-in NAT supports port forwarding, so there's really no need for bridging. You can omit the ostype setting if you wish. This is a hint to VirtualBox about which operating system you plan to install as the guest OS, allowing for some OS-specific optimizations to be performed. I've had BSODs booting my VM if I used Windows 7 with a wrong ostype, so it's probably a good idea to specify this. You can get a list of valid OS identifiers with VBoxManage list ostypes. Next, create a hard drive image to install the guest operating system on Then assign this image to the VM's virtual hard drive: 3. Install OS on Virtual MachineI normally do a base install (OS without development tools) and archive it somewhere so I can later restore if I want to do a clean upgrade - eg. if I switch to Visual Studio 2010, I easily start fresh instead of uninstalling Visual Studio 2008 and ending up with a build machine carrying around remains from the past. If you're running the commercial edition of VirtualBox, you can mount a CD/DVD image of your operating system's install disk and perform the install via VirtualBox' built-in RDP server: Don't forget to enable RDP after you started the virtual machine: If you're using the Open Source Edition of VirtualBox, you should install one of the full VirtualBox releases on your workstation to prepare a hard drive image with the guest OS that you can then copy to your headless server. 4. Install Guest AdditionsThe first thing I recommend doing is to install the Guest Additions for VirtualBox. These provide better mouse cursor integration and an optimized graphics driver. There are VirtualBox Guest Additions available for the commercial edition of VirtualBox directly from sun, but if you, like me, decided to run the open source edition, you can find an Open Source reimplementation of the Guest Additions for Windows systems here: VirtualBox Windows Guest Additions Installer. 5. Enable SATA InterfaceYou can further improve the performance of your virtual machine by using a virtual SATA hard drive instead of an IDE one:
6. Back Up your Base ImageThis would be a good time to let your OS download its updates and to create a backup of your base image that you can use to set up future virtual machines. To minimize the size of the image, I usually follow these steps:
7. Daemonize VirtualBoxThere's a pretty good explanation complete with well-written init script available from the Gentoo wiki: Gentoo Linux Wiki - VirtualBox - Service. Here's a copy of their init script in case the wiki changes or goes down: /etc/conf.d/virtualbox.example /etc/init.d/virtualbox Above script has one master init script (/etc/init.d/virtualbox) and requires you to create symlinks to it for each virtual machine you want to run as a daemon: 8. Configure Port ForwardingIf you're running any services on the virtual machine that require a port to be accessible from the outside, you can configure port forwarding for VirtualBox' NAT like this: The VirtualBox NAT uses a kernel module to intercept and inject network packets. This approach requires zero configuration and works extremely well. I'm running OpenVPN on the host and the guest system accesses a remote server through the host's OpenVPN connection and vice versa without problems.
|


Comments
The initscript now on the wiki is buggy, but your version works out of the box.
Thanks!!
I just had to go through all this again myself after accidentally killing my building machine and when I created a new VM via VBoxManage, it didn't have any IDE or SATA controllers at all. And for "VBoxManage modifyvm --dvd" to work, the IDE controller needed to have a specific name and the DVD drive had to be attached to a specific port.
I hope the article at least serves as a general guide :)
...just being OCD
Unmount system drive:
VBoxManage modifyvm Builder1 --sataport0 none
Make system drive immutable:
/opt/VirtualBox/VBoxManage modifyhd --type immutable WinBuilder-System.vdi
Remount system drive:
VBoxManage modifyvm Builder1 --sataport1 WinBuilder-System.vdi
VirtualBox will automatically create a snapshot for the immutable drive. If you look at your VirtualBox.xml, there's a property 'AutoReset="true"' that does exactly what you think it does ;)
RSS feed for comments to this post