Preseeding a Debian Squeeze Netboot Install

This is the fourth and last article in a multi-part series that describes how to use Oracle’s VirtualBox to automatically set up Debian Squeeze VMs on a host machine. All the scripts used in these articles are available for download.

The articles are available here:

  1. Headless Debian VirtualBox Setup
  2. Debian Squeeze PXE Netboot For VirtualBox
  3. Need An Ultralight WebServer? You Need Mongoose!
  4. Preseeding a Debian Squeeze Netboot Install

Contents

Introduction

This article is the last in a series that describes my system for easily setting up Debian Squeeze VMs using VirtualBox. In previous articles, I’ve shown how to set up the VM using a simple script instead of using the VirtualBox GUI, and how to set a NAT interface for PXE Booting the VM. Now we’ll go though the process of booting into a custom Debian installer that takes advantage of preseeding the install with the exact settings that you want without ever having to touch the keyboard.

Needless to say, this speeds things up, reduces confusion, and makes you look like a rock star sysadmin. So, let’s get started.

Resources

Setting Up The Custom Installer

If you set up the VirtualBox TFTP directory as described in the previous article, then you’ve got things almost perfectly set up already. If you have a look at the file heirarchy in the netboot.tar.gz archive, the following key files appear:

TFTP/debian-installer/i386/initrd.gz

The custom initrd image we made in the previous article

TFTP/pxelinux.cfg

A symlink to the config file that controls the operation of the menus when the installer starts. More importantly, the config file actually sets up the boot options for the different installer options.

TFTP/debian-installer/i386/boot-screens/syslinux.cfg

The final destination of the TFTP/pxelinux.cfg symlink. We’ll just need to modify the timeout in this file.

TFTP/debian-installer/i386/boot-screens/text.cfg

The first section of the installer menu. We’ll be adding a new default entry here for our “Handsoff Preseed Install”

The easiest way to get these files set up is to copy the originals, and then just echo new files into place, using this script:

[crayon-4fb4c55cdaa34 url="./pxeSqueezeBox/makePxeBootScripts.sh" lang="sh"]

With this step complete, we only have one more file to create before we can run a hands off install.

This preseed.cfg file is symlinked to the webserver root directory before the actual install can run.

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#### Contents of the preconfiguration file (for squeeze VirtualBox)
d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/wireless_wep string
d-i mirror/protocol string http
d-i mirror/country string manual
d-i mirror/http/hostname string 192.168.56.1:8080
d-i mirror/http/directory string /ISO
d-i mirror/http/proxy string
d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean false
d-i partman-auto/disk string /dev/sda
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 multi
d-i partman-auto/expert_recipe string mypreseed-scheme :: \
30 40 50 ext3 \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ /boot } \
. \
200 300 400 ext3 \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ / } \
. \
128 192 256 linux-swap \
method{ swap } format{ } \
. \
1024 1280 1536 ext3 \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ /home } \
. \
96 128 160 ext3 \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ /tmp } \
. \
1024 1280 1536 ext3 \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ /usr } \
. \
640 768 1024 ext3 \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ /var } \
.
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i base-installer/kernel/linux/initramfs-generators string initramfs-tools
# password for root is "r00tme"
d-i passwd/root-password-crypted password $1$ab5KxFlx$WVnNvOwzhkt9GVxgA7Hxo/
d-i passwd/user-fullname string Firstname Lastname
d-i passwd/username string flastname
# password for flastname is "flastname"
d-i passwd/user-password-crypted password $1$eDIa9LF3$kNsQU7YuCHmJ51SQ5uw3d/
d-i apt-setup/main boolean true
d-i apt-setup/non-free boolean false
d-i apt-setup/contrib boolean false
d-i apt-setup/source boolean false
d-i apt-setup/use_mirror boolean false
d-i apt-setup/services-select none
d-i apt-setup/security_host string
d-i debian-installer/allow_unauthenticated string true
tasksel tasksel/first multiselect standard
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/poweroff boolean true
d-i preseed/late_command string in-target wget -O etc/postInstall.sh http://192.168.56.1:8080/postInstall.sh;chmod 700 /target/etc/postInstall.sh

Now that all the files are in place, it’s a simple matter of setting up all the necessary symlinks, making sure that the mongoose webserver is running, and starting the virtual machine. Here’s the script to set up the symlinks and start the

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /bin/dash
#
# -----------------------------------------------------------------------------
# installDebianVM.sh - Sets up the rest of the system so that we can do
# a hands off install of a Debian VM
#
# Works in the user's HOME directory and assumes that makePxeInstaller.sh
# and makePxeBootScripts.s have already been executed.
# -----------------------------------------------------------------------------
echo "Executing installDebianVM"
# Set up variables so that the script is easier to update
vmName="$1"
vmDir=$HOME/"VirtualBox VMs"/$vmName
preseedFile="$HOME/projects/pxeSqueezeBox/vmSetupScripts/$vmName/preseed.cfg"
postInstallFile="$HOME/projects/pxeSqueezeBox/vmSetupScripts/$vmName/targetPostInstall.sh"
isoFile=$HOME/.VirtualBox/ISO/debian-6.0.3-i386-netinst.iso
# -----------------------------------------------------------------------------
# Check if we have a preseed file, exit if we don't
if [ ! -e "$preseedFile" ]; then
echo " missing $preseedFile"
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Check if we have a postInstall.sh file, exit if we don't
if [ ! -e "$postInstallFile" ]; then
echo " missing $postInstallFile"
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Check if we have a VM alredy created file, exit if we don't
if [ ! -d "$vmDir" ]; then
echo " missing $vmDir - do we need to create it first?"
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Create the ISO directory (no error if it already exists)
mkdir -p ~/.VirtualBox/www/ISO
# Set up the symlink for the preseed and postinstall files
ln -sf "$preseedFile" $HOME/.VirtualBox/www/preseed.cfg
ln -sf "$postInstallFile" $HOME/.VirtualBox/www/postInstall.sh
# -----------------------------------------------------------------------------
# Check if we have the netinst ISO file, exit if we don't
if [ ! -e $isoFile ]; then
echo " missing $isoFile"
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Check if we have the ISO file mounted, mount if we don't
if [ ! -e $HOME/.VirtualBox/www/ISO/isolinux ]; then
$isoFile $HOME/.VirtualBox/www/ISO
fi
# Start up Mongoose and put it in the background
./startMongoose.sh &
# Start up the VM
VBoxManage startvm "$vmName"

In 5 to 10 minutes, depending on the type of host machine you have, you’ll be done and the VM can be powered up and will be ready for use.

Note that you may want to add your own preferred usename to the preseed config, as well as add certain packages. It’s relatively easy to experiment with the pre-seeded install without messing things up too badly. It’s best to use symlinks for a variety of preseed files.

That’s it – now you can start the VM, either from the commandline or from the VirtualBox GUI.