Automating Debian installs with Preseeding

Following on from my post about building Debian virtual machines with libvirt, I’ve now got automated installations of Debian Lenny using the preseeding method. Coupling this with using virt-install, I can have a Debian virtual machine installation in only a few minutes. No questions asked.

The virt-install command contains an extra-args argument, where you can fill-in the specific parts of the preseeding. I don’t want to set an IP address in the file as it’s going to be used to build lots of machines, so I just specify that at install time. The URL part is where out preseed config file is stored. This obviously means that the machine needs to able to contact with webserver at install time to download the config.

$ NAME=debian-test
virt-install --name=${NAME} \
--ram=512 --file=/var/lib/xen/images/${NAME}.img \
--file-size 8 \
--nographics \
--paravirt \
--network=bridge:br0 \
--location=http://mirrors.uwa.edu.au/debian/dists/lenny/main/installer-i386 \
--extra-args="auto=true interface=eth0 hostname=${NAME} domain=vpac.org netcfg/get_ipaddress=192.168.1.2 netcfg/get_netmask=255.255.255.0 netcfg/get_gateway=192.168.1.1 netcfg/get_nameservers=192.168.1.1 netcfg/disable_dhcp=true url=http://webserver/preseed.cfg"

To get an idea of the contents of the preseed config file, the best place to start is the Debian stable example preseed file. It lists lots of different options, with plenty of comments so you can understand what’s going on.

For me to get a fully-automated install, I used these options. It’s fairly standard, but definitely worth reading the comments about each line.

$ egrep -v "(^#|^$)" preseed.cfg
d-i debian-installer/locale string en_AU
d-i console-keymaps-at/keymap select us
d-i netcfg/choose_interface select eth0
d-i netcfg/disable_dhcp boolean true
d-i netcfg/dhcp_options select Configure network manually
d-i netcfg/confirm_static boolean true
d-i mirror/protocol string http
d-i mirror/country string manual
d-i mirror/http/hostname string mirrors.uwa.edu.au
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i clock-setup/utc boolean true
d-i time/zone string Australia/Melbourne
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string ntp.vpac.org
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password-crypted password [MD5 Sum of the password]
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server vim puppet
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean false
d-i finish-install/reboot_in_progress note

Some good resources I found, which might help you are:

Posted in Geek, Linux, Work at September 18th, 2009. 3 Comments.

Running a Debian Lenny DomU under a CentOS 5 Dom0

The aim of this was to use the standard CentOS/RHEL Xen Dom0 tools to boot a Debian Lenny DomU.

I found plenty of instructions for doing CentOS DomU under a Debian Dom0, but not the other way around. So, this is a little how-to documenting the little things that need to be overcome.

I also wanted the Debian virtual machines to have their filesystems in a file, in the same standard way that the RHEL virt-install creates.

Steps involved:

  • Use virt-install to build a standard CentOS virtual machine
  • Use debootstrap to build a Debian Lenny base install for transplanting
  • Break apart a CentOS filesystem-in-a-file, and move the Debian install into it
  • Modify Debian config for booting the CentOS kernel

Use virt-install to build a standard CentOS virtual machine

I created a new virtual machine, using virt-install.

virt-install -n newvm -r 512 -f /var/lib/xen/images/debian.img -s 8 -l http://ftp.monash.edu.au/pub/linux/CentOS/5/os/i386/ -p --nographics -x

I needed some CentOS virtual machines anyway, so I let the install go through and do its thing. If you didn’t need it, you could probably kill the install before it started installing packages. We just needed the config file for the VM in /etc/xen and the filesystem image.

Use debootstrap to build a Debian Lenny base install for transplanting

I actually had a Debian Xen Dom0 with the xen-tools package installed. I used this to create a new Debian Lenny install, and also do some of the nice hook scripts with you would otherwise have to do by hand.

# xen-create-image --hostname=vanila --size=8Gb --dist=lenny --memory=512M --ide --dhcp

This meant I had a hostname file, libc6-xen and other things already done for me.

This was installed into an LVM partition, so after building it, I mounted the LVM partition, and used tar to compress it.

# mount /dev/mapper/vg-vanilla--disk /mnt
# tar zc -C /mnt/ . > /tmp/vanilla-debian.tar.gz

Break apart a CentOS filesystem-in-a-file, and move the Debian install into it

Set up the loop device
# losetup -f /var/lib/xen/images/debian.img

Map the partitions inside the loop device
# kpartx -av  /dev/loop0
add map loop0p1 : 0 208782 linear /dev/loop0 63
add map loop0p2 : 0 16032870 linear /dev/loop0 208845

At this point, you should have /dev/mapper/loop0p1 which is the root filesystem of your new VM. You’ll need to format the filesystem with:
# mkfs.ext3 /dev/mapper/loop0p1

Mount the newly formatted filesystem
# mount /dev/mapper/loop0p1 /mnt

Extract our Debian Lenny install into the filesystem
# cd /mnt
# tar xf /tmp/vanilla-debian.tar.gz

Modify Debian config for booting the CentOS kernel

We want to use CentOS/RHEL’s pygrub bootloader, just because it’s nice.

First, you’ll need to copy the CentOS kernel into your Debian install. You’ll need the config, kernel and initrd files from /boot of a DomU (or maybe the Dom0..)
# cd /boot
# cp config-2.6.18-92.1.22.el5xen vmlinuz-2.6.18-92.1.22.el5xen initrd-2.6.18-92.1.22.el5xen.img /mnt/boot

Rename the initrd to drop the .img from the end. It doesn’t work with the update-grub script in Debian
# mv initrd-2.6.18-92.1.22.el5xen.img initrd-2.6.18-92.1.22.el5xen

Copy the kernel modules to your new VM too:
# cp -r /lib/modules/2.6.18-92.1.22.el5xen /mnt/lib/modules

If you don’t have a /boot/grub directory in your Debian DomU, then you’ll need create one. You only really need three files: menu.lst and device.map. We’ll need to set it up properly so that both the update-grub script in Debian and the pyGrub bootloader work happily.

Edit the /boot/grub/device.map file. Make sure your hd0 is set to /dev/xvda:
(hd0)   /dev/xvda

The pyGrub script reads grub.conf, and not menu.lst, so symlink it
cd /boot; ln -s menu.lst grub.conf

Here’s the contents of my /boot after I’m finished:
/boot/config-2.6.18-92.1.22.el5xen
/boot/initrd-2.6.18-92.1.22.el5xen
/boot/vmlinuz-2.6.18-92.1.22.el5xen
/boot/grub
/boot/grub/default
/boot/grub/menu.lst
/boot/grub/device.map
/boot/grub/grub.conf

You’ll need to fix your inittab to use the xvc0 as your console. If you don’t you lose access to log into the console. In the file /etc/inittab, edit the tty1 line to be xvc0 instead.
1:2345:respawn:/sbin/getty 38400 xvc0

Your first tty should be changed to xvc0, and the others (tty2-6) should be commented out (if they’re not already)

Unmap the partitions and destroy our loop device
# kpartx -d /dev/loop0
# losetup -d /dev/loop0

Start the new Debian Lenny virtual machine

# xm create -c debian

You should see PyGrub come up, and let you pick the kernel.
pyGRUB version 0.6
==========================================================================
| Debian GNU/Linux, kernel 2.6.18-92.1.22.el5xen                         |
| Debian GNU/Linux, kernel 2.6.18-92.1.22.el5xen (single-user mode)      |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
==========================================================================
Use the ^ and v keys to select which entry is highlighted.
Press enter to boot the selected OS. 'e' to edit the
commands before booting, 'a' to modify the kernel arguments
before booting, or 'c' for a command line.

Will boot selected entry in  4 seconds

Hopefully, it works for you too :)

I’ve made one vanilla debian install, and just make a copy of that image file for each new VM I need to create. I have eth0 in the interfaces file commented out, so I just put the new IP in, set the hostname and I’m ready to go.

I may have missed a step in here, so if you’re trying this out, please comment to let us know how it goes.

Posted in Geek, Work at February 26th, 2009. 4 Comments.

Victorian Partnership for Advanced Super Mario Bros

img_7638.jpg

Posted in Geek, Work at November 28th, 2006. 3 Comments.

Grad lunch

Some of the Big T grads went to Christian’s Dad’s place for lunch. It’s called Aroma Cafe, on Queen St. Very nice.

gradsatlunch.jpg

Posted in Work at February 3rd, 2006. 2 Comments.

This graphic is somewhat disturbing

This is me doing a blowfish on the Innovation Centre machine room window

Posted in Personal, Work at December 1st, 2005. 1 Comment.

An update for the last couple of weeks

Haven’t blogged for a while, so he’s a quick update of what’s been going on.
At work late tonight, helping out because of a function. It was supposed to be finished at 9pm, but it’s now 10:15pm and they’re still here. Let’s bring on the tear gas and tasers :)

We started getting pissed off with the builders across the lane from us, so we started hassling the council about it, and maybe something’s going to get done. I moved my webcam server home, and set up two cams outside our window, so at any time, I can see what they’re doing. You can check it out at http://andybotting.com/webcam. Whatever you do, don’t leave it running too long, it kills my bandwidth :)

My old man is going to salary sacrifice a new laptop for me. This is nice because it means that i’ll only have to pay about 52c in every dollar. I was tossing up between an IBM ThinkPad and an Apple 15″ PowerBook, but I think the PowerBook is going to be the choice. I set up a Wiki page on everything I could find about running Linux on the new hi-res (powerbook5,8 Oct 2005) model PowerBooks here. It seems that there are a couple of little issues (current kernels don’t have support for the ATA controller, AGP and the Gigabit Ethernet but can be patched), but is basically ok. I should be ordering it in 2 weeks time.

I broke the Segway at work (not sure how…) but it’s back today. They couldn’t tell me exactly what broke, but it was under warranty anyway. Looks like i’m going back to my old rotation at IP Voice next week. They’ve got plenty of work and need some more bodies, so I’m going back to help out.

Also, the fuckwits managing this company decided to Not go ahead with the graduate intake for 2006. This does mean that the grads who were promised jobs, and signed their contracts will now be sacked. The Age ran an article about it, and there is also a Whirlpool forum on the subject. If you’re wondering, Nelsie’s still got her spot for next year. Phew.

Jezza has done some terrific work on his new Melways frontend. You can now search for an address to bring up the melways map to fill your full brower window, and even switch to the corresponding Google Maps satellite image. It’s the best we’ve got until Google bring maps to Australia

… also, I found this which made me laugh.

Note to self: blog more often :)

Posted in Geek, Linux, Personal, Work at November 9th, 2005. 3 Comments.

Cool stuff at Work

I hung back at work to score a couple of beers and some nice finger food :)


Jeremy, Rob and Andy @ the IC

I’m also getting close to finishing my webcam server. You should be able to see me (in the store room) on the cam at batman.andybotting.com. Everybody’s favourite telco is hosting this box on a 100Mb link to the net. Rock on :)

Posted in Geek, Work at October 13th, 2005. No Comments.

Eat my Segway dust biiach

Earlier this week, we got a Segway at work. Here is an action shot:

Andy on a Segway Andy on the Segway
Andy on the Segway

These things are amazing to ride. They have some incredible gyroscopic electronics which keep this thing upright… and they also go at about 20 km/h, which doesn’t sound like much, but feels very quick. It comes with three electronic keys, a black, a yellow and a red. Each one with a different profile on maximum driving and turning speed. I can’t wait until we belt this thing around Telstra dome late one night ;)

Posted in Geek, Work at August 18th, 2005. 4 Comments.

Photo

The guys at Canon kindly donated a couple of digital cameras to the centre. So here’s a pick of me and the guys I work with, amongst all the mess :)

Michael, Rob and Andy @ the Innovation Centre
Michael, Rob and Andy @ the Innovation Centre

Posted in Work at August 4th, 2005. 4 Comments.

Gnome 2.12

I haven’t blogged in about three weeks, which is pretty slack. The major thing to happen within that time is that I have moved to another group at work. I’m now working at the Big-T Innovation Centre, down at Docklands. Coolest place i’ve ever worked :)

What this post is really about is GNOME 2.12. Davyd Madeley has created a summary of all the new stuff in GNOME 2.12 here.

From just reading this stuff, it reminds me how much GNOME rocks! I’m really glad that they seem to be switching to the new ClearLooks theme too. It’s a very snappy looking theme.

I have found blogs of two seperate people making ebuilds for it. Albert Hopkins and Raphaël Slinckx. It looks like Raphaël’s are much more complete.. but I think I might wait until it hits hardmasked in portage.

Posted in Geek, Work at August 2nd, 2005. No Comments.