I've been trying mount root (/) as overlayfs.
OS is booting over NFS to RAM. I've added a premount script in initrd, which creates the 'work', 'upper' and 'lower' directories.
During the boot process I'm copying the contents of NFS to the 'lower' dir. Overlayfs is being mounted into ${rootmnt} after that.
Finally, the init script chroots to ${rootmnt} (next, init from real root etc…) and the OS works fine.
Naturally I can't see the 'work' and 'upper' dirs. How can I do this? What must I change in initrd?
Best Answer
The challenge of mounting root as overlayfs has been solved.
Briefly, the 'lower', 'work' and 'upper' directories should be moved to the 'merge' dir. However, you should consider:
1) There is no need to do something if the 'lower' directory is present as a disk image. Just mounting it. If not, create tmpfs mount point on it and copy all needed files over NFS into it.
2) The 'upper' and 'lower' directories must be located in one filesystem. Creating another tmpfs mount point and thus placing 'upper' and 'lower' directories on it will be enough.
3) Ensure that your
initrd.img
has modules for NFS and Overlayfs. If they do not exist, then add them in /etc/initramfs-tools/modules.4) Ensure that your
initrd.img
has the full version of the 'mount' command. It it does not exist, then add it over hooks in/etc/initramfs-tools/hooks
.For example (some details have been omitted):
Finally, add the pre-mount script in
/etc/initramfs-tools/scripts/init-premount/
. For example: