Ubuntu 12.04 live NFS+PXE boot (diskless, casper kept)

Uncategorized 1 Comment

Today I was trying with Ubuntu live boot over NFS.

My goal was to set up an Ubuntu that can boot from network, map its root filesystem (or “/cdrom” mount point) from NFS, and run just as the CD would.

I have seen tutorials of Ubuntu Diskless boot and NFS setup on Ubuntu. All these were really long and complicated.

I have learned that after extracting the whole CD image to a directory (that can be reached over TFTP and NFS at “/ubuntu/12.04″on host 1.2.3.4 — more details about this can be read a bit below) the following boot parameters should be the correct ones:

label ubuntu
    kernel /ubuntu/12.04/casper/vmlinuz
    append root=/dev/nfs initrd=/ubuntu/12.04/casper/initrd.lz boot=casper netboot=nfs nfsroot=1.2.3.4:/ubuntu/12.04 ro

But…

The “rpc failed: 2” error

The “casper” supports NFS mount for “/cdrom” but with my NFS server I got the following messages:

rpc failed: 2

After digging the initramfs image, /init, /scipts/casper, /scripts/nfs, consulting Google, it seems the nfsmount was unable to mount the share (probably due to an incompatibility with NFS3 and NSF4), but suprisingly “mount -t nfs …” is able. So I have modified the /scripts/casprer script to use that instead of nfsmount – it is all working now!

Here is a patch to what I have done (diff -rupN):

--- ./scripts/casper.orig	2012-05-15 15:22:04.000000000 +0200
+++ ./scripts/casper	2012-05-15 15:24:45.000000000 +0200
@@ -223,11 +223,11 @@ do_nfsmount() {
         NFSOPTS=""
     fi
 
-    [ "$quiet" != "y" ] && log_begin_msg "Trying nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
+    [ "$quiet" != "y" ] && log_begin_msg "Trying mount -t nfs -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
     # FIXME: This while loop is an ugly HACK round an nfs bug
     i=0
     while [ "$i" -lt 60 ]; do
-        nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
+        mount -t nfs -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && rc=0 && break
         sleep 1
         i="$(($i + 1))"
     done

More on modifying the initramfs image – in a nutshell

In case of Ubuntu 12.04 the initramfs image is a CPIO image with LZMA compression.

You can decompress it by the following:

mkdir /tmp/ubuntu_boot
cd /tmp/ubuntu_boot
cat /cdrom/casper/initrd.lz | lzcat | cpio -i

You can do your modifications (for example the above one)

And compress it again (watch out for the correct cpio parameters!) like this:

cd /tmp/ubuntu_boot
find . | cpio --quiet --dereference -o -H newc | lzma -c9 > /tmp/initrd_new.lz

This article needs some more details, but the main goal, describing of the solution to rpc failed: 2 is here…

One thought on “Ubuntu 12.04 live NFS+PXE boot (diskless, casper kept)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.