Skip to contentSkip to conversation

init: Introduce rootdir bootparm to select which dir to sys_chroot

PATCH In review Al Boldi 3 participants 7 messages Nov 6, 2007 – Nov 9, 2007 VFS

lore
Share & tools
lore

Al Boldi

author
#0 lore raw

PATCH 1/1 init: Introduce rootdir bootparm to select which dir to sys_chroot

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

This is useful for systems that have more than one distribution installed on the same fs/partition.

Cc H. Peter Anvin <[email protected]>
Cc Andrew Morton <[email protected]>

---

init/do_mounts.c +13 -0
@@ -252,6 +252,15 @@ __setup("rootflags=", root_data_setup);
 __setup("rootfstype=", fs_names_setup);
 __setup("rootdelay=", root_delay_setup);
 
+static char * __initdata root_dir;
+static int __init root_dir_setup(char *str)
+{
+	root_dir = strcat("./",str);
+	return 1;
+}
+
+__setup("rootdir=", root_dir_setup);
+
 static void __init get_fs_names(char *page)
 {
 	char *s = page;
@@ -469,6 +478,10 @@ void __init prepare_namespace(void)
 	mount_root();
 out:
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+
+	if(root_dir)
+		sys_chdir(root_dir);
+
 	sys_chroot(".");
 	security_sb_post_mountroot();
 }
author
#1 lore raw
Quoted 16 lines · Al Boldi

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

This is useful for systems that have more than one distribution installed on the same fs/partition.

Cc H. Peter Anvin <[email protected]>
Cc Andrew Morton <[email protected]>

---

init/do_mounts.c __setup("rootflags=", root_data_setup); · line 258

Quoted 7 lines
init/do_mounts.c +4 -0
@@ -252,6 +252,15 @@ __setup("rootflags=", root_data_setup);
 __setup("rootfstype=", fs_names_setup);
 __setup("rootdelay=", root_delay_setup);
 
+static char * __initdata root_dir;
+static int __init root_dir_setup(char *str)
+{
+	root_dir = strcat("./",str);

This line is probably using an overloaded function that does not exist. Use this instead:

static char __initdata root_dir[128];
static int __init root_dir_setup(char *str)

{
	strcpy(root_dir, "./");
	strlcat(root_dir, str, sizeof(root_dir) - strlen(root_dir) - 1);
	return 1;
}
Quoted 6 lines
init/do_mounts.c +2 -0
+__setup("rootdir=", root_dir_setup);
+
 static void __init get_fs_names(char *page)
 {
 	char *s = page;

init/do_mounts.c void __init prepare_namespace(void) · line 487

Quoted 10 lines
init/do_mounts.c +4 -0
@@ -469,6 +478,10 @@ void __init prepare_namespace(void)
 	mount_root();
 out:
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+
+	if(root_dir)
+		sys_chdir(root_dir);
+
 	sys_chroot(".");
 	security_sb_post_mountroot();
 }

Thanks!

--
Al

#2 lore raw
Quoted 6 lines · Al Boldi
Quoted 5 lines · Al Boldi

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

This is useful for systems that have more than one distribution installed on the same fs/partition.

This seems like something that should be done via an initramfs.

-hpa

author
#3 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Al Boldi
Quoted 5 lines · Al Boldi

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

This is useful for systems that have more than one distribution installed on the same fs/partition.

This seems like something that should be done via an initramfs.

Agreed. But, not everybody boots their systems via initramfs, and even if they did, they also have to know how to reconfigure it.

In contrast, this patch offers the rootdir functionality as a simple bootparm and without any extra initramfs dependency.

Thanks!

--
Al

#4 lore raw
Quoted 6 lines · Al Boldi
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Al Boldi
Quoted 3 lines · Al Boldi

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

This is useful for systems that have more than one distribution installed on the same fs/partition.

This seems like something that should be done via an initramfs.

Agreed. But, not everybody boots their systems via initramfs, and even if they did, they also have to know how to reconfigure it.

In contrast, this patch offers the rootdir functionality as a simple bootparm and without any extra initramfs dependency.

And yet another hack in the kernel!

Instead of heaping hack du jour into the kernel, write a small initramfs that provides the appropriate functionality, please.

-hpa

#5 lore raw
In reply to Al Boldi
Quoted 19 lines · On Tue, 6 Nov 2007 13:40:26 +0300 Al Boldi <[email protected]> wrote:

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

This is useful for systems that have more than one distribution installed on the same fs/partition.

Cc H. Peter Anvin <[email protected]>
Cc Andrew Morton <[email protected]>

---

init/do_mounts.c +0 -0
@@ -252,6 +252,15 @@ __setup("rootflags=", root_data_setup);
 __setup("rootfstype=", fs_names_setup);

init/do_mounts.c __setup("rootflags=", root_data_setup); · line 262

Quoted 10 lines
init/do_mounts.c +8 -0
 __setup("rootdelay=", root_delay_setup);
 
+static char * __initdata root_dir;
+static int __init root_dir_setup(char *str)
+{
+	root_dir = strcat("./",str);
+	return 1;
+}
+
+__setup("rootdir=", root_dir_setup);

Please update Documentation/kernel-parameters.txt when adding __setup options.

init/do_mounts.c void __init prepare_namespace(void) · line 484

Quoted 11 lines
init/do_mounts.c +4 -0
 static void __init get_fs_names(char *page)
 {
 	char *s = page;
@@ -469,6 +478,10 @@ void __init prepare_namespace(void)
 	mount_root();
 out:
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+
+	if(root_dir)
+		sys_chdir(root_dir);
+

Please run scripts/checkpatch.pl across all patches before sending them to anyone.

author
#6 lore raw
Quoted 21 lines · Andrew Morton
Quoted 21 lines · On Tue, 6 Nov 2007 13:40:26 +0300 Al Boldi <[email protected]> wrote:

This patch introduces a rootdir kernel boot parameter, which specifies the path to the kernel sys_chroot boot dir.

This is useful for systems that have more than one distribution installed on the same fs/partition.

Cc H. Peter Anvin <[email protected]>
Cc Andrew Morton <[email protected]>

---

init/do_mounts.c +0 -0
@@ -252,6 +252,15 @@ __setup("rootflags=", root_data_setup);
 __setup("rootfstype=", fs_names_setup);
 __setup("rootdelay=", root_delay_setup);
 
Quoted 11 lines

init/do_mounts.c __setup("rootflags=", root_data_setup); · line 262

Quoted 8 lines
init/do_mounts.c +8 -0
+static char * __initdata root_dir;
+static int __init root_dir_setup(char *str)
+{
+	root_dir = strcat("./",str);
+	return 1;
+}
+
+__setup("rootdir=", root_dir_setup);

Please update Documentation/kernel-parameters.txt when adding __setup options.

Sure.

If you think this feature is useful, which I think it is, then I probably need to resend with a doc update. But bare in mind, this patch needs something like small hack to allow remounting root, which currently isn't possible. I'm sure hpa is probably the genius to help out here.

Quoted 15 lines

init/do_mounts.c void __init prepare_namespace(void) · line 484

Quoted 12 lines
init/do_mounts.c +4 -0
 static void __init get_fs_names(char *page)
 {
 	char *s = page;
@@ -469,6 +478,10 @@ void __init prepare_namespace(void)
 	mount_root();
 out:
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+
+	if(root_dir)
+		sys_chdir(root_dir);
+

Please run scripts/checkpatch.pl across all patches before sending them to anyone.

Ok.

Thanks!

--
Al