Well, it’s been a while since I last posted. There’s a lot been going on (major flat refurb), the results and process of which I shall be blogging about soon. In the interim however, I thought I’d write about an issue I encountered just today.
VMWare has unfortunately decided to end-of-life VMWare Server. This excellent free product allowed me to run multiple VMs on my home server, in a headless configuration, to provide certain resources on my network (DNS server, Radius, IPv6 router). Even better, when I inevitably messed up a kernel, or network config, the product allowed me to open up a console and play with the VM direct rather than relying on ssh.
Unfortunately, it is no more. And what’s worse, I hadn’t realised it was no more until I was part-way through my Gentoo update (up-time 235 days…). I went to recompile the VMWare kernel modules, and emerge informed me it wasn’t aware of any such package as vmware-server. D’oh!
So, what were my options:-
- Use VMWare Player or Workstation, in a headless configuration, using the vmrun command line,
- Use VMWare ESXi or similar
- Use an alternate virtualization technology – KVM, Xen, or VirtualBox
VMWare Player and Workstation are designed to be run with a GUI. Whilst they can be run in a headless configuration, I couldn’t (admittedly after minimal googling) see a way to get a VM console off them for the rare times I need one. So they were out.
ESXi etc are ‘bare-metal’ hypervisors, which would require a full server rebuild. My server is critical for me, and I don’t have any spare HDDs to put in a spare to try installing ESXi on. Plus, it’s a pretty old machine, and I’m not certain it would have the grunt to virtualize all the work I do on it. So they were out (although I like the idea for future reference).
Xen performance appears pretty iffy in most benchmarks I’ve seen.
KVM works well when all the VMs are linux. But they aren’t.
And that leaves VirtualBox. After some experimenting, this seems to work, and is the direction I’ve gone in. This blog details the steps I took to get it working…
So, let’s assume the following:-
- Running an up-to-date version of Gentoo, with a semi-recent version of VMWare Server
- Current VMs are stored in /var/lib/vmware/VMs/ with one dir per VM
- Each VM has a single disk, but that disk is split into multiple files on the host (e.g. Gentoo2010.0-s001.vmdk, Gentoo2010.0.s002.vmdk, etc…) It is an IDE driver
- We are going to store all the new VMs in /data/VMs/ one directory per VM
- You’ll want to get a copy of the MAC addresses of all the interfaces in the VM. We’ll assume de:ad:be:ef:b0:0b for the purpose of this
- The VM is a Gentoo VM, called wibble
First of all, let’s install virtualbox
echo "app-emulation/virtualbox -alsa doc extensions headless vboxwebsrv python java" >> /etc/portage/package.use echo "=app-emulation/virtualbox-extpack-oracle-4.1.4 PUEL" >> /etc/portage/package.license echo "=app-emulation/virtualbox-additions-4.1.4 PUEL" >> /etc/portage/package.license emerge -av app-emulation/virtualbox
That should all automagically work. We’re now going to need to (optionally) transcode the VMWare hard drive into a virtualbox one, then create a VirtualBox VM, set up the VM, then run it. Then debug.
First of all, the hard-drive. VirtualBox does apparently now run with VMWare vmdk files natively, however some functionality (namely snapshots) allegedly don’t work. Furthermore, I was following some dated instructions when I did the below, so it may not be necessary. Your mileage may vary with other approaches, but I can tell you this definitely worked for me…
Important: Stop the VMWare VM before you do this to it!!! As soon as you’ve finished the first step, and have a .bin file, you can restart it.
Step 1) Convert VMWare HDD to VirtualBox format (optional)
You will need a qemu tool if you choose to convert the hdd file. So…
emerge -av qemu
Now we can do
# Combine all the <2GB files into one file vmware-vdiskmanager -r Gentoo2010.0.vmdk -t 0 sda.vmdk # Now convert it to VirtualBox format, via an intermediate format qemu-img convert sda.vmdk sda.bin VBoxManage convertdd sda.bin sda.vdi
Step 2) Set up VirtualBox (optional)
By default, VirtualBox stores VMs at ~/.VirtualBox/ but we want to change that to /data/VMs/
mkdir /data/VMs/ VBoxManage setproperty machinefolder /data/VMs/
Step 3) Create and register VM
Creating and registering a VM is trivial, but note that it is far from all that is needed. When you create a VM, you’re creating an XML file and a directory for it, and optionally registering the VM so the VirtualBox system know about it (allowing you to henceforth refer to it by name). You are not yet populating that VM with anything other than the defaults.
VBoxManage createvm --ostype Gentoo --name wibble --register
That has created a new directory /data/VMs/wibble/ with a configuration wibble.vbox within it. To get a list of supported OS types, try the following:
VBoxManage list ostypes
Step 4) Configuration
We’re first of all going to copy the vdi file in, and then do a load of configuration. I’ll inline notes here. Note that all of the configuration options can be done in a single command if desired.
# Move in the file mv /var/lib/VMs/wibble/sda.vdi /data/VMs/wibble/ #Set RAM to 256MB VBoxManage modifyvm wibble --memory 256 #Disable USB VBoxManage modifyvm wibble --usb off --usbehci off #Disable Clipboard VBoxManage modifyvm wibble --clipboard disabled #Enable ACPI VBoxManage modifyvm wibble --acpi on #Create a single NIC, of the same type as VMWare, and bridge it to eth0. Set the MAC Address so the guest OS doesn't get confused VBoxManage modifyvm wibble --nic1 bridged --bridgeadapter1 eth0 --nictype1 Am79C970A --macaddress1 deadbeefb00b #As we still have VMWare installed and running, virtualbox doesn't have exclusive access. We can change this in the future VBoxManage modifyvm wibble --hwvirtexexcl off #Create IDE controller VBoxManage storagectl wibble --name "IDE Controller" --add ide --controller PIIX4 #Attach HDD to controller VBoxManage storageattach wibble --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /data/VMs/wibble/sda.vdi
We’re now almost good to go. The last item is support for a virtual/remote console. VirtualBox provides this through RDP. There has to be one port per running VM, and we’re going to assign it now. Note that I haven’t put any security on here – I strongly recommend you do so… Note that if you start a VM headless, VRDE will automatically be turned on anyway.
VBoxManage modifyvm wibble --vrde on --vrdeport 9999
Step 5) Running, Stopping
To run the VM it’s as simple as:
VBoxHeadless --startvm wibble
Note that this does not daemonize, which is useful for seeing logs, but not perfect for a server. I’ll leave daemonizing it etc as an exercise for the reader (because I haven’t gotten around to doing it myself yet, other than backgrounding it).
And to stop the VM, just do:
VBoxManage controlvm wibble poweroff
Finally, some other useful commands:
# Show the config VBoxManage showvminfo wibble # List all available VMs VBoxManage list vms #List running VMs VBoxManage list runningvms
I hope the above proves to be of some use. As stated, your mileage will inevitably vary, but this has definitely worked for me.