Debian Squeeze PXE Netboot For VirtualBox

This is the second 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 part of a series that describes my system for easily setting up Debian Squeeze VMs using VirtualBox. Specifically, we’ll go though setting up a PXE boot environment that takes advantage of the VirtualBox built-in TFTP server for NAT interfaces.

Resources

Setting Up The PXE Boot Files

The instructions for netbooting Debian Squeeze are pretty good, except there is a wrinkle if you are booting a VirtualBox machine – the default drivers in the netboot image from the Debian site don’t support the VirtualBox hard drives. So we need to do some patching which involves grabbing an initrd.gz image that has the drivers and transplanting them into the netboot image. Rather than walk you through this step by step, I’ll just show the script that I use.

The script creates a d-i_firmare under your $HOME/tmp directory, and we’ll use the results in the TFTP setup later to serve up the actual netboot image.

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#! /bin/dash
#
# -----------------------------------------------------------------------------
# makePxeInstaller.sh - Make a netbootable directory that has all the IDE
# and sata drivers needed for a VirtualBox install
#
# Works in the current directory
# -----------------------------------------------------------------------------
echo "Executing makePxeInstaller"
# Set up variables so that the script is easier to update
FWDEST=$PWD
FWTMP=$HOME/tmp/d-i_firmware
DEB_DISTS=http://http.us.debian.org/debian/dists
SQUEEZE_IMAGES=$DEB_DISTS/squeeze/main/installer-i386/current/images
NETBOOT_TAR_GZ=$SQUEEZE_IMAGES/netboot/netboot.tar.gz
HD_INITRD_GZ=$SQUEEZE_IMAGES/hd-media/initrd.gz
# Comment these lines out if you do NOT want to clear out existing files
# rm -rf $FWTMP
# rm -rf $FWDEST/netboot
# rm $HOME/.VirtualBox/TFTP
# -----------------------------------------------------------------------------
# Check if we already copied the installer, symlink if we have it
if [ -d $FWDEST/netboot ]; then
echo " symlinking the netboot directory..."
ln -sf $FWDEST/netboot $HOME/.VirtualBox/TFTP
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Check if we already built the installer, copy and symlink if we have it
if [ -d $FWTMP/netboot ]; then
echo " Copying and symlinking the netboot directory..."
cp -R $HOME/tmp/d-i_firmware/netboot $FWDEST
ln -sf $FWDEST/netboot $HOME/.VirtualBox/TFTP
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Otherwise get ready to do a complete build
#
# Make a temp dir for the installer gz files and then go there
echo " Making download directory..."
mkdir -p $FWTMP/download
cd $FWTMP/download
# Check to see if the destination files already exist before downloading
# them
echo " Downloading netboot.tar.gz if we don't have it already..."
[ -f netboot.tar.gz ] || wget $NETBOOT_TAR_GZ
echo " Downloading hdboot intrd.gz if we don't have it already..."
[ -f initrd.gz ] || wget $HD_INITRD_GZ
# Make a directory for the extracted netboot files and extract them
echo " Extracting netboot.tar.gz..."
mkdir -p $FWTMP/netboot
cd $FWTMP/netboot
pax -rz -f $FWTMP/download/netboot.tar.gz
# Make a directory for the extracted intrd files and extract them
echo " Extracting netboot initrd.gz..."
mkdir -p $FWTMP/initrd
cd $FWTMP/initrd
pax -rz -f $FWTMP/netboot/debian-installer/i386/initrd.gz
# Copy the missing ata and ide drivers from the hdboot image to the netboot image
echo " Copying ide and ata drivers from hdboot initrd.gz..."
pax -rz -f $FWTMP/download/initrd.gz lib/modules/2.6.32-5-486/kernel/drivers/ata/*
pax -rz -f $FWTMP/download/initrd.gz lib/modules/2.6.32-5-486/kernel/drivers/ide/*
# Find all the files in the netboot initrd directory and rebuild netboot initrd.gz
echo " Rebuilding netboot initrd.gz..."
pax -wz -x sv4cpio -f $FWTMP/netboot/debian-installer/i386/initrd.gz .
# Remove the initrd directory - no longer needed
echo " Cleaning up the initrd dircetory..."
cd $FWTMP
rm -r $FWTMP/initrd
# Copy the results to the where we ran the script from
echo " Copying and symlinking the netboot dircetory..."
cp -R $HOME/tmp/d-i_firmware/netboot $FWDEST
ln -sf $FWDEST/netboot $HOME/.VirtualBox/TFTP
echo "Done"

If you run this script, you’ll be most of the way to getting a PXE bootable image together – in fact it does all the symlinking necessary to get us to the next step in the process, which is actually booting the machine.

If the network interface that is configured for NAT is set up as the priority boot interface, everything should just work. In the next article, we’ll discuss how to customize the boot files so that the installer is started automatically, and we’ll also investigate automating the entire install process using preseeding.