Skip to contentSkip to conversation

init: Introduce rootdir bootparm to select which dir to sys_chroot

PATCH In review Al Boldi 2 participants 3 messages Nov 18, 2007 – Nov 19, 2007

Subsystems (2)
lore
Share & tools
lore

Al Boldi

author
#0 lore raw

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

Second try; this time with a doc-update, and the ability to remount normally.

Tested against 2.6.23.

---

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]>

---

Documentation/kernel-parameters.txt +4 -0
@@ -1506,6 +1506,10 @@ and is between 256 and 4096 characters. 
 			Useful for devices that are detected asynchronously
 			(e.g. USB and MMC devices).
 
+	rootdir=	[KNL] Set root dir to chroot to on bootup.
+			Useful for systems that have more than one distribution
+			installed on the same filesystem.
+
 	rw		[KNL] Mount root device read-write on boot
 
 	S		[KNL] Run init in single mode
init/do_mounts.c +16 -0
@@ -252,6 +252,16 @@ __setup("rootflags=", root_data_setup);
 __setup("rootfstype=", fs_names_setup);
 __setup("rootdelay=", root_delay_setup);
 
+static char __initdata root_dir[128];
+static int __init root_dir_setup(char *str)
+{
+	strcpy(root_dir, "./");
+	strlcat(root_dir, str, sizeof(root_dir));
+	return 1;
+}
+
+__setup("rootdir=", root_dir_setup);
+
 static void __init get_fs_names(char *page)
 {
 	char *s = page;
@@ -469,6 +479,12 @@ void __init prepare_namespace(void)
 	mount_root();
 out:
 	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+
+	if (root_dir) {
+		sys_mount(root_dir, root_dir, NULL, MS_BIND, NULL);
+		sys_chdir(root_dir);
+	}
+
 	sys_chroot(".");
 	security_sb_post_mountroot();
 }
#1 lore raw
Quoted 3 lines · On Sun, 18 Nov 2007 20:09:19 +0300 Al Boldi <[email protected]> wrote:

Second try; this time with a doc-update, and the ability to remount normally.

Hi,

to be honest, this is something that really should be done in the initramfs image; we should strive to keep the more complex bootup scenarios there and not inside the kernel bootup code...

Greetings,
Arjan van de Ven

Signature · 3 lines
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
author
#2 lore raw
Quoted 3 lines · Arjan van de Ven

to be honest, this is something that really should be done in the initramfs image; we should strive to keep the more complex bootup scenarios there and not inside the kernel bootup code...

Agreed, but this is neither complex nor is it a scenario.

This is a shortcut. And, IMHO, a clean one.

Thanks!

--
Al