Random Post: bacula-2.2.5-1 etch backport
RSS .92| RSS 2.0| ATOM 0.3
  • Home
  •  

    diskless booting with PXE and NFS

    For a long time now I’ve wanted to set up all my mythfrontends to be diskless nodes that boot via PXE using an NFS share as their root filesystem. I finally got around to doing this. I was even able to just migrate my existing installations directly into the PXE boot environment. Here is how I accomplished it…

    The first thing youll need is a TFTP server. This will serve out the kernel and initrd images to clients on the network.

    root@pxe:~$ apt-get install tftpd-hpa
    

    That will install a good tftp server daemon and create the tftp root for you in /var/lib/tftpboot. Some HOWTO’s on the Internet suggest installing the syslinux package as well which provides a needed file (pxelinux.0). I prefer to download the entire netboot environment for debian since this will also provide a network bootable installer for Debian on top of the other goodness we are creating today.

    root@pxe:~$ cd /var/lib/tftpboot
    root@pxe:~$ wget http://ftp.debian.org/debian/dists/lenny/main/installer-i386/current/images/netboot/netboot.tar.gz
    root@pxe:~$ tar xzvf netboot.tar.gz
    

    The kernel and initrd you are going to use to boot the mythbox must reside on the TFTP server. Furthermore, the initrd must be updated to support NFS root. On the mythbox I was migrating to the NFS root, it looked like this:

    root@mythbox:~$ sed -i 's/BOOT=local/BOOT=nfs/'  /etc/initramfs-tools/initramfs.conf
    root@mythbox:~$ /usr/sbin/mkinitramfs -o /boot/initrd.img-2.6.26-1-686_netboot
    

    Now just copy the /boot/vmlinuz-2.6.26-1-686 and /boot/initrd.img-2.6.26-1-686_netboot to /var/lib/tftpboot/ on the TFTP server.

    Last step for the TFTP server is to create a config file for our mythbox. If you dont create one specifically for it, it will instead boot the network installer as mentioned above. Create the file /var/lib/tftpboot/pxelinux.cfg/01-$(hardware ethernet address). Including the hardware address in the file name binds that config to the particular workstation we are working on today. In my case, the file name is 01-00-19-db-4a-6a-0e.

    LABEL linux
    KERNEL vmlinuz-2.6.26-1-686
    APPEND root=/dev/nfs initrd=initrd.img-2.6.26-1-686_netboot nfsroot=192.168.1.108:/srv/nfs/mythbox.pixelchaos.net ip=dhcp rw
    

    Now that our TFTP server is up and running we will next need to configure a DHCP server to provide IP addresses to netboot clients, as well as point them to the TFTP server to continue the boot process.

    root@dhcp:~$ apt-get install dhcp3-server
    

    That will install the DHCP service for you. Now we just need to add one little section to /etc/dhcp3/dhcpd.conf for the workstation we are going to netboot.

    host mythbox {
    hardware ethernet 00:19:db:4a:6a:0e;
    fixed-address mythbox.pixelchaos.net;
    filename "pxelinux.0";
    next-server 192.168.1.115;
    }
    

    host mythbox: mythbox is just the descriptive name for this configuration block .You can use any name you like.
    hardware ethernet 00:19:db:4a:6a:0e: This is the hardware ethernet address of the workstation we are netbooting.
    fixed-address mythbox.pixelchaos.net: This tells the DHCP server what address to assign the mythbox. You can use a FQDN (if its resolvable!) or an IP address.
    filename “pxelinux.0″: This is the PXE boot loader file that we installed onto our TFTP server earlier.
    next-server 192.168.1.115: This is the IP address of our TFTP server. It tells the mythbox where the “next server” is after it gets its IP address from the DHCP server. The “next server” can be any machine on the network. It can even be the same one running DHCP.

    Once all that is done, restart your DHCP server.

    root@dhcp:~$ /etc/init.d/dhcp3-server restart
    

    Now for the third piece of the puzzle, our NFS root filesystem. You’ll first need to create a directory to share.

    root@nfs:~$ mkdir /srv/nfs/mythbox.pixelchaos.net
    

    Now add that directory to /etc/exports so that it gets shared via NFS with this line:

    /srv/nfs/mythbox.pixelchaos.net mythbox(rw,async,no_root_squash)
    

    The rw, async, and no_root_squash options are important. Dont omit them. At this point we can reload all our NFS exports to active this new share point.

    root@nfs:~$ exportfs -rv
    

    At this point the entire TFTP, DHCP, and NFS parts of the environment are ready to go. Now we will migrate our existing installation of Linux from the mythbox onto its new nfsroot. First we make a directory to mount the NFS share on and then mount it.

    root@mythbox:~$ mkdir /mnt/nfs
    root@mythbox:~$ mount -t nfs -o nolock 192.168.1.108:/srv/nfs/mythbox.pixelchaos.net /mnt/nfs
    

    Now we run a cp command on every locally mounted partition, as well as /dev. On my mythbox it looked like this:

    root@mythbox:~$ cp -axv /. /mnt/nfs/.
    root@mythbox:~$ cp -axv /boot/. /mnt/nfs/boot/.
    root@mythbox:~$ cp -axv /home/. /mnt/nfs/home/.
    root@mythbox:~$ cp -axv /dev/. /mnt/nfs/dev/.
    

    The last thing to do is edit two files that we copied up to /mnt/nfs. The first is /mnt/nfs/etc/network/interfaces. You’ll need to remove any lines that bring the interface up automatically. You want to remove anything like “allow-hotplug eth0″ and just leave a single line like “iface eth0 inet dhcp”. The network interface will have already been brought up by netboot normally and leaving in any “hotplug” or “auto” lines will bring it up again, which has the effect of destroying it.

    Now we remove all the old filesystems from /mnt/nfs/etc/fstab so that it looks like this:

    # /etc/fstab: static file system information.
    #
    # <file system> 		<mount point>   	<type>  <options>       <dump>  <pass>
    /dev/nfs        /               nfs     defaults 0 0
    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
    none            /media          tmpfs   defaults 0 0
    

    That should be it. Now just set the mythbox to use network booting in its BIOS and reboot.

    Cool, huh? :)

    4 Responses to “diskless booting with PXE and NFS”

    1. tomek says:

      Thanks a lot for this great how-to!

      I have just a problem …
      I have performed the steps from the how-to, but the startup does not work
      I get the folloing messages from boot:

      Begin: Mounting root file system … /init: .: line 171 can’t open /scripts/nsf
      … Kernel panic – no syncing: Attempted to kill init

      If I use the same tftp- and dhcp-server and the same configuration of them, but just the the net-installation works perfectly – I have just exchanged the content of the file “default” (from debian-installer) against the file 01- from this how-to.
      So I suppose the only problem is incorrect generated “initrd.img-2.6.26-1-686_netboo”

      Thanks in advance for any ideas …

    2. tomek says:

      Sorry, it was just a typo in initramfs.conf (“nsf” instead of “nfs”)
      Having corrected the typo, net-boot works perfectly.

      Thanks a lot again for the how-to!

    3. at0m says:

      Hoi,

      Suggestion: After mkinitramfs and the nfs copy, edit the local /etc/initramfs-tools/initramfs.conf and change “BOOT=local” back to “BOOT=nfs”.

      Reason: I had to try a couple of times, and wanted to keep local hd copy for in case, and kernel tried to find rootFS over nfs – which didn’t work because the server wasn’t setup properly yet. To fix that, I had to boot each client that was broken (a couple) from Debian Netinstall (smallest bootable ISO I could find), then chroot into /dev/hda1 and mkinitramfs again after the edit from the suggestion. So to avoid that, do the edit beforehand, like after nfs copy :)

      For the rest, this blogpost seems great, gave me much better insight in this whole process!

      Thanks,
      at0m.

    4. at0m says:

      **Correction:** After mkinitramfs and the nfs copy, edit the local /etc/initramfs-tools/initramfs.conf and change “BOOT=nfs” back to “BOOT=local”.

      That’s better :)

    Leave a Reply