Skip to contentSkip to conversation

rootfs boot param. support

patch-2.4.0-test13-pre3 [email protected] 5 participants 8 messages Dec 18, 2000 – Dec 19, 2000

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Tigran Aivazian <[email protected]>

+ rootfs= [KNL] Use filesystem type specified (e.g. rootfs=ext2) for root.

(i) I prefer "rootfstype". Indeed, "rootfs" is ambiguous. It gives some property of the root filesystem, but which?

    +static char rootfs[128] __initdata = "ext2";

(ii) It is a bad idea to arbitrarily select "ext2". Moreover, we want to recognize the case where a boot option was given, see below.

+ fs_type = get_fs_type(rootfs);
+ if (fs_type) {
+ sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
+ if (sb)
+ goto mount_it;
+ }

(iii) I probably give the rootfstype explicitly because bad things (like disk corruption) happen when the kernel misrecognizes some filesystem, and perhaps starts updating access times or so. Thus, if the boot option rootfstype is given, I prefer a boot failure over a kernel attempt to try all filesystems it knows about, just like mount(8) only will start guessing when no explicit type was given.

Andries
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw

[Andries Brouwer]

Quoted 7 lines

(i) I prefer "rootfstype". Indeed, "rootfs" is ambiguous. It gives some property of the root filesystem, but which?

(ii) It is a bad idea to arbitrarily select "ext2".

(iii) [...] Thus, if the boot option rootfstype is given, I prefer a boot failure over a kernel attempt to try all filesystems it knows

Agreed on all counts.

Peter

fs/super.c renamed from fs/super.c~ +16 -11
@@ -18,7 +18,7 @@
  *    Torbjörn Lindh ([email protected]), April 14, 1996.
  *  Added devfs support: Richard Gooch <[email protected]>, 13-JAN-1998
  *  Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
- *  Added rootfs boot param. used by mount_root(): Tigran Aivazian. Dec 2000.
+ *  Added rootfstype boot param. used by mount_root(): Tigran Aivazian. Dec 2000.
  */
 
 #include <linux/config.h>
@@ -59,11 +59,11 @@
 /* this is initialized in init/main.c */
 kdev_t ROOT_DEV;
 
-/* this can be set at boot time, e.g. rootfs=ext2 
+/* this can be set at boot time, e.g. rootfstype=ext2 
  * if set to invalid value or if read_super() fails on the specified
  * filesystem type then mount_root() will go through all registered filesystems.
  */
-static char rootfs[128] __initdata = "ext2";
+static char rootfstype[32] __initdata = "";
 
 int nr_super_blocks;
 int max_super_blocks = NR_SUPER;
@@ -90,11 +90,11 @@
 	int n = strlen(line) + 1;
 
 	if (n > 1 && n < 128)
-		strncpy(rootfs, line, n);
+		strncpy(rootfstype, line, n);
 	return 1;
 }
 
-__setup("rootfs=", rootfs_setup);
+__setup("rootfstype=", rootfs_setup);
 
 /* WARNING: This can be used only if we _already_ own a reference */
 static void get_filesystem(struct file_system_type *fs)
@@ -1479,7 +1479,7 @@
 
 void __init mount_root(void)
 {
-	struct file_system_type * fs_type;
+	struct file_system_type * fs_type = NULL;
 	struct super_block * sb;
 	struct vfsmount *vfsmnt;
 	struct block_device *bdev = NULL;
@@ -1597,11 +1597,15 @@
 		goto mount_it;
 	}
 
-	fs_type = get_fs_type(rootfs);
-	if (fs_type) {
-  		sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
-		if (sb)
-			goto mount_it;
+	if (*rootfstype) {
+		fs_type = get_fs_type(rootfstype);
+		if (fs_type) {
+  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
+			if (sb)
+				goto mount_it;
+		}
+		/* do NOT try all filesystems - user explicitly wanted this one */
+		goto fail;
 	}
 	read_lock(&file_systems_lock);
 	for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) {
@@ -1617,6 +1621,7 @@
 		put_filesystem(fs_type);
 	}
 	read_unlock(&file_systems_lock);
+fail:
 	panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
 
 mount_it:

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw

Ok, the version below doesn't look too bad, except a couple things, see below:

fs/super.c line 97

Quoted 2 lines · Peter Samuelson
fs/super.c renamed from fs/super.c~ +1 -1
-__setup("rootfs=", rootfs_setup);
+__setup("rootfstype=", rootfs_setup);

this is wrong. If the parameter is "rootfstype" then the function is rootfstype_setup(). Too long. No, "rootfs" was a good idea to beging with (ask any kernel hacker who wrote UW7 BCP support -- they knew what they were calling their variables :)

fs/super.c line 1482

Quoted 3 lines

{

fs/super.c renamed from fs/super.c~ +1 -1
-	struct file_system_type * fs_type;
+	struct file_system_type * fs_type = NULL;

this is not needed. Why did you put it there?

fs/super.c

Quoted 12 lines
fs/super.c renamed from fs/super.c~ +10 -0
+	if (*rootfstype) {
+		fs_type = get_fs_type(rootfstype);
+		if (fs_type) {
+  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
+			if (sb)
+				goto mount_it;
+		}
+		/* do NOT try all filesystems - user explicitly wanted this one */
+		goto fail;
...
+fail:
 	panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));

we should also print out the filesystem type, so instead of having a fail label I would put the panic() inside the code above.

I will redo the patch with your and Andries' comments in place and re-send to Linus. Namely, the useful things, imho, from your suggestions are:

a) the space allocated for it should be 32 bytes and not 128

b) we should check if user passed any value and only then activate the code

c) default value "" is ok (ok, fine, the extra line of code to check for it is not too bad).

d) but the variable should still be called "rootfs" and not "rootfstype". rootfstype is too long, too confusing and not obvious. Whilst "rootfs" immediately tells you "it's the name of the filesystem in the namespace defined by file_system_type->name"

Oh, btw you changed one place from 128 to 32 but forgot another -- never mind :)

Regards,
Tigran

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw

[patch-2.4.0-test13-pre3] rootfs (2nd attempt)

In reply to Peter Samuelson

Hi Linus,

Thanks to suggestions from Andries and Peter I enhanced the rootfs patch to do the same it did before + panic when rootfs= is given but failed to match the userspace mount(8) behaviour. Also other cleanups mentioned in the thread are all incorporated (well, at least the sensible ones). Now, everyone is (hopefully) happy.

Tested under 2.4.0-test13-pre3.

Regards,
Tigran

Documentation/kernel-parameters.txt +4 -1
diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
@@ -473,7 +473,10 @@
 
 	ro		[KNL] Mount root device read-only on boot.
 
-	root=		[KNL] root filesystem.
+	root=		[KNL] Mount root filesystem on specified (as hex or "/dev/XXX") device.
+
+	rootfs=		[KNL] Use filesystem type specified (e.g. rootfs=ext2) for root.
+ 
 
 	rw		[KNL] Mount root device read-write on boot.
 
fs/super.c +29 -0
diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
@@ -18,6 +18,7 @@
  *    Torbjörn Lindh ([email protected]), April 14, 1996.
  *  Added devfs support: Richard Gooch <[email protected]>, 13-JAN-1998
  *  Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
+ *  Added rootfs boot param. used by mount_root(): Tigran Aivazian. Dec 2000.
  */
 
 #include <linux/config.h>
@@ -58,6 +59,12 @@
 /* this is initialized in init/main.c */
 kdev_t ROOT_DEV;
 
+/* this can be set at boot time, e.g. rootfs=ext2 
+ * if set to invalid value or if read_super() fails on the specified
+ * filesystem type then mount_root() will go through all registered filesystems.
+ */
+static char rootfs[32] __initdata = "";
+
 int nr_super_blocks;
 int max_super_blocks = NR_SUPER;
 LIST_HEAD(super_blocks);
@@ -78,6 +85,17 @@
 static struct file_system_type *file_systems;
 static rwlock_t file_systems_lock = RW_LOCK_UNLOCKED;
 
+static int __init rootfs_setup(char *line)
+{
+	int n = strlen(line) + 1;
+
+	if (n > 1 && n < 32)
+		strncpy(rootfs, line, n);
+	return 1;
+}
+
+__setup("rootfs=", rootfs_setup);
+
 /* WARNING: This can be used only if we _already_ own a reference */
 static void get_filesystem(struct file_system_type *fs)
 {
@@ -1579,6 +1597,16 @@
 		goto mount_it;
 	}
 
+	if (*rootfs) {
+		fs_type = get_fs_type(rootfs);
+		if (fs_type) {
+  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
+			if (sb)
+				goto mount_it;
+		} 
+		/* don't try others if type given explicitly, same behaviour as mount(8) */
+		goto fail;
+	}
 	read_lock(&file_systems_lock);
 	for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) {
   		if (!(fs_type->fs_flags & FS_REQUIRES_DEV))
@@ -1593,6 +1621,7 @@
 		put_filesystem(fs_type);
 	}
 	read_unlock(&file_systems_lock);
+fail:
 	panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
 
 mount_it:

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw

Oops Re: [patch-2.4.0-test13-pre3] rootfs (2nd attempt)

just a typo in the comment, sorry. Corrected version below.

Documentation/kernel-parameters.txt +4 -1
diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
@@ -473,7 +473,10 @@
 
 	ro		[KNL] Mount root device read-only on boot.
 
-	root=		[KNL] root filesystem.
+	root=		[KNL] Mount root filesystem on specified (as hex or "/dev/XXX") device.
+
+	rootfs=		[KNL] Use filesystem type specified (e.g. rootfs=ext2) for root.
+ 
 
 	rw		[KNL] Mount root device read-write on boot.
 
fs/super.c +29 -0
diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
@@ -18,6 +18,7 @@
  *    Torbjörn Lindh ([email protected]), April 14, 1996.
  *  Added devfs support: Richard Gooch <[email protected]>, 13-JAN-1998
  *  Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
+ *  Added rootfs boot param. used by mount_root(): Tigran Aivazian. Dec 2000.
  */
 
 #include <linux/config.h>
@@ -58,6 +59,12 @@
 /* this is initialized in init/main.c */
 kdev_t ROOT_DEV;
 
+/* this can be set at boot time, e.g. rootfs=ext2 
+ * if set to invalid value or if read_super() fails on the specified
+ * filesystem type then mount_root() will panic
+ */
+static char rootfs[32] __initdata = "";
+
 int nr_super_blocks;
 int max_super_blocks = NR_SUPER;
 LIST_HEAD(super_blocks);
@@ -78,6 +85,17 @@
 static struct file_system_type *file_systems;
 static rwlock_t file_systems_lock = RW_LOCK_UNLOCKED;
 
+static int __init rootfs_setup(char *line)
+{
+	int n = strlen(line) + 1;
+
+	if (n > 1 && n < 32)
+		strncpy(rootfs, line, n);
+	return 1;
+}
+
+__setup("rootfs=", rootfs_setup);
+
 /* WARNING: This can be used only if we _already_ own a reference */
 static void get_filesystem(struct file_system_type *fs)
 {
@@ -1579,6 +1597,16 @@
 		goto mount_it;
 	}
 
+	if (*rootfs) {
+		fs_type = get_fs_type(rootfs);
+		if (fs_type) {
+  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
+			if (sb)
+				goto mount_it;
+		} 
+		/* don't try others if type given explicitly, same behaviour as mount(8) */
+		goto fail;
+	}
 	read_lock(&file_systems_lock);
 	for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) {
   		if (!(fs_type->fs_flags & FS_REQUIRES_DEV))
@@ -1593,6 +1621,7 @@
 		put_filesystem(fs_type);
 	}
 	read_unlock(&file_systems_lock);
+fail:
 	panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
 
 mount_it:

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw

Re: [patch-2.4.0-test13-pre3] rootfs (2nd attempt)

In reply to Tigran Aivazian

Tigran, you write:

Quoted 2 lines

Thanks to suggestions from Andries and Peter I enhanced the rootfs patch to do the same it did before + panic when rootfs= is given but failed to

If I could add one thing here (we have had a 2.2 patch like this for testing with ext3) - if you specify the rootfstype parameter don't use the "quiet" option to read_super, so you know why it couldn't mount a specific filesystem as root, and/or print rootfs type in the panic message.

This is especially useful if you have something in LILO that you forgot about...

Cheers, Andreas
=============================================================================

fs/super.c +3 -2
diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
@@ -1600,7 +1600,7 @@
 	if (*rootfs) {
 		fs_type = get_fs_type(rootfs);
 		if (fs_type) {
-  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,1);
+  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,0);
 			if (sb)
 				goto mount_it;
 		} 
@@ -1622,7 +1622,8 @@
 	}
 	read_unlock(&file_systems_lock);
 fail:
-	panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
+	panic("VFS: Unable to mount root %s on %s", *rootfs ? rootfs : "fs",
+	      kdevname(ROOT_DEV));
 
 mount_it:
 	printk ("VFS: Mounted root (%s filesystem)%s.\n",
Signature · 7 lines
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#6 lore raw

[final] Re: [patch-2.4.0-test13-pre3] rootfs (2nd attempt)

Quoted 4 lines · Andreas Dilger

If I could add one thing here (we have had a 2.2 patch like this for testing with ext3) - if you specify the rootfstype parameter don't use the "quiet" option to read_super, so you know why it couldn't mount a specific filesystem as root, and/or print rootfs type in the panic message.

Agree completely.

Here is the hopefully final version. Sorry, Linus, I thought the first version was final :) Looks like I have missed a couple of very useful things... Thanks to all who commented!

Regards,
Tigran

Documentation/kernel-parameters.txt +4 -1
diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
@@ -473,7 +473,10 @@
 
 	ro		[KNL] Mount root device read-only on boot.
 
-	root=		[KNL] root filesystem.
+	root=		[KNL] Mount root filesystem on specified (as hex or "/dev/XXX") device.
+
+	rootfs=		[KNL] Use filesystem type specified (e.g. rootfs=ext2) for root.
+ 
 
 	rw		[KNL] Mount root device read-write on boot.
 
fs/super.c +29 -0
diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
@@ -18,6 +18,7 @@
  *    Torbjörn Lindh ([email protected]), April 14, 1996.
  *  Added devfs support: Richard Gooch <[email protected]>, 13-JAN-1998
  *  Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
+ *  Added rootfs boot param. used by mount_root(): Tigran Aivazian. Dec 2000.
  */
 
 #include <linux/config.h>
@@ -58,6 +59,12 @@
 /* this is initialized in init/main.c */
 kdev_t ROOT_DEV;
 
+/* this can be set at boot time, e.g. rootfs=ext2 
+ * if set to invalid value or if read_super() fails on the specified
+ * filesystem type then mount_root() will panic
+ */
+static char rootfs[32] __initdata = "";
+
 int nr_super_blocks;
 int max_super_blocks = NR_SUPER;
 LIST_HEAD(super_blocks);
@@ -78,6 +85,17 @@
 static struct file_system_type *file_systems;
 static rwlock_t file_systems_lock = RW_LOCK_UNLOCKED;
 
+static int __init rootfs_setup(char *line)
+{
+	int n = strlen(line) + 1;
+
+	if (n > 1 && n < 32)
+		strncpy(rootfs, line, n);
+	return 1;
+}
+
+__setup("rootfs=", rootfs_setup);
+
 /* WARNING: This can be used only if we _already_ own a reference */
 static void get_filesystem(struct file_system_type *fs)
 {
@@ -1579,6 +1597,16 @@
 		goto mount_it;
 	}
 
+	if (*rootfs) {
+		fs_type = get_fs_type(rootfs);
+		if (fs_type) {
+  			sb = read_super(ROOT_DEV,bdev,fs_type,root_mountflags,NULL,0);
+			if (sb)
+				goto mount_it;
+		} 
+		/* don't try others if type given explicitly, same behaviour as mount(8) */
+		goto fail;
+	}
 	read_lock(&file_systems_lock);
 	for (fs_type = file_systems ; fs_type ; fs_type = fs_type->next) {
   		if (!(fs_type->fs_flags & FS_REQUIRES_DEV))
@@ -1593,6 +1621,7 @@
 		put_filesystem(fs_type);
 	}
 	read_unlock(&file_systems_lock);
+fail:
 	panic("VFS: Unable to mount root %s on %s", *rootfs ? rootfs : "fs", kdevname(ROOT_DEV));
 
 mount_it:

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/