2000-12-18 12:25:25

by Tigran Aivazian

[permalink] [raw]
Subject: [patch-2.4.0-test13-pre3] rootfs boot param. support

Hi Linus,

In November last year I wrote support for a new boot parameter called
"rootfs" implementing functionality similar to UnixWare7, i.e. being
able to specify the filesystem type to try first in mount_root() and if
this fails then go on to the usual loop over all registered filesystems.

At the time it was of pure academical interest (i.e. generally useful to
everybody) but now I realized that it is actually quite critical, i.e.
there exist filesystems (e.g. ext2) which are not able to detect their
structural integrity beyond simple damage to the superblock. So, as a
result, I have kernel panics because it successfully mounts the garbage as
a valid ext2 filesystem simply because the real filesystem on the block
device happens to use the location of the block containing superblock
different than ext2.

Therefore, please consider this tiny patch, tested against
2.4.0-test13-pre3.

Regards,
Tigran

diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
--- linux/Documentation/kernel-parameters.txt Tue Sep 5 21:51:14 2000
+++ rootfs/Documentation/kernel-parameters.txt Mon Dec 18 09:04:06 2000
@@ -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.

diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
--- linux/fs/super.c Tue Dec 12 09:25:22 2000
+++ rootfs/fs/super.c Mon Dec 18 10:03:31 2000
@@ -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[128] __initdata = "ext2";
+
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 < 128)
+ 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,12 @@
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;
+ }
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))


2000-12-18 12:42:59

by Andrzej Krzysztofowicz

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

"Tigran Aivazian wrote:"
> In November last year I wrote support for a new boot parameter called
> "rootfs" implementing functionality similar to UnixWare7, i.e. being
> able to specify the filesystem type to try first in mount_root() and if
> this fails then go on to the usual loop over all registered filesystems.
>
> At the time it was of pure academical interest (i.e. generally useful to
> everybody) but now I realized that it is actually quite critical, i.e.
> there exist filesystems (e.g. ext2) which are not able to detect their
> structural integrity beyond simple damage to the superblock. So, as a

It is more critical now if one wants to use eg. UMSDOS filesystem as root fs.
As the msdos filesystem is linked first system always tries to use it first
when there is a FAT filesystem on the root device.

One way of solving the problem is the "rootfs" parameter.
Changing link sequence to be non-alphabetic is another choice...

However, it is a separate issue that UMSDOS-root is broken in 2.4 at the
moment. But I hope it is not a permanent state.

> diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
> --- linux/Documentation/kernel-parameters.txt Tue Sep 5 21:51:14 2000
> +++ rootfs/Documentation/kernel-parameters.txt Mon Dec 18 09:04:06 2000
> @@ -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.
>

Regards
Andrzej
--
=======================================================================
Andrzej M. Krzysztofowicz [email protected]
phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math., Technical University of Gdansk

2000-12-18 13:16:04

by Peter Samuelson

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support


[Tigran Aivazian]
> +/* 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[128] __initdata = "ext2";

Better that we not hard-code anything here. If we want ext2 to be
tried first, we should link it first, which we already do.

Peter

[hand-edited patch, may not be right!]

--- linux/fs/super.c Tue Dec 12 09:25:22 2000
+++ rootfs/fs/super.c Mon Dec 18 10:03:31 2000
@@ -63,7 +63,7 @@
* 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 rootfs[32] __initdata = "";

int nr_super_blocks;
int max_super_blocks = NR_SUPER;

2000-12-18 13:53:42

by Tigran Aivazian

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

On Mon, 18 Dec 2000, Peter Samuelson wrote:

>
> [Tigran Aivazian]
> > +/* 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[128] __initdata = "ext2";
>
> Better that we not hard-code anything here. If we want ext2 to be
> tried first, we should link it first, which we already do.
>

no, because it would cause a "spurious" call to get_fs_type("") which we
don't want to happen (by default i.e. -- if user _really_ wants it
that is ok). The default of "ext2" is fine.

Regards,
Tigran

2000-12-18 14:48:11

by Andries E. Brouwer

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

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

2000-12-18 15:43:17

by Peter Samuelson

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support


[Tigran Aivazian]
> no, because it would cause a "spurious" call to get_fs_type("") which
> we don't want to happen (by default i.e. -- if user _really_ wants it
> that is ok). The default of "ext2" is fine.

I still disagree -- super.c is no place to dictate the default root
filesystem. And I agree with Andries that 'rootfs=' is confusing.

Peter

--- 2.4.0test13pre3+rootfs/fs/super.c~ Mon Dec 18 09:06:47 2000
+++ 2.4.0test13pre3+rootfs/fs/super.c Mon Dec 18 09:09:48 2000
@@ -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,7 +1597,8 @@
goto mount_it;
}

- fs_type = get_fs_type(rootfs);
+ 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)

2000-12-18 15:53:07

by Tigran Aivazian

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

On Mon, 18 Dec 2000, Peter Samuelson wrote:

>
> [Tigran Aivazian]
> > no, because it would cause a "spurious" call to get_fs_type("") which
> > we don't want to happen (by default i.e. -- if user _really_ wants it
> > that is ok). The default of "ext2" is fine.
>
> I still disagree -- super.c is no place to dictate the default root
> filesystem. And I agree with Andries that 'rootfs=' is confusing.

I have already covered both of these issues in the email I sent ages
ago... Here it is below (instead of re-sending) (the original got lost
because of the mail-abuse vs btconnect's randomness)

>From [email protected] Mon Dec 18 15:20:08 2000
Date: Mon, 18 Dec 2000 14:44:32 +0000 (GMT)
From: Tigran Aivazian <[email protected]>
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

On Mon, 18 Dec 2000 [email protected] wrote:
> (i) I prefer "rootfstype". Indeed, "rootfs" is ambiguous.
> It gives some property of the root filesystem, but which?

No, it is not ambiguous. Because, look at this sequence:

"ffs", "ufs", "bfs", "reiserfs", "vxfs", "sockfs", "pipefs", "nfs", ...

they are familiar to everyone and everyone immediately recognizes the
attribute they describe by the ending "fs". So, the attribute is
immediately obvious and should be recognized by programmer without need to
explicitly comment about it (it just is like it is _obvious_ that static
int x; is initialized to 0 and there is no need to start asking oneself
"what is this attribute of x that is being set to 0 here... ah.. it's the
_value_ thereof!" )

> +static char rootfs[128] __initdata = "ext2";
>
> (ii) It is a bad idea to arbitrarily select "ext2".

No, how could you say it is a bad idea without saying also _what_ is a
good idea? If there is no replacement for a bad idea then it is, by
definition, a good (or best) idea. So, having not found a better initial
value for rootfs[] I set it to "ext2". Setting it to "" is no good as I
explained to Peter. Setting it to NULL is also no good because needs an
extra line of code in mount_root() to check for it. So, what then? I say
"ext2" as it is the most popular Linux filesystem at the moment.

> (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.

that gives it a different semantics, i.e. you are changing the rules. I am
not sure which rules are better but there are advantages to it being as
is, e.g. one could hardcode "rootfs=vxfs" in their lilo.conf and rely on
fallback to ext2 for some of the partitions but not others.

This one is a matter of taste and if Linus says your way is better I will
redo the patch immediately. Both ways are fine with me.

Regards,
Tigran

>From [email protected] Mon Dec 18 15:20:13 2000
Date: Mon, 18 Dec 2000 14:54:40 +0000 (GMT)
From: Tigran Aivazian <[email protected]>
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

On Mon, 18 Dec 2000, Tigran Aivazian wrote:
> Setting it to NULL is also no good because needs an
> extra line of code in mount_root() to check for it.

before N people misunderstand the above -- I meant having just a
pointer and doing kmalloc/kfree manually.

Regards,
Tigran




2000-12-18 15:53:37

by Peter Samuelson

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support


[Andries Brouwer]
> (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

--- test13pre3+rootfs/fs/super.c~ Mon Dec 18 09:06:47 2000
+++ test13pre3+rootfs/fs/super.c Mon Dec 18 09:18:02 2000
@@ -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:

2000-12-18 16:06:08

by Tigran Aivazian

[permalink] [raw]
Subject: Re: [patch-2.4.0-test13-pre3] rootfs boot param. support

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

On Mon, 18 Dec 2000, Peter Samuelson wrote:
> -__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 :)

> {
> - struct file_system_type * fs_type;
> + struct file_system_type * fs_type = NULL;

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

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


2000-12-18 16:30:33

by Tigran Aivazian

[permalink] [raw]
Subject: [patch-2.4.0-test13-pre3] rootfs (2nd attempt)

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

diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
--- linux/Documentation/kernel-parameters.txt Tue Sep 5 21:51:14 2000
+++ rootfs/Documentation/kernel-parameters.txt Mon Dec 18 09:04:06 2000
@@ -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.

diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
--- linux/fs/super.c Tue Dec 12 09:25:22 2000
+++ rootfs/fs/super.c Mon Dec 18 14:49:08 2000
@@ -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:




2000-12-18 16:33:33

by Tigran Aivazian

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

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

diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
--- linux/Documentation/kernel-parameters.txt Tue Sep 5 21:51:14 2000
+++ rootfs/Documentation/kernel-parameters.txt Mon Dec 18 09:04:06 2000
@@ -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.

diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
--- linux/fs/super.c Tue Dec 12 09:25:22 2000
+++ rootfs/fs/super.c Mon Dec 18 15:03:44 2000
@@ -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:

2000-12-18 18:58:02

by Andreas Dilger

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

Tigran, you write:
> 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
=============================================================================
diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
--- linux/fs/super.c Tue Dec 12 09:25:22 2000
+++ rootfs/fs/super.c Mon Dec 18 14:49:08 2000
@@ -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",

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

2000-12-18 19:02:52

by Tigran Aivazian

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

On Mon, 18 Dec 2000, Andreas Dilger wrote:
> 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

diff -urN -X dontdiff linux/Documentation/kernel-parameters.txt rootfs/Documentation/kernel-parameters.txt
--- linux/Documentation/kernel-parameters.txt Tue Sep 5 21:51:14 2000
+++ rootfs/Documentation/kernel-parameters.txt Mon Dec 18 09:04:06 2000
@@ -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.

diff -urN -X dontdiff linux/fs/super.c rootfs/fs/super.c
--- linux/fs/super.c Tue Dec 12 09:25:22 2000
+++ rootfs/fs/super.c Mon Dec 18 15:03:44 2000
@@ -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:

2000-12-19 07:21:44

by Tri D. Hoang

[permalink] [raw]
Subject: Is there a devfs patch for 2.2.18?

Hi,
Is there a devfs patch for 2.2.18 or how do I
get devfs to work with 2.2.18?

Tri
[email protected]