Preparing a Linux NFS Root to boot directly from the local machine

Overview

The purpose of this document is to keep track of the steps I performed in converting a computer which used to boot using dhcp/tftp/nfs into one that booted using its own local drive. Additionally, I am adding notes about things that, in hindsight, may have been easier.

Why?

I created this NFS root for booting a Soekris Embedded Device. (I used a net4801.) These instructions are based on the guide Mike Machado created Here, which was written for Debian Potato. Before continuing with these instructions, consider your own "why?", since the answers may change how you proceed.

Terminology

A brief note on the language I'm using. The NFS root export directory will be called the "root filesystem area". The distribution installed there will be called the "installation". The original distribution running on this computer will be called the "host", and the computer will be the "host machine". The computer that will be using the NFS share will be called the "remote machine". Additionally, the copy of the installation on the remote machine will be called the "remote root".

Preparation

Before beginning this process, your remote machine should be able to start and operate normally from the NFS server. Depending on what kind of media you want to use as the remote root, you may also want to work on making it start properly with root mounted read-only (you can set the NFS share to be read only). Because I am writing this for the Soekris, running from a 256MB compact flash drive, I set this up to be "mostly" read-only, with some things read-write. This is due to the limited number of write cycles before a CF card will cease to operate properly.

As a side note, setting the NFS root up to run read-only can let you do interesting things like run several identical machines from the same NFS share by keeping them from interfering with each other.

Also as a side note, I should document what I did to make it work "mostly" read-only and how I captured "stateful" information between boots (like random-seed)...

Filesystem Transfer

The key to transferring the filesystem is to be careful in transferring /dev, /proc, and other special files (sockets, etc.). If you try to use cp without excluding these, you'll find yourself filling the harddrive with the data read from device nodes, or a copy of /proc/kcore. Thus, the easiest way to do this is from the host machine, using tar in the /nfs/root directory, then extracting that tarball into the remote machine's drive. Make sure that your filesystem will fit on whatever drive you're going to use.

Preparing the Filesystem to boot

Converting the system configuration to use the local drive instead of the host's NFS share is the next step in the process. From here on out, everything uses the remote system. Start by updating /etc/fstab to have / point to the local partition rather than the NFS server. Next, update the pxelinux.cfg/default file in the tftp server so that the kernel will use the local filesystem rather than NFS for the root. Now reboot the remote machine so that it starts up using the root installation.

Next, you will need to install a boot loader. For now, I am using lilo. On the Soekris, the compact flash drive is /dev/hdb. In /etc/lilo.conf I have set:
lba32
boot=/dev/hdb
root=/dev/hdb1
install=text
map=/boot/map
vga=normal
prompt
timeout=50
image=/boot/vmlinuz
  label="Linux"
  append="console=ttyS0,19200n81 ip=DHCP panic=10"
  read-only

If you configure a static IP address in /etc/network/interfaces then leave the ip=DHCP out. You can also leave it out if you intend to use a user-space DHCP client like dhcpcd, pump, or dhcp-client. Run /sbin/lilo to install the boot sector and configuration, then reboot again, this time booting from the local drive rather than the network.

This document was last updated 2005-02-13