HowTo: Create a Diskless workstation that boots from PXE using Ubuntu
Diskless booting is where a PC starts up purely from a network connection. It does not have a physical hard-drive in it to start from in the traditional manner.
Why would you want to do this? Well, say for example you have a MythTV Frontend PC. For the most part, most Frontends are dedicated PC’s connected to a TV or projector that are not used for any other purpose, so technically there is really no need to have a hard-drive inside one as nothing new will ever be stored (all the media is streamed from the Backend server). There’s also the added bonus of less noise by not having a hard-drive installed.
Another good example of using a Diskless boot environment is for performing offline virus scans of Windows based PC’s in a safe environment that is not Windows, using tools like ClamAV. In a corporate environment, having a “normal” installation makes it easier to setup default settings that normally don’t suit booting up from an Ubuntu Live CD, such as corporate Proxy settings. Making a Diskless Boot setup is far easier than creating a customised Live CD in this instance.
So how exactly do you create a diskless booting PC?
Pre-requisites:
- First up, you need a working PXE server. If you haven’t built one yet, you can refer to my previous tutorial on how to build one.
- Sufficient space to store a typical Ubuntu Desktop install. I would recommend having at least 10GB free to allow space for both the OS and any additional apps you might install.
- A PC that you will using as your diskless machine that has the ability to boot from PXE.
- A temporary hard-drive for your diskless machine that we will be using to do our initial build on.
- A fast network. Diskless booting is only useful if your network can transfer data quickly. I would recommend that you use a gigabit network.
- It is recommended to have at least 2GB RAM on your diskless PC, primarily because we will not be running a swap file or swap partition (swapping over a network connection is just silly).
- Ubuntu 10.04.2 LTS was used for this tutorial, but you should be able to use just about any release of Ubuntu. Note: The version of Ubuntu on your PXE server and the version of Ubuntu you are turning into diskless boot does not have to be the same version, but I would recommend using 10.04.2 LTS or later.
What to do:
- First up, install the temporary hard-disk into your PC that is going to become diskless. You can attach it in the traditional way or connect it via USB.
- Perform a normal installation of Ubuntu Desktop Edition onto the hard-drive of your PC.
- Once installed, update the system with any outstanding system updates.
- Install any additional apps you wish to utilise on this machine, such as MythTV.
- Once you are satisfied that your installation is setup the way you want it, we need to prepare the installation to be able to boot via PXE. Start by opening up a terminal and type in the following commands:
$ cd ~
$ sudo nano /etc/initramfs-tools/initramfs.conf - You will now be looking at a text configuration file in the Nano text editor. This is the configuration file that controls how the boot-time RAM disk image is created. We need to modify it so that we can create a PXE-ready version of the RAM disk image instead of the usual type. Scroll down until you find the configuration line that looks like:
MODULES=most
…and modify it so that is now looks like:MODULES=netboot
- Scroll down a little further until you see the line:
BOOT=local
…and change it to read:BOOT=nfs
- Press CTRL+X, then “Y” and then “Enter” to save your changes. You will be returned to the Terminal prompt.
- Now let’s create our custom RAM Disk image using the following command:
$ sudo mkinitramfs -o ./initrd.img
- Once that has finished, we also need an unmodified copy of the current kernel you are running:
$ cp /boot/vmlinuz-`uname -r` ./vmlinuz
- Now we need to prep the server. First up, we need to setup a way to transfer our temporary hard-disk contents to the PXE server, and we also need to ready how the PXE server will serve the data to the diskless workstation when booting. We will be using the Network File System, or NFS for short. On your Ubuntu PXE Server, open a terminal and type in the following:
$ sudo apt-get install nfs-kernel-server
- Once the NFS server is installed, we need to setup the directory that will store and serve the Diskless system’s files. Assuming you have all your PXE related data under /srv/tftp, let’s create the following for our Diskless station data:
$ sudo mkdir -p /srv/nfs/disklessboot
- Now let’s tell the NFS server about this new directory:
$ sudo nano /etc/exports
- In the text file that appears in the Nano text editor, scroll to the bottom of the file and add the following line:
/srv/nfs/disklessboot *(rw,no_root_squash,async,no_subtree_check)
The above will allow read/write access to the path /srv/nfs/disklessboot on your PXE server from any incoming IP address. - Save your changes by pressing CTRL+X, then “Y” and then “Enter”.
- Now activate the new NFS shareby using the following command:
$ sudo exportfs -a
- We’re nearly there! Now we just need to transfer the contents of our temporary workstation hard-drive to the new NFS share. On your soon-to-be-diskless PC (not the server), and assuming that your PXE server’s IP address is 192.168.0.10, type the following in a Terminal:
$ sudo apt-get install nfs-common
$ mkdir /dev/shm/nfs
$ sudo mount -t nfs -nolock 192.168.0.10:/srv/nfs/disklessboot /dev/shm/nfs
The above will create a directory in your RAM disk to mount the PXE server’s NFS share on and the second command will mount the NFS share /srv/nfs/disklessboot in the directory you just created in your RAM disk locally, thus allowing you to now read and write data to that NFS share by using /dev/shm/nfs locally. - Now let’s copy the OS files from the temporary hard-disk to the PXE server’s NFS share:
$ sudo cp -avx /. /dev/shm/nfs/.
$ sudo cp -avx /dev/. /dev/shm/nfs/dev/.
The above commands will take a minute or two to finish and will show you a giant list of files being copied. - We are now done with the soon-to-be-diskless PC, so shut it down and remove your temporary hard-drive.
- Go back to your server and type in the following at the Terminal prompt:
$ sudo mkdir -p /srv/tftp/disklessboot
$ sudo cp /srv/nfs/disklessboot/home/USERNAME/vmlinuz /srv/tftp/disklessboot/
$ sudo cp /srv/nfs/disklessboot/home/USERNAME/initrd.img /srv/tftp/disklessboot/
Note: Replace USERNAME above with whatever your username was on the temporary hard-disk setup, eg: “/home/jbloggs/” - We now need to change the network setup of the disklessboot install so that it doesn’t try to configure itself with a new IP address on boot (since it’ll already have one when you do the initial PXE boot):
$ sudo nano /srv/nfs/disklessboot/etc/network/interfaces
- Look for a reference to “eth0″ which is your first ethernetadapter. It will generally be the last line in the file and may look like:
auto eth0
…or:iface eth0 inet dhcp
- Once you locate it, comment out that line by putting a hash symbol at the front like so:
#auto eth0
…or:#iface eth0 inet dhcp
- Now add a new line with the following:
iface eth0 inet manual
- Save your changes with CTRL+X, then “Y” and then “Enter”.
- Now we need to ensure that the devices mounted by your disklessbooting PC do not try to mount physical disk devices for things like /home and the root filesystem. Type in the following command:
$ sudo nano /srv/nfs/disklessboot/etc/fstab
- Once in the text editor, DELETE EVERYTHING and replace it all with the following:
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 - Save your changes with CTRL+X, then “Y” and then “Enter”.
- That’s the Diskless setup ready to go. All that we now need to do is configure the PXE boot menu to give you an option to boot Diskless. To do this, edit your PXE boot menu configuration file. Assuming you called it /srv/tftp/mybootmenu.cfg, type in the following:
$ sudo nano /srv/tftp/mybootmenu.cfg
- In the text editor, scroll down to the bottom of your configuration file and add the following lines:
label My Diskless Boot PC
kernel disklessboot/vmlinuz
append initrd=disklessboot/initrd.img root=/dev/nfs nfsroot=192.168.0.10:/srv/nfs/disklessboot ip=dhcp rw
The above menu configuration will tell PXE to load the kernel and custom RAM disk image from the TFTP directory and then transfer control of the boot process to the OS files located in /srv/nfs/disklessboot which will be mounted on the diskless system at /dev/nfs as the root filesystem. - Save your changes by pressing CTRL+X, then “Y” and then “Enter”.
- Finally, make sure that the TFTP daemon can read the new files you added to it with the following command:
$ sudo chmod 777 -R /srv/tftp
- That’s it! You are now ready to boot! Turn on your now-diskless PC and tell it to boot from PXE. When the PXE boot menu appears, choose “My Diskless Boot PC” and watch in wonder and amazement as Ubuntu boots up without a hard-disk as if by magic!
NOTE: Whilst the Diskless PC will boot and operate much like any ordinary PC and in fact you can indeed perform future system updates this way, be aware that the kernel itself will NOT get automatically updated. Newer kernels will get installed to the NFS mount as you would expect, however the kernel actually boots from your TFTP directory, not the NFS share, so if you do update the kernel in future, you must create a new RAM disk image manually as per step 9 and copy both it and the new kernel file into your TFTP’s directory (in this case /srv/tftp/disklessboot/) otherwise your updated system will not boot anymore. Alternatively, simply allow all updates to be performed except for kernel updates.
Finally, hardware drivers: If you install the NVidia proprietary drivers for your Diskless Boot system, ensure that you don’t try to boot other systems that do not contain NVidia graphics hardware otherwise X will break. The reason for this is that the NVidia driver installation makes a number of changes to system-level libraries to work, effectively binding that system to NVidia graphics-based systems only. If you intend to use your Diskless setup on multiple hardware platforms, such as NVidia, Intel and ATi, do not install the proprietary NVidia (or ATi) driver.
Enjoy!
Leave a Reply