Quick VM creation with ubuntu-vm-builder and apt-proxy

So today I learned about an incredibly simple way to split up essential services on my home network with VMs. It isn't that hard to do normally, of course, but there's a lot of rote overhead in VM creation. Enter ubuntu-vm-builder!

  1. First things first. You'll need VMWare Server or KVM installed, obviously, to run VMs. VirtualBox would work too, but it hasn't been implemented yet in ubuntu-vm-builder -- the option's listed in the usage description, but don't be fooled. I personally used VMWare Server, to which this post will continue to refer. This tutorial ought to get you up and running, although I also had to install the libxtst6 package to get it to accept my serial number.

  2. Next, set up apt-proxy, which is a must-have if you've got a lot of Ubuntu boxes. It acts as...well, as a proxy to repositories, caching package files. Thus, if you upgrade a bunch of Ubuntu boxes through the proxy, you'll only have to download the packages once. This will let you create all your VMs after the first in about five minutes. I used this tutorial, and it worked without a hitch.

  3. Finally, install ubuntu-vm-builder, which is in the Hardy repos:

    $ sudo apt-get install ubuntu-vm-builder

    It'll install some dependencies as well. Once that's all done, you're ready to create a VM, which couldn't be simpler:

    $ sudo ubuntu-vm-builder vmserver hardy
    --hostname dupondt --addpkg ssh -d dupondt
    --mirror --ip

    A little explanation. The first argument is the type of VM -- kvm, vbox (which, as I mentioned, doesn't work), vmserver, and a few others. Second is the Ubuntu suite you want installed -- hardy, feisty, gutsy, etc. The -d option is for specifying the path where you want the VM created, which is important because otherwise it'll create it in $PWD named something like ubuntu-hardy-i386-vm, which is fairly useless. --addpkg lets you specify packages you want installed on the VM, clearly; it can be repeated (e.g. --addpkg mysql-server --addpkg apache2). Finally, the --mirror option is the repository you want it to use. That's where you specify your apt-proxy box. The rest are basic configuration options; see the usage for the full list. There are some useful ones; you can specify the name and password of the default user to be created, and even feed it an SSH pub key to be added to authorized_keys.

    That'll chug away for a while (if it's the first time you're populating the proxy; otherwise it'll be very fast). At the end, you'll have a folder wherever you specified with a VM in it. If you're using VMWare Server, as I did, register it:

    $ sudo vmware-cmd -s register /path/to/vms/dupondt/dupondt.vmx

    And start it up:

    $ sudo vmware-cmd /path/to/vms/dupondt/dupondt.vmx start

    And you're good to go! If you didn't specify a user/password during creation, it's ubuntu/ubuntu.

So that's how I got me a nameserver and a Zenoss server in no time. Now I need to think of reasons for more VMs.


Post a Comment