g0blin Bringing together art & technology

16Mar/110

Ubuntu Preseed, VirtualBox and Hetzner EQ4 Virtual Machines

In February 2011, Hetzner.de added a funky bit of functionality to their hosting panel which made me rejoice - the ability to create a virtual MAC address for your extra IP addresses! As Hetzner are very restrictive in which NICs can use which IP addresses based on their MAC address, getting a Virtual Machine online in Bridged Mode was very hard, if not impossible.

This is a guide that will teach you not only how to create your own preseeded Ubuntu installation ISOs, but also how to get your Virtual Machines online with Hetzners EQ root server range.

First things first, we want the very latest available version of VirtualBox, so we need to add the following line to our '/etc/apt/sources.list' file and run 'apt-get update'.

Now it's time to install VirtualBox from our newly added repository.

This will install a fair few packages along with the latest version of VirtualBox. Once it's finished we can start creating our new Virtual Machine. First things first though, we need to get a new IP address (if we have not got one from Hetzner yet) and a custom MAC address for one of our extra IP address.

Login to the Hetzner Robot and navigate to the server that the Virtual Machine will be hosted on via the 'Servers' link in the left hand menu. Once you have selected your server, you should by default be on the 'IPs' tab. Here you will find the option to request a new IP and a list of all the IP addresses that can be used with this server. If you have not requested a new IP yet do so now. Once confirmed you should receive an email in the format below. Keep a note of these bits of information, we'll need them later.

Below you will find your additional IP address added to
the server EQ 4 #XXXX (xxx.xxx.xxx.xxx).

Please note that you can use the IP address only for this server.

IP: xxx.xxx.xxx.xxx
Gateway: xxx.xxx.xxx.xxx
Mask: xxx.xxx.xxx.xxx

Once your IP address has been confirmed, browser back to the IP section and find the IP address you want to use for the Virtual Machine and click on link next to it that is titled 'Request Separate Mac'. Make a note of the MAC address, as we'll need this later.

On to creating our Virtual Machine. We're going to be using an application bundled with Virtual Box called 'vboxmanage'. With this application, we can create, modify and control our Virtual Machines. First of all we need to create a directory that will hold our Virtual Machine Images - or VMIs. For this we'll be logged in as a normal user called 'VMManager'.

Now let's create our Virtual Machine. This machine will be named "Ubuntu VM Server", have access to 1 core, have 256mb of RAM and 10gb disk space. Go ahead and run the following to do this. You will have to replace with the MAC Address we were given earlier in the tutorial (without the ":" seperators).

If all went well, we have now setup our first Virtual Machine - but wait, we're not ready to boot yet! We need something to boot into - an ISO.

When researching for this article, my end goal was to create an automated setup process for Virtual Machines that would be able to not only create a Virtual Machine, but also rapidly deploy a certain set of software automatically. For this task, I turned to the preseeding feature of Linux (Ubuntu in specific).

Preseeding allows you to have the setup completed without the need for any user interaction at all - perfect for setting up a new server instance for a specific role!

What we're going to do is grab the Ubuntu netinst ISO, mount it onto a loopback directory, create a copy of the filesystem on the CD, unpack the Initial Ramdisk, create and add a preseed file and finally pack it all back up ready for mounting.

Note that this is being done on a 64bit CPU - so any reference to architecture will be different if you are on a 32bit. This next set of commands need to be run as root due to creating and mounting a loopback device.

Let's prepare our preseed file now. First of all grab the example file. You'll have to change a few of the lines to match up with your desired settings, in specific the IP address, netmask, gateway, hostname, domain name, root and administrator passwords. For the IP/netmask/gateway use the information that was sent to you by Hetzner when you requested a new IP address for your server. The hostname can be any single string (i.e. 'server1') and the domain the domain the server will belong to (i.e. 'host.co.uk').

Note: by the looks of things, preseeded installs will completely ignore the hostname you provide and override it with the reverse-resolved hostname, so be sure to set the reverse dns entry correctly and give it time to propagate, otherwise your new virtual machine will likely assign the hostname 'static' to itself (the default hostname for unassigned Hetzner IPs is 'static.xxx.xxx.xxx.xxx.clients.your-server.de')

Now we're going to make a copy of the installation CD, customize the Initial Ramdisk with our preseed file and then repack it all up into an ISO ready for mounting to our virtual machine.

This next set of commands can be run as our standard user 'VMManager'. We'll be starting off in the users home directory. This also assumes the preseed.cfg file we created is stored in the users home directory.

We're almost ready to reconstruct our installation ISO, but first we need to make a change to a couple of files to ensure this is a completely unattended install. You'll have to make these files writable before you make the changes.

In the files "ISOBuild/cd/isolinux.cfg" and "ISOBuild/cd/prompt.cfg" change the line that reads "timeout 0" to read "timeout 4". This ensures the ISO will boot into setup without any interaction required from the user.

Now to generate our ISO image. Perform the following commands from the users home directory.

If all has gone well we should see our custom-built ISO in the current directory called "boot.iso". Now it's time to mount and boot! For this task we go back and make use of the "vboxmanage" command again.

Now usually I would be starting the Virtual Machine in headless mode - that means we would not get ANY output from the Virtual Machine at all. While you're getting used to this process, I'd recommend instead that you start up X or any other Window Manager and open the Virtual Box application so we can see exactly what the Virtual Machine is doing while it installs. If you are running a server you can use 'vncserver' and connect using any VNC client (see this post for instructions on how to do that).

We should now see in Virtual Box our newly created Virtual Machine starting up with our preseeded ISO image and chugging through the install steps all by itself, only stopping when it powers off at the end. Once installation is complete we should remove the boot media.

And now, we can finally power up the machine in headless mode with the following command.

Once it boots up, we should be able to access it via SSH with the password we gave it earlier (either through the root or administrator account).

References:
Howto create a custom Debian installer netinstall ISO
Installing Debian using only SSH

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.