fs: add immutable rootfs
Get series with b4
b4 am [email protected] change-id 20260102-work-immutable-rootfs-b5f23e0f5a27Versions newest first
- v2 Latest4 patches 12 repliesIn review
- v13 patches 12 repliesSuperseded
Changes in v2 from the cover letter
- Rename to "nullfs".
- Update documentation.
- Link to v1: https://patch.msgid.link/[email protected]
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | fs: ensure that internal tmpfs mount gets mount id zerofs/ | +1 | 1 reply | |
| 2/4 | fs: add init_pivot_root()fs/ fs/ fs/ +1 more | +73 | 0 replies | |
| 3/4 | fs: add immutable rootfsfs/ fs/ fs/ +4 more | +159 | 0 replies | |
| 4/4 | docs: mention nullfsDocumentation/ | +23 | 0 replies |
Reviews trailers per patch
1 of 4 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Jeff Layton |
|---|---|
| Series | R-b |
| 1/4 | R-b |
| 2/4 | |
| 3/4 | |
| 4/4 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 0/4] fs: add immutable rootfs
Currently pivot_root() doesn't work on the real rootfs because it cannot be unmounted. Userspace has to do a recursive removal of the initramfs contents manually before continuing the boot.
Really all we want from the real rootfs is to serve as the parent mount for anything that is actually useful such as the tmpfs or ramfs for initramfs unpacking or the rootfs itself. There's no need for the real rootfs to actually be anything meaningful or useful. Add a immutable rootfs called "nullfs" that can be selected via the "nullfs_rootfs" kernel command line option.
The kernel will mount a tmpfs/ramfs on top of it, unpack the initramfs and fire up userspace which mounts the rootfs and can then just do:
chdir(rootfs);
pivot_root(".", ".");
umount2(".", MNT_DETACH);and be done with it. (Ofc, userspace can also choose to retain the initramfs contents by using something like pivot_root(".", "/initramfs") without unmounting it.)
Technically this also means that the rootfs mount in unprivileged namespaces doesn't need to become MNT_LOCKED anymore as it's guaranteed that the immutable rootfs remains permanently empty so there cannot be anything revealed by unmounting the covering mount.
In the future this will also allow us to create completely empty mount namespaces without risking to leak anything.
systemd already handles this all correctly as it tries to pivot_root() first and falls back to MS_MOVE only when that fails.
This goes back to various discussion in previous years and a LPC 2024 presentation about this very topic.
Now in vfs-7.0.nullfs.
---
Changes in v2:
- Rename to "nullfs".
- Update documentation.
- Link to v1: https://patch.msgid.link/[email protected]
---
Christian Brauner (4):
fs: ensure that internal tmpfs mount gets mount id zero
fs: add init_pivot_root()
fs: add immutable rootfs
docs: mention nullfs
.../filesystems/ramfs-rootfs-initramfs.rst | 32 +++- fs/Makefile | 2 +- fs/init.c | 17 ++ fs/internal.h | 1 + fs/mount.h | 1 + fs/namespace.c | 181 ++++++++++++++------- fs/nullfs.c | 70 ++++++++ include/linux/init_syscalls.h | 1 + include/uapi/linux/magic.h | 1 + init/do_mounts.c | 14 ++ init/do_mounts.h | 1 + 11 files changed, 254 insertions(+), 67 deletions(-)
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20260102-work-immutable-rootfs-b5f23e0f5a27