Ubuntu PXE

Diskless booting is a method of booting a PC without the need for a harddrive. Instead, the client PC boots from a network attached harddrive provided by a server computer or a NAS device. Its pretty cool and can be very useful for re-purposing old computers.

Install Dnsmasq

For diskless booting to work, you need to have your LAN configured with a tftp server and a PXE enabled dhcp server. Dnsmasq can do both these things (and more). So install it on your server computer. (Also, checkout my previous post on how to configure dnsmasq as your home dhcp and dns server)

sudo apt-get install dnsmasq

and configure dnsmasq for tftp and pxe service:

#enable tftp service enable-tftp tftp-root=/opt/tftpboot
#enable pxe service to point to this tftp-server. Use this instead of the older dhcp-boot pxe-service=x86PC, "Netboot Linux", pxelinux

Get a Vanilla Ubuntu Distro

Debootstrap will download and install a bare-bones debian distro to the filesystem.

sudo debootstrap --arch amd64 precise /opt/nfsroot/ubuntu/12.04/amd64 http://us.archive.ubuntu.com/ubuntu/

Chroot into your new distro and prepare for diskless booting:
Create a new user and give sudo permission

sudo chroot /opt/nfsroot/ubuntu/12.04/amd64 adduser <new username> usermod -a -G sudo <new username>  

set /etc/fstab

proc            /proc           proc    defaults        0       0 /dev/nfs        /               nfs     defaults        1       1 none            /tmp            tmpfs   defaults        0       0 none            /var/run        tmpfs   defaults        0       0 none            /var/lock       tmpfs   defaults        0       0 none            /var/tmp        tmpfs   defaults        0       0  

now mount everything with

mount -a

set your new system’s hostname to whatever you want:

echo "new system hostname" > /etc/hostname

install linux-image package. This will add a Linux kernel and initrd to your distro root (/vmlinuz and /initrd.img)

apt-get install linux-image

Choose to NOT install grub when it prompts you.

Update your initrd image do boot from nfs:

sed -i 's/^MODULES.*/MODULES=netboot/' /etc/initramfs-tools/initramfs.conf sed -i 's/^BOOT.*/BOOT=nfs/' /etc/initramfs-tools/initramfs.conf update-initramfs -u  

Set the network device to manual. This is very important. If you forget to set this, the system will assume iface eth0 auto, which will try to reconfigure your ethernet device, and you will loose your nfs connection and the entire system will freeze.

add this line to /etc/network/interfaces

iface eth0 inet manual

Now exit the chroot enviroment and copy the initrd and vmlinuz to your tftp server

exit sudo cp /opt/nfsroot/ubuntu/12.04/amd64/boot/initrd.img-3.2.0-23-generic /opt/tftp/ /opt/tftpboot/Ubuntu/12.04/amd64/initrd.img sudo cp /opt/nfsroot/ubuntu/12.04/amd64/boot/vmlinuz-3.2.0-23-generic /opt/tftpboot/Ubuntu/12.04/amd64/vmlinuz sudo chmod a+r /opt/tftpboot/Ubuntu/12.04/amd64/*  

Reboot your client machine and you should be good to go. After you boot into your new machine, you can install the full desktop if you wish:

sudo apt-get install ubuntu-desktop




Paul Soucy

Read more posts by this author.