From: Menglong Dong <[email protected]>
As Luis Chamberlain suggested, I split the patch:
[init/initramfs.c: make initramfs support pivot_root]
(https://lore.kernel.org/linux-fsdevel/[email protected]/)
into three.
The goal of the series patches is to make pivot_root() support initramfs.
In the first patch, I introduce the function ramdisk_exec_exist(), which
is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN
lookup mode.
In the second patch, I create a second mount, which is called
'user root', and make it become the root. Therefore, the root has a
parent mount, and it can be umounted or pivot_root.
In the third patch, I fix rootfs_fs_type with ramfs, as it is not used
directly any more, and it make no sense to switch it between ramfs and
tmpfs, just fix it with ramfs to simplify the code.
Changes since V1:
In the first patch, I add the flag LOOKUP_DOWN to init_eaccess(), to make
it support the check of filesystem mounted on '/'.
In the second patch, I control 'user root' with kconfig option
'CONFIG_INITRAMFS_USER_ROOT', and add some comments, as Luis Chamberlain
suggested.
In the third patch, I make 'rootfs_fs_type' in control of
'CONFIG_INITRAMFS_USER_ROOT'.
Menglong Dong (3):
init/main.c: introduce function ramdisk_exec_exist()
init/do_cmounts.c: introduce 'user_root' for initramfs
init/do_mounts.c: fix rootfs_fs_type with ramfs
fs/init.c | 2 +-
include/linux/init.h | 5 ++
init/do_mounts.c | 109 +++++++++++++++++++++++++++++++++++++++++++
init/do_mounts.h | 18 ++++++-
init/initramfs.c | 10 ++++
init/main.c | 7 ++-
usr/Kconfig | 10 ++++
7 files changed, 158 insertions(+), 3 deletions(-)
--
2.32.0.rc0
From: Menglong Dong <[email protected]>
As for the existence of 'user root' which is introduced in previous
patch, 'rootfs_fs_type', which is used as the root of mount tree,
is not used directly any more. So it make no sense to make it tmpfs
while 'INITRAMFS_USER_ROOT' is enabled.
Make 'rootfs_fs_type' ramfs when 'INITRAMFS_USER_ROOT' enabled.
Signed-off-by: Menglong Dong <[email protected]>
---
include/linux/init.h | 5 +++++
init/do_mounts.c | 10 +++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/include/linux/init.h b/include/linux/init.h
index 045ad1650ed1..d65b12fe438c 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -148,7 +148,12 @@ extern unsigned int reset_devices;
/* used by init/main.c */
void setup_arch(char **);
void prepare_namespace(void);
+#ifndef CONFIG_INITRAMFS_USER_ROOT
void __init init_rootfs(void);
+#else
+static inline void __init init_rootfs(void) { }
+#endif
+
extern struct file_system_type rootfs_fs_type;
#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 2fd168cca480..74f5b0fc8bdf 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -716,7 +716,14 @@ void __init init_user_rootfs(void)
}
}
}
-#endif
+
+struct file_system_type rootfs_fs_type = {
+ .name = "rootfs",
+ .init_fs_context = ramfs_init_fs_context,
+ .kill_sb = kill_litter_super,
+};
+
+#else
static bool is_tmpfs;
static int rootfs_init_fs_context(struct fs_context *fc)
@@ -739,3 +746,4 @@ void __init init_rootfs(void)
(!root_fs_names || strstr(root_fs_names, "tmpfs")))
is_tmpfs = true;
}
+#endif
--
2.32.0.rc0
On Tue, May 25, 2021 at 10:15:21PM +0800, [email protected] wrote:
> From: Menglong Dong <[email protected]>
>
> As Luis Chamberlain suggested, I split the patch:
> [init/initramfs.c: make initramfs support pivot_root]
> (https://lore.kernel.org/linux-fsdevel/[email protected]/)
> into three.
>
> The goal of the series patches is to make pivot_root() support initramfs.
>
> In the first patch, I introduce the function ramdisk_exec_exist(), which
> is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN
> lookup mode.
>
> In the second patch, I create a second mount, which is called
> 'user root', and make it become the root. Therefore, the root has a
> parent mount, and it can be umounted or pivot_root.
>
> In the third patch, I fix rootfs_fs_type with ramfs, as it is not used
> directly any more, and it make no sense to switch it between ramfs and
> tmpfs, just fix it with ramfs to simplify the code.
>
> Changes since V1:
>
> In the first patch, I add the flag LOOKUP_DOWN to init_eaccess(), to make
> it support the check of filesystem mounted on '/'.
>
> In the second patch, I control 'user root' with kconfig option
> 'CONFIG_INITRAMFS_USER_ROOT', and add some comments, as Luis Chamberlain
> suggested.
>
> In the third patch, I make 'rootfs_fs_type' in control of
> 'CONFIG_INITRAMFS_USER_ROOT'.
This looks much better, thank you; this addresses all my concerns with
v1. I appreciate having the config option to control this as well.
Hello!
On Fri, May 28, 2021 at 3:10 PM Masami Hiramatsu <[email protected]> wrote:
>
> Hi,
[...]
>
>
> This idea sounds good to me. I have tested it with MINCS container shell
> script (https://github.com/mhiramat/mincs).
>
> However, I found different issue on init_eaccess() (or symlink lookup)
> with this series.
>
> I'm using a busybox initramfs, and it makes /init as a symlink of "/sbin/init"
> (absolute path)
>
> When CONFIG_INITRAMFS_USER_ROOT=n, it booted. But CONFIG_INITRAMFS_USER_ROOT=y,
> it failed to boot because it failed to find /init. If I made the /init as
> a symlink of "sbin/init" (relative path), it works.
>
> Would you have any idea?
>
Thanks for your report!
I think it's because of the path lookup on '/'. With LOOKUP_DOWN
set, the lookup for '/' of '/init' will follow the mount. However,
during the follow link of '/sbin/init', the '/' of it will not be followed,
because LOOKUP_DOWN only works one time. I'm not sure if this is an
imperfection of 'path_lookupat()'.
I'll fix it in the next series.
Thanks!
Menglong Dong
Hi,
On Tue, 25 May 2021 22:15:21 +0800
[email protected] wrote:
> From: Menglong Dong <[email protected]>
>
> As Luis Chamberlain suggested, I split the patch:
> [init/initramfs.c: make initramfs support pivot_root]
> (https://lore.kernel.org/linux-fsdevel/[email protected]/)
> into three.
>
> The goal of the series patches is to make pivot_root() support initramfs.
>
> In the first patch, I introduce the function ramdisk_exec_exist(), which
> is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN
> lookup mode.
>
> In the second patch, I create a second mount, which is called
> 'user root', and make it become the root. Therefore, the root has a
> parent mount, and it can be umounted or pivot_root.
>
> In the third patch, I fix rootfs_fs_type with ramfs, as it is not used
> directly any more, and it make no sense to switch it between ramfs and
> tmpfs, just fix it with ramfs to simplify the code.
This idea sounds good to me. I have tested it with MINCS container shell
script (https://github.com/mhiramat/mincs).
However, I found different issue on init_eaccess() (or symlink lookup)
with this series.
I'm using a busybox initramfs, and it makes /init as a symlink of "/sbin/init"
(absolute path)
When CONFIG_INITRAMFS_USER_ROOT=n, it booted. But CONFIG_INITRAMFS_USER_ROOT=y,
it failed to boot because it failed to find /init. If I made the /init as
a symlink of "sbin/init" (relative path), it works.
Would you have any idea?
Thank you,
--
Masami Hiramatsu <[email protected]>