Using the fsc mount option with nfsroot kernel parameter to allow FS-cache

I'm PXE-booting a Ubuntu 10.10 system, where I specify the kernel parameters as follows:

append root=/dev/nfs initrd=ubuntu-boot/initrd.img-2.6.35-24-generic
nfsroot=11.22.33.44:/data/nfsroot,fsc ip=dhcp rw

I need to use the mount option 'fsc' in order to use FS-cache functionality (the cachefilesd package.) However, when I try this I get the following error upon boot:

nfsmount: bad option 'fsc'

Why doesn't nfsmount permit this option? (It works fine when you mount manually with mount -o fsc after booting up.)

I changed nfsmount to mount -t nfs in the file /usr/share/initramfs-tools/scripts/nfs and then I ran update-initramfs -u to update the initramfs image, but it seems this still gives an error:

mount: unknown nfs mount option 'fsc'

My guess would be that this is a limitation of the mount functionality in klibc. What would be the best way to address this? Does the nfsmount program need to be patched?

Since this seems to be a limitation of the nfsmount tool in klibc, I was thinking that I could add /sbin/mount.nfs to the initramfs image and mount the nfsroot with this tool instead. I copied it into the folder /usr/lib/klibc/bin and I updated the script /usr/share/initramfs-tools/scripts/nfs as follows:

mount.nfs ${NFSROOT} ${rootmnt} -o nolock ${roflag} ${NFSOPTS}

After booting the updated initramfs image, there is a long delay when mount.nfs is executed and then the following message is displayed:

mount.nfs: an incorrect mount option was specified  
Begin: Retrying nfs mount ... Begin: Running /scripts/nfs-premount ... done.

However, this message is displayed no matter what mount options I use, so it appears to be a different problem altogether...


Solution 1:

I finally manged to solve it. Here are the steps:

  1. Add mount.nfs from Ubuntu 10.04 to the initramfs image (copy it into the /usr/lib/klibc/bin folder.)
  2. Change the nfsmount line in /usr/share/initramfs-tools/scripts/nfs to:

    mount.nfs ${NFSROOT} ${rootmnt} -o nolock ${roflag} ${NFSOPTS}
    
  3. Update the initramfs image with either mkinitramfs or update-initramfs.

This would enable the fsc option on the nfsroot for my Ubuntu 10.10 system. I have no idea why I'm not able to use mount.nfs from 10.10 though -- perhaps a regression?

Solution 2:

Recently I was building a new nfsroot based on 16.04 and decided to take another look at using cachefilesd for the nfsroot file system. Yet again I stumbled on this post. It helped to get me pointed in the right direction, and I ended up getting it to work but I believe I have a better answer than the one posted here.

While meanderix's steps could work I don't think its the best way. So here are my steps:

  1. In /usr/share/initramfs-tools/hooks create a new file. I called mine fsc for file system cache.
  2. Add the following content to your file:

    #!/bin/sh 
    set -e
    PREREQ=""
    prereqs () {
            echo "${PREREQ}"
    }  
    case "${1}" in
            prereqs)
                    prereqs
                    exit 0
                    ;;
    esac
    . /usr/share/initramfs-tools/hook-functions
    copy_exec /sbin/mount.nfs /sbin
    exit 0
    
  3. Make the fsc file executable:

    chmod 755 /usr/share/initramfs-tools/hooks/fsc
    
  4. Modify /usr/share/initramfs-tools/scripts/nfs as meanderix suggests.

  5. Generate your initramfs. eg:

    mkinitramfs -o /fscinitrd
    

The difference and the real magic here is the /usr/share/initramfs-tools/hooks/fsc file. Particularly the copy_exec line. When the initial RAM disk is created it will automatically add mount.nfs to the initramfs. But wait there's more! It will also determine the libraries needed and add them for you too. That's really cool since on Ubuntu 16.04 I needed libtirpc.so since mount.nfs was dependent on it and this added those dependencies for me.

After doing this and configuring cachefilesd I now have file system caching for my NFSROOT and that's just awesome.