I'm trying to create a small rescue partition (~800MB spare space after all other system and storage partitions) for a laptop with specialized hardware that requires special kernel and kernel modules such that stock rescue tools such as Clonezilla Live and GParted Live don't work very well. The partition is too small to include the modules and software needed for what I'd like to build, so the bulk of the system needs to be compressed and loaded into RAM at runtime. Additionally, I prefer to have the system fully extracted instead of relying on squashfs, and I would like the ability to save changes made to the system as much as the partition allows. Using Ubuntu 20.04 as the base system, I devised the following scheme for this purpose:
- After building the initial system in
chroot, create and empty folder/ramas the mount point for thetmpfsto house decompressed system and user files at runtime, move all system and user file folders (home,usr,var,opt,etc, etc.) into/ramand replace each with a symbolic link to/ram/$dir. Compress/ramas/ram.tar.gzand leave the special mount points (dev,sys,run,tmp, andproc) as well asbootalone onrootfs. Delete/ram/*and write therootfsonto the partition. - At boot, after kernel and
initrdare loaded, premountrootfs, mounttmpfson/ram, then extract the content of/ram.tar.gzinto/ram. This has to happen beforerootfsreplacesinitramfsas root since otherwiserootfscan't access the utilities needed to mount/ramand extract from the compressed archive. - Mount
rootfsand proceed with boot. - At shutdown, back up
/ram.tar.gzas/ram.tar.gz.bakthen compress the modified/raminto/ram.tar.gz. This can be achieved usingsystemd.
Obviously things can go wrong in step 4 and therefore step 2 needs to include the integrity of /ram.tar.gz and load the backup if that fails, but this should be just a few additional commands to include in the initramfs-tools script and beyond the scope of my question, which is:
Without altering /usr/share/initramfs-tools/init, how do I create a script in /etc/initramfs-tools/scripts to accomplish step 2? The commands should be easy enough as
mount -t tmpfs -o $OPTIONS none /ram
tar xvzf ram.tar.gz
But I'm a bit at loss as to which folder to include the script (init? local? top? bottom? premount?) and how to work with the PREREQ header in the script itself.