mnt: add support for non-rootfs initramfs
Subsystems (2)
PATCH 1/1 mnt: add support for non-rootfs initramfs
From: Ignat Korchagin <[email protected]>
The main need for this is to support container runtimes on stateless Linux system (pivot_root system call from initramfs).
Normally, the task of initramfs is to mount and switch to a "real" root filesystem. However, on stateless systems (booting over the network) it is just convenient to have your "real" filesystem as initramfs from the start.
This, however, breaks different container runtimes, because they usually use pivot_root system call after creating their mount namespace. But pivot_root does not work from initramfs, because initramfs runs from rootfs, which is the root of the mount tree and can't be unmounted.
One workaround is to do:
mount --bind / /
However, that defeats one of the purposes of using pivot_root in the cloned containers: get rid of host root filesystem, should the code somehow escapes the chroot.
There is a way to solve this problem from userspace, but it is much more cumbersome:
* either have to create a multilayered archive for initramfs, where the outer layer creates a tmpfs filesystem and unpacks the inner layer, switches root and does not forget to properly cleanup the old rootfs
* or we need to use keepinitrd kernel cmdline option, unpack initramfs to rootfs, run a script to create our target tmpfs root, unpack the same initramfs there, switch root to it and again properly cleanup the old root, thus unpacking the same archive twice and also wasting memory, because the kernel stores compressed initramfs image indefinitely.
With this change we can ask the kernel (by specifying nonroot_initramfs kernel cmdline option) to create a "leaf" tmpfs mount for us and switch root to it before the initramfs handling code, so initramfs gets unpacked directly into the "leaf" tmpfs with rootfs being empty and no need to clean up anything.
This also bring the behaviour in line with the older style initrd, where the initrd is located on some leaf filesystem in the mount tree and rootfs remaining empty.
--- .../admin-guide/kernel-parameters.txt | 9 +++- fs/namespace.c | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +8 -1
@@ -3517,11 +3517,18 @@ nomfgpt [X86-32] Disable Multi-Function General Purpose Timer usage (for AMD Geode machines). + nomodule Disable module load + nonmi_ipi [X86] Disable using NMI IPIs during panic/reboot to shutdown the other cpus. Instead use the REBOOT_VECTOR irq. - nomodule Disable module load + nonroot_initramfs + [KNL] Create an additional tmpfs filesystem under rootfs + and unpack initramfs there instead of the rootfs itself. + This is useful for stateless systems, which run directly + from initramfs, create mount namespaces and use + "pivot_root" system call. nopat [X86] Disable PAT (page attribute table extension of pagetables) support.
fs/namespace.c +48 -0
66 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH 1/1 mnt: add support for non-rootfs initramfs
From: Ignat Korchagin <[email protected]>
The main need for this is to support container runtimes on stateless Linux system (pivot_root system call from initramfs).
Normally, the task of initramfs is to mount and switch to a "real" root filesystem. However, on stateless systems (booting over the network) it is just convenient to have your "real" filesystem as initramfs from the start.
This, however, breaks different container runtimes, because they usually use pivot_root system call after creating their mount namespace. But pivot_root does not work from initramfs, because initramfs runs from rootfs, which is the root of the mount tree and can't be unmounted.
One workaround is to do:
mount --bind / /
However, that defeats one of the purposes of using pivot_root in the cloned containers: get rid of host root filesystem, should the code somehow escapes the chroot.
There is a way to solve this problem from userspace, but it is much more cumbersome:
* either have to create a multilayered archive for initramfs, where the outer layer creates a tmpfs filesystem and unpacks the inner layer, switches root and does not forget to properly cleanup the old rootfs
* or we need to use keepinitrd kernel cmdline option, unpack initramfs to rootfs, run a script to create our target tmpfs root, unpack the same initramfs there, switch root to it and again properly cleanup the old root, thus unpacking the same archive twice and also wasting memory, because the kernel stores compressed initramfs image indefinitely.
With this change we can ask the kernel (by specifying nonroot_initramfs kernel cmdline option) to create a "leaf" tmpfs mount for us and switch root to it before the initramfs handling code, so initramfs gets unpacked directly into the "leaf" tmpfs with rootfs being empty and no need to clean up anything.
This also bring the behaviour in line with the older style initrd, where the initrd is located on some leaf filesystem in the mount tree and rootfs remaining empty.
--- .../admin-guide/kernel-parameters.txt | 9 +++- fs/namespace.c | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +8 -1
@@ -3517,11 +3517,18 @@ nomfgpt [X86-32] Disable Multi-Function General Purpose Timer usage (for AMD Geode machines). + nomodule Disable module load + nonmi_ipi [X86] Disable using NMI IPIs during panic/reboot to shutdown the other cpus. Instead use the REBOOT_VECTOR irq. - nomodule Disable module load + nonroot_initramfs + [KNL] Create an additional tmpfs filesystem under rootfs + and unpack initramfs there instead of the rootfs itself. + This is useful for stateless systems, which run directly + from initramfs, create mount namespaces and use + "pivot_root" system call. nopat [X86] Disable PAT (page attribute table extension of pagetables) support.
fs/namespace.c +48 -0
66 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH v3 1/1 mnt: add support for non-rootfs initramfs
In reply to [email protected]From: Ignat Korchagin <[email protected]>
The main need for this is to support container runtimes on stateless Linux system (pivot_root system call from initramfs).
Normally, the task of initramfs is to mount and switch to a "real" root filesystem. However, on stateless systems (booting over the network) it is just convenient to have your "real" filesystem as initramfs from the start.
This, however, breaks different container runtimes, because they usually use pivot_root system call after creating their mount namespace. But pivot_root does not work from initramfs, because initramfs runs from rootfs, which is the root of the mount tree and can't be unmounted.
One workaround is to do:
mount --bind / /
However, that defeats one of the purposes of using pivot_root in the cloned containers: get rid of host root filesystem, should the code somehow escapes the chroot.
There is a way to solve this problem from userspace, but it is much more cumbersome:
* either have to create a multilayered archive for initramfs, where the outer layer creates a tmpfs filesystem and unpacks the inner layer, switches root and does not forget to properly cleanup the old rootfs
* or we need to use keepinitrd kernel cmdline option, unpack initramfs to rootfs, run a script to create our target tmpfs root, unpack the same initramfs there, switch root to it and again properly cleanup the old root, thus unpacking the same archive twice and also wasting memory, because the kernel stores compressed initramfs image indefinitely.
With this change we can ask the kernel (by specifying nonroot_initramfs kernel cmdline option) to create a "leaf" tmpfs mount for us and switch root to it before the initramfs handling code, so initramfs gets unpacked directly into the "leaf" tmpfs with rootfs being empty and no need to clean up anything.
This also bring the behaviour in line with the older style initrd, where the initrd is located on some leaf filesystem in the mount tree and rootfs remaining empty.
--- .../admin-guide/kernel-parameters.txt | 9 +++- fs/namespace.c | 48 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +8 -1
@@ -3517,11 +3517,18 @@ nomfgpt [X86-32] Disable Multi-Function General Purpose Timer usage (for AMD Geode machines). + nomodule Disable module load + nonmi_ipi [X86] Disable using NMI IPIs during panic/reboot to shutdown the other cpus. Instead use the REBOOT_VECTOR irq. - nomodule Disable module load + nonroot_initramfs + [KNL] Create an additional tmpfs filesystem under rootfs + and unpack initramfs there instead of the rootfs itself. + This is useful for stateless systems, which run directly + from initramfs, create mount namespaces and use + "pivot_root" system call. nopat [X86] Disable PAT (page attribute table extension of pagetables) support.
fs/namespace.c +48 -0
66 lines not on this page · raw message
Signature · 1 line
2.32.0