News

Boot Linux from an NFS server

Diskless booting allows you to access the same distro from multiple locations on a network without juggling files

RS33951_edit_Android 290968-1

While movies like to think they’re still common, the concept of a mainframe with dumb terminals is a bit of an obsolete concept now. The proliferation of high-powered machines made it easier to give everyone their own system and that hasn’t really changed.

What has changed, though, is the way we treat data, which is now backed up to the cloud so it’s ever-accessible, or jostling around in our pocket on tiny USB storage devices with more memory than you’d ever need for word processing documents. If you’re often moving between different computers within the same network, a more updated version of the classic mainframe solution may prove beneficial.

With NFS booting, the core kernel and file systems are kept on a central server and then pushed out onto client systems to be booted on there. That means your files and desktop will always be available wherever you want to log in.

This tutorial needs a server that’s dedicated to hosting the distro and is always on – specifically an Ubuntu server – to be able to serve Ubuntu around a network.

RS33951_edit_Android 290968-1

Resources

An Ubuntu server

Step-by-step

Step 01 First installation

The first job is to install some specific packages on the server side. Open up the terminal DHCP, NFS tools and a few other things with:

$ sudo apt-get install dhcp3-server tftpd-hpa syslinux nfs-kernel-server initramfs-tools

Step 02 Configure DHCP

The server will need to have a DHCP server set up. To do this, open the terminal and get to the DHCP config file by typing sudo nano /etc/dhcp/ dhcpd.conf. Start by adding the following lines to the end of the file:


allow booting;
allow bootp;

Step 03 Configure the subnet and IPs

Add this next:

subnet 192.168.x.0 netmask 255.255.255.0 {
   range 192.168.x.xxx 192.168.x.xxx;
   option broadcast-address 192.168.x.255;
   option routers 192.168.x.xxx;
   option domain-name-servers 192.168.x.xxx;
   filename "/pxelinux.0";
}

Changing the ‘x’ placeholders to your network.

Step 04 Configure PXE options

Finish it off with a PXE instruction to force the client to these settings. This works especially well if you plan to use multiple disc images.

host pxe_client {
   hardware ethernet xx:xx:xx:xx:xx:xx;
   fixed-address 192.168.x.xxx;
}

Step 05 Restart DHCP

Save the file to confirm the changes – they can always be modified further at a later date if any settings change. Before moving on, the server needs to be restarted by using:

$ sudo service isc-dhcp-server restart

Step 06 Create a TFTP server

There needs to be a way to transfer boot files and this can be done with a TFTP server. Open up the config file with sudo nano /etc/default/ tftpd-hpa and add the following to the file:

RUN_DAEMON="yes"
OPTIONS="-l -s /tftpboot"

Step 07 Create a TFTP directory

There needs to be a root directory for some of the TFTP files for the setup to work properly. This is linked with PXE booting protocols so this directory and the initial file needs to be created with:

$ sudo mkdir -p /tftpboot/pxelinux.cfg

Step 08 TFTP bootfiles

The current PXE boot configuration files need to be copied over to the TFTP directories so they can be used by the server. This is done with:

$ sudo cp /usr/lib/syslinux/pxelinux.0 /tftpboot

Step 09 Default kernel configuration

Create a new file with sudo nano /tftpboot/pxelinux.cfg/default and add the following with the necessary details:

LABEL linux
KERNEL vmlinuz-[kernel number]
APPEND root=/dev/nfs initrd=initrd.img-[kernel number] nfsroot=192.168.1.2:/nfsroot ip=dhcp rw

Step 10 Finish up TFTP

The final step is to get the TFTP server working properly. To do this, the correct permissions need to be set with:

sudo chmod -R 777 /tftpboot

…which finally means the TFTP server can be startedusing:

$ sudo /etc/init.d/tftpd-hpa start

Step 11 Root files

There needs to be a folder to hold the files for the client OS, make this with sudo mkdir /nfsroot. Export nfsroot by using sudo nano /etc/exports and add the following line:

/nfsroot 192.168.x.xxx(rw,no_root_ squash,async,insecure)

Save and sync it all with sudo exportfs -rv

Step 12 Client setup

The client system needs to start out having a hard drive installed into it. Get the versions of Ubuntu you want to use and install it with standard settings to the system. Once the tutorial is finished, remove the hard drive.

Step 13 Client kernel

For the moment stay on the client and open the terminal. Copy kernel version to the home directory in case it needs to be restored a bit further down the line to fix an issue. Do this with:

$ sudo cp /boot/vmlinuz-`uname -r` ~

Step 14 Modify the init file

Some boot flags need to be changed so the system knows to boot from the network. Open up the config file with sudo nano /etc/initramfs-tools/ initramfs.conf and make sure the following two variables read as below:

BOOT=nfs
MODULES=netboot

Step 15 Modules and making

Find out what modules you’ll need for your network adapter and add them to the network modules file which can be accessed sudo nano /etc/initramfs-tools/modules. Once finished, save the file and finish the boot files by typing:

$ mkinitramfs -o ~/initrd.img-`uname -r`

Step 16Copy OS to server

Now that the client is completely set up, you can start transferring the files across to the server. Do this by typing in the following three commands:

$ mount -t nfs -onolock 192.168.1.2:/nfsroot/mnt
$ cp -ax /. /mnt/.
$ cp -ax /dev/. /mnt/dev/.

Step 17 Back to server

After everything has finished transferring over from the client, return to the server and open back up the terminal. The kernel and init files need to be copied to the tftp directories with:

$ sudo cp ~/vmlinuz-`uname -r` /tftpboot/
$ sudo cp ~/initrd.img-`uname -r` /tftpboot/

Step 18 Network modifications

To ensure the DHCP settings remain constant, the network interfaces config file needs to be updated. Edit it with sudo nano /nfsroot/etc/ network/interfaces and change these lines:

auto lo
iface lo inet loopback
iface eth0 inet manual

Step 19 Update the fstab

Open up fstab (sudo nano /nfsroot/etc/fstab) and make sure it looks like this:

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
/dev/hdc   /media/cdrom0   udf,iso9660   user,noauto   0       0

Step 20 Client BIOS

Reboot the client system, and enter the BIOS to find the boot menu settings. Make sure network boot is moved up to the first option and if that can be modified further choose PXE.

Step 21 Boot over the network

Reboot the client and it will begin the initial boot process, taking the kernel and PXE image from the server. This will work across multiple systems as long as they’re set up correctly.

Step 22Benefits

Everything working fine on the clients? You can now remove their hard drives if you never plan to use them for extra storage and put them to be better use on a file server, or as extra space in the main PXE server. The computers will now boot over the network without needing any internal storage.

×