4 ms·
There's one (not always but often enough) viable alternative to read-only root filesystems that is often overlooked. It's the possibility to copy the entire roo
by manuel_w 2y ago
There's one (not always but often enough) viable alternative to read-only root filesystems that is often overlooked. It's the possibility to copy the entire rootfs onto a ramdisk when booting. It increases the boot time and obviously disables persisting data (logs etc.), but often these are not needed anyway.
It's just a few lines of code in initramfs!
--- a/usr/share/initramfs-tools/scripts/local 2021-11-05 12:50:23.541088057 +0100
+++ b/usr/share/initramfs-tools/scripts/local 2021-11-05 13:02:14.483203576 +0100
@@ -180,9 +180,20 @@
# Mount root
# shellcheck disable=SC2086
- if ! mount ${roflag} ${FSTYPE:+-t "${FSTYPE}"} ${ROOTFLAGS} "${ROOT}" "${rootmnt?}"; then
- panic "Failed to mount ${ROOT} as root file system."
- fi
+ #if ! mount ${roflag} ${FSTYPE:+-t "${FSTYPE}"} ${ROOTFLAGS} "${ROOT}" "${rootmnt?}"; then
+ # panic "Failed to mount ${ROOT} as root file system."
+ #fi
+
+ mkdir --parents /tmp/diskroot
+ mount -t ${FSTYPE} ${roflag} ${ROOTFLAGS} ${ROOT} /tmp/diskroot
+
+ mount -t tmpfs -o size=6G none ${rootmnt?}
+ chmod 755 ${rootmnt}
+
+ cp --force --archive --verbose /tmp/diskroot/* ${rootmnt}
+
+ umount /tmp/diskroot
+ rm -r --force /tmp/diskroot
}
local_mount_fs()
and `update-initramfs -u`.
- gsliepen 2y agoEven better, you can just put the whole root fs into the initramfs image, and never pivot to another root filesystem during boot. This also allows you to netboot a whole OS.
- ylyn 2y agoOne pitfall of this is that the decompressed contents of your initramfs must fit within half of your physical RAM since Linux decompresses it into a tmpfs. Or if you set rootfstype=ramfs, then you can take up to all of physical RAM, but ramfs isn't swappable.
- ahepp 2y agoWait I'm not following, why must the decompressed contents of the initramfs fit within half of physical ram? Initramfs (and tmpfs) are swappable right? As you say, ramfs is the one that isn't swappable. So if your initramfs is "to big" can't it just be swapped out?
- manuel_w 2y ago> Wait I'm not following, why must the decompressed contents of the initramfs fit within half of physical ram? It makes sense if you replace "initramfs" with "initrd": > One pitfall of this is that the decompressed contents of your ~initramfs~ _initrd_ must fit within half of your physical RAM since Linux decompresses it into a tmpfs. > Or if you set rootfstype=ramfs, then you can take up to all of physical RAM
- seba_dos1 2y agoIf you go for an ephemeral rw fs anyway, you can just mount a rw overlayfs on top of a ro rootfs and skip the whole copying process.