5

Looking for example/howto/etc of howto create an overlayfs for my diskless computers.

I have multiple diskless computers that have root on nfs configured. I would like to use an overlay for files that need to be changed for the computes. Like /etc/hostname and /etc/fstab, etc...

Anyone have this working that can give me a reference url?

Jorge Castro
  • 71,754
Mike
  • 51
  • I'm trying to accomplish the same thing. I want to export the rootfs read-only, and then use overlayfs to get read-write file system on the client with non-persistent writes. Although I don't have all the details figured out yet, I looking at how the live CD does this is probably the best example. – jderose Mar 15 '13 at 19:54
  • So I haven't quite got it working with NFS yet, but in Quantal and newer, there is this intriguing overlayroot package: http://packages.ubuntu.com/search?keywords=overlayroot – jderose Mar 16 '13 at 01:44
  • Maybe this question helps you finding more information:

    http://askubuntu.com/questions/109413/how-do-i-use-overlayfs

    – D-E-N Mar 19 '13 at 21:50

2 Answers2

2

I can almost get this working by installing overlayroot, then adding an /etc/overlayroot.local.conf file like this:

overlayroot_cfgdisk="disabled"
overlayroot=tmpfs

However, this bug in overlayfs is blocking my progress. That bug means NFSv3 and overlayfs currently can't play nice together for the copy-on-write functionality you're looking for. Although once that's fixed, I do think using overlayroot is probably the best way to add the needed initramfs magic.

With the above bug, you can create files in the upperdir that don't exists in the lowerdir, but the copy-up from the lowerdir to the upperdir is what's broken. So as a workaround, I recursively delete all files found in these directories when I install my rootfs on the server:

/etc/apparmor.d/cache/
/var/log/
/var/lib/ubuntu-release-upgrader/
/var/lib/update-notifier/

This gives me a more-or-less properly functioning system, enough to run the client stuff I need.

For more info, check out Dustin Kirkland's blog post on overlayroot.

jderose
  • 659
  • That overlayroot package is refined indeed. It does a lot more than just the overlayfs on top of some read-only mount point... For my simple purposes, I have rolled my own script to stack overlayfs on top of NFS. I have "documented" my approach here: http://support.fccps.cz/download/adv/frr/nfs-root/nfs-root.htm – frr Sep 20 '20 at 07:40
1

You could try adding to your startup scripts (e.g. paste into /etc/rc.local - before the exit 0 line - if you don't want to get into the nitty gritty of bootscript programming) the following sequence which uses a temporary memory filesystem for the overlay (you'll want to replace that line with one that points to your preferred location!):

mkdir /mnt/root /mnt/overlay
mount -o bind / /mnt/root
mount -t tmpfs tmpfs /mnt/overlay
mount -o lowerdir=/mnt/root,upperdir=/mnt/overlay -t overlayfs /

Beware, that I've NOT tested whether this works!

  • Although I haven't tried this in /etc/rc.local, when I've tried booting into a system with a read-only root partition, the boot hung pretty early on. So I don't think you'd make it to /etc/rc.local. I think you have to do this in an initramfs script. – jderose Mar 24 '13 at 17:04