PXE Boot/Network Install/Repository Server
This post covers the complete process of using PXE to install Ubuntu 10.04 over the network from a locally hosted Ubuntu 10.04 repository server.
The first part of PXE booting is getting the DHCP server to tell clients where to get the appropriate boot files from the network. In dhcpd.conf, the following options are added in the subnet declaration or in each individual client declaration:
next-server [tftp server ip]; filename = "pxelinux.0";
These options tell the network-booting client to go to tftp server to get the boot files. Most modern motherboards support PXE booting, so just make sure to set the motherboard to boot to network first. That wraps it up for the PXE part.
NETWORK INSTALL SERVER
Having a local install server eliminates the need for CDs and USB drives for installation. Additionally, when combined with a local repository server, the new installation is immediately up-to-date, which means lengthy software updates are unnecessary on the new install. All that is needed for this part is the tftpd-hpa package:
apt-get install tftpd-hpa
Once tftpd-hpa is installed, /var/lib/tftpboot will be available to load the installation files to the PXE client. In /var/lib/tftpboot, create folders appropriate for the releases that will be installed over the network. In this example, an Ubuntu folder which contains an i386 and amd64 folder is created.
mkdir -p /var/lib/tftpboot/ubuntu/lucid/i386 mkdir -p /var/lib/tftpboot/ubuntu/lucid/amd64
The subdirectories lucid/i386 and lucid/amd64 are necessary to separate different releases, allowing the addition of other Ubuntu releases if needed. Now that the folder structure is created, the tftpboot folder needs two files which will tell the client where to find the install files. The first file to add is the boot.txt file. This file will display a menu which will allow the user to choose between a 64-bit or 32-bit installation. The file should look something like this:
Boot Options ============ 1. Ubuntu 10.04 amd64 2. Ubuntu 10.04 i386
The second file that works with the boot.txt file is the default file found within the pxelinux.cfg folder. This folder will be pulled from an Ubuntu mirror. The folder is located at http://mirror.anl.gov/ubuntu/dists/lucid/main/installer-i386/current/images/netboot/. From within the /var/lib/tftpboot folder, use wget to pull the directory contents:
wget -nH -np -r --cut-dirs=8 http://mirror.anl.gov/ubuntu/dists/lucid/main/installer-i386/current/images/netboot/
There should now be a pxelinux.cfg folder inside the tftpboot folder. The “default” file inside the pxelinux.cfg folder needs to be edited, as it is the file that tells the client exactly where the installation files are located.
Because this example uses only Ubuntu Lucid i386 or amd64, the edited default file will be fairly simple, as shown below:
DISPLAY boot.txt default 1 label 1 kernel ubuntu/lucid/amd64/linux append vga=normal initrd=ubuntu/lucid/amd64/initrd.gz label 2 kernel ubuntu/lucid/i386/linux append vga=normal initrd=ubuntu/lucid/i386/initrd.gz prompt 1 timeout 0
Next, the installation files for both the i386 and amd64 installs need to be put into the /var/lib/tftpboot/ubuntu/lucid/i386 and amd64 folders. From within the /var/lib/tftpboot/ubuntu/lucid/i386 folder, use wget to get the necessary files:
wget -nH -np -r --cut-dirs=10 http://mirror.anl.gov/ubuntu/dists/lucid/main/installer-i386/current/images/netboot/ubuntu-installer/i386/
From within the /var/lib/tftpboot/ubuntu/lucid/amd64 folder, do the same, except replace i386 with amd64:
wget -nH -np -r --cut-dirs=10 http://mirror.anl.gov/ubuntu/dists/lucid/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/
Now all the pieces of the install server are in place. At this point, restart tftpd-hpa:
service tftpd-hpa restart
UBUNTU REPOSITORY SERVER (MIRROR)
An Ubuntu repository server, otherwise called a mirror, contains all the packages that can be installed on an Ubuntu system, including third-party software such as Adobe Reader. To create an Ubuntu mirror, we need two packages: apt-mirror and apache2.
apt-get install apache2 apt-mirror
The apache2 settings can be left at the default settings. Apt-mirror needs to know what releases to mirror. The /etc/apt/mirror.list file specifies which Ubuntu repositories to mirror locally. Making sure to use a nearby mirror, mirror.list should look something like this:
############# config ################## # # set base_path /var/spool/apt-mirror # # set mirror_path $base_path/mirror # set skel_path $base_path/skel # set var_path $base_path/var # set cleanscript $var_path/clean.sh # set defaultarch <running host architecture> # set postmirror_script $var_path/postmirror.sh # set run_postmirror 0 set nthreads 20 set _tilde 0 # ############# end config ############## deb-i386 http://mirror.anl.gov/ubuntu lucid main restricted universe multiverse deb-i386 http://mirror.anl.gov/ubuntu lucid-security main restricted universe multiverse deb-i386 http://mirror.anl.gov/ubuntu lucid-updates main restricted universe multiverse deb-i386 http://mirror.anl.gov/ubuntu lucid main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer deb-amd64 http://mirror.anl.gov/ubuntu lucid main restricted universe multiverse deb-amd64 http://mirror.anl.gov/ubuntu lucid-security main restricted universe multiverse deb-amd64 http://mirror.anl.gov/ubuntu lucid-updates main restricted universe multiverse deb-amd64 http://mirror.anl.gov/ubuntu lucid main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer #Clean clean http://mirror.anl.gov/ubuntu
A cron job is available for apt-mirror. It is located in /etc/cron.d/apt-mirror and can be activated by uncommenting the cron job and restarting cron. Apt-mirror will initially take several hours to download all the packages, depending on the speed of the Internet connection. Subsequent runs of apt-mirror will only download new updates, if any, and will not require so much time.
Symlinks will link the default apache webpage to the repository packages. From within /var/www, an ubuntu symlink is all that is needed for a network install.
ln -s /var/spool/apt-mirror/mirror/mirror.anl.gov/ubuntu/ ubuntu
The command above creates a symlink called ubuntu within the /var/www folder which links to the /var/spool/apt-mirror/mirror/mirror.anl.gov/ubuntu folder. Running ls /var/www/ubuntu should show the dists and pool folders. At this point, a restart of apache will complete the repository server.
USING PXE, AND THE NETWORK INSTALL AND REPOSITORY SERVERS TOGETHER
With the servers ready to go, a client computer simply has to boot to lan. The client computer will receive booting instructions from the DHCP server and will start pulling install files from the /var/lib/tftpboot folder of the install server. The Ubuntu installation will start and when it asks for which mirror to use, the ip address or hostname of the repository server can be given to the client, which will then pull the latest available packages from the repository server. When the client installation finishes, it will reboot into an up-to-date fresh install of Ubuntu.