HowTo: Get an Ubuntu Live CD to boot off a PXE server
Following my article about creating your own PXE network boot server, here is the first practical use you can put it to – taking the Ubuntu Live CD and turning it into a network-bootable version!
Network booting the Live CD has obvious advantages – aside from booting faster than CD (especially on a gigabit network), it is indispensable as an emergency boot medium in a workplace environment, especially for broken Windows systems, and allows for Ubuntu effortless installations on netbook PC’s that don’t have optical drives and saves you having to have a USB stick handy.
Pre-requisites
- You need a working Linux PXE boot server. Doesn’t have to be Ubuntu, but it needs to be Linux. You cannot use a Windows PXE server.
- An Ubuntu 10.04 Live CD ISO or physical CD. Can be the 32-bit or 64-bit ISO, but you can also setup both of them at once!
- At least 700MB of drive space on your PXE server, more if you want to have more than one CD available.
- This tutorial was put together using Ubuntu Server 10.04 Lucid Lynx, but should work with all future releases and older versions to at least Ubuntu Server 8.04 Hardy Heron.
Getting it together
- Login to your PXE server and mount the CD or ISO image (in this example we are copying the 32-bit disc). Assuming the CD is mounted at /media/cdrom, copy the CD’s files to your server as follows:
$ sudo mkdir -p /srv/tftp/ubuntu-livecd-boot/i386
$ sudo mkdir -p /srv/ubuntu-livecd/i386
$ sudo cp -av /media/cdrom/* /srv/ubuntu-livecd/i386
$ sudo cp -av /media/cdrom/.disk /srv/ubuntu-livecd/i386
$ sudo cp -av /media/cdrom/casper/initrd.lz /srv/tftp/ubuntu-livecd-boot/i386
$ sudo cp -av /media/cdrom/casper/vmlinuz /srv/tftp/ubuntu-livecd-boot/i386
- (if you want to setup the 64-bit disc, then replace all instances of “i386″ with “amd64″, or you can setup both architectures by setting up both directories)
- Make sure the permissions of the files to be loaded by TFTP are correct:
$ sudo chmod 777 -R /srv/tftp
- The astute of you will have noticed that we have copied the Ubuntu CD outside of the TFTP directory and that we have made a separate copy of only two of the disc’s files inside the TFTP directory. Why is this? Well, the vmlinuz and initrd.lz files are the only files that TFTP will need to download to get started with the boot process. After that, we will use NFS to deliver the rest of the Live CD, so let’s set that up:
$ sudo apt-get install nfs-kernel-server
Note: I should point out that the files that are copied to the NFS share do not have to be on the PXE server. The NFS server can be any box as NFS is not related to PXE at all. - Once that is installed, we need to define an NFS share. This is done in the NFS exports file, so let’s get that into a text editor:
$ sudo nano /etc/exports
- Add the following line to the bottom of the file:
# Ubuntu Live CD files for PXE booting
/srv/ubuntu-livecd/i386 *(ro,async,no_root_squash,no_subtree_check)
…if you are setting up the 64-bit version, replace “i386″ with “amd64″, or if setting up both architectures, list it as follows:# Ubuntu Live CD files for PXE booting
/srv/ubuntu-livecd/i386 *(ro,async,no_root_squash,no_subtree_check)
/srv/ubuntu-livecd/amd64 *(ro,async,no_root_squash,no_subtree_check)
A breakdown of the parameters on the right is as follows:- The asterisk means “share with everyone on this network, regardless of who they are”.
- The “ro” parameter means to share the data as read-only.
- The “async” parameter allows the NFS server to reply before data is written to the share. Since it’s mounted as read-only anyway, the parameter is only there to keep NFS’ syntax happy.
- The “no_root_squash” parameter means to allow the NFS client to use the mount as a root filesystem, otherwise it’s mounted as “nobody” instead of “root”. Since the LiveCD is essentially a diskless client, we need to be able to define the NFS mount as a root volume.
- The “no_subtree_check” parameter helps to speed up transfers. Normally NFS will check to see if a requested file exists in an exported sub-directory. This slows things down, so turning this off means the only check that is made is that the requested file exists on the exported filesystem. Subtree checking can also cause issues when an open file is renamed, but since the export is read-only, this is irrelevant.
- Save your changes with CTRL+X, then “Y” and then Enter.
- Now have NFS re-read its export file and begin sharing the specified directories with:
$ sudo exportfs -a
- We’re nearly ready to rock and/or roll. All we need to do now is prepare the PXE boot menu to launch the Live CD for us. Assuming you followed by previous tutorial and your boot menu file is called mybootmenu.cfg:
$ sudo nano /srv/tftp/mybootmenu.cfg
- Assuming your NFS server’s IP address is 192.168.0.10, insert the following lines for a 32-bit Live CD entry:
label Live CD 32-bit
kernel ubuntu-livecd-boot/i386/vmlinuz
append boot=casper netboot=nfs nfsroot=192.168.0.10:/srv/ubuntu-livecd/i386 initrd=ubuntu-livecd-boot/i386/initrd.lz -- splash quiet
…and if you are doing 64-bit, you can replace or add as a separate menu option the following:
label Live CD 64-bit
kernel ubuntu-livecd-boot/amd64/vmlinuz
append boot=casper netboot=nfs nfsroot=192.168.0.10:/srv/ubuntu-livecd/amd64 initrd=ubuntu-livecd-boot/amd64/initrd.lz — splash quiet
The kernel line is the actual kernel that is loaded to run the session. The append line tells the boot process several things. First up, the casper directory contains the boot files (a SquashFS image in the case of the Live CD), the root of the NFS file system is located on the server with the IP 192.168.0.10 under the path /srv/ubuntu-livecd/i386 (or amd64) and that the image to fire up the RAM disk with is located under ubuntu-livecd/i386/initrd.lz and finally we have advised the boot process to suppress console messages and display the splash screen while loading. From this point on, the initrd.lz is extracted and will grab the SquashFS image from the casper directory via NFS, extract it and commence running it. All other files that the disc needs to do its thing (such as when installing Ubuntu from the Live environment) are also provided by the NFS share. - Save your changes by pressing CTRL+X, then “Y” and then Enter.
- You’re now ready to go – reboot your PXE workstation and you should now see an entry for your Live CD. Upon choosing it, your system should fire up with the Live environment! Once booted, you can even do an Ubuntu install to the PC you started on as though you’d booted from a CD or USB device!
Enjoy!