Virtual machines are very useful for testing. I often use them to verify changes to software, without messing up the local environment. Due to laziness I use VirtualBox and install Ubuntu official ISOs on them, rather than something more elegant/complicated such as kvm, lxc containers or chroots. This replicates an actual desktop environment pretty closely so is ideal for reporting bugs and validating that fixes to software work as expected.
Taking a virtual machine to a point where it’s mostly usable is a bit involved. I launched the desktop ISO, did the manual install procedure, rebooted, installed the VirtualBox extensions so I could mount the host’s drives, did some group changes, rebooted again… this is getting a bit tiring!
I had a quick look at Vagrant to see if it could somehow ease the task. It’s very interesting but didn’t really work in this case, as the virtual machine still has to be set up the way I describe before being able to package and then use it. What I’m after, really, is a way to set up a VM from scratch, just by doing the installation and adding a few extra packages.
This is what preseeding does, but up until now I had only played with local preseeds, baked into the ISO image. I imagined being able to load a preseed from the network would be difficult to set up quickly, and on a personal workstation, which is what would best fit my use case.
Turns out that virtualbox and a simple python module make this very easy. With the default configuration (NAT networking), a virtualbox VM will get an IP address through DHCP, and it will be able to reach the host’s public IP address. So as long as we configure the Ubuntu installer correctly and have something serving that file, things are very easy. One of the parts I like about this is that experimenting with this is as easy as changing the local preseed and rebooting the VM. About the only cumbersome part is typing the kernel parameters every time, but since there’s only three of them to type/change, this is not as bad as it sounds.
- Put your preseed files in a directory (called, for instance, preseed.cfg).
- Change to this directory and run python -m SimpleHTTPServer. This starts a miniature HTTP Server on port 8000.
- If you like, verify that the preseed is served properly: wget http://
- Set up the virtual machine, point it to the Ubuntu installation CD, start it.
- When you get the keyboard and human icon, press any key.
- Move to “install Ubuntu” but don’t press Enter.
- Press F6 to access the “advanced mode”. At this point we’re modifying the kernel command line.
- Go to the beginning, delete the “file=
- Add “auto url=http://
- Replace “only-ubiquity” with “automatic-ubiquity”.
- Press Enter
- Sit back and relax while the virtual machine gets installed.
This fits the bill perfectly for me, it removes the manual steps in setting up a testing VM (which I don’t need to keep afterwards, so I can just delete it and recreate with the same procedure), allows for easy experimentation and customization, and doesn’t use a lot of strange technologies or components.
Here’s a link to a sample, basic preseed file. You can customize mainly the late_command (rather, the success_command for ubiquity) and anything else you like. The installation-guide-amd64 package has more details and sample preseed files.
Note that for server installations the kernel command line will be a bit different:
- No need to add automatic-ubiquity.
- You DO need to add the “auto url=blahblah” part.
- For it to be 100% automated, you need to specify a few parameters that in debian-installer are requested *before* the preseed is loaded. Add these: debconf/priority=critical locale=en_US console-setup/ask_detect=false console-setup/layoutcode=us netcfg/choose_interface=auto
- Note that for debian-installer, the late_command is used as opposed to the ubiquity/success_command.