Re: waiting 10s before mounting root filesystem?

From: Jesper Juhl
Date: Thu Dec 30 2004 - 18:35:40 EST


On Thu, 30 Dec 2004, Marcelo Tosatti wrote:

> On Tue, Dec 28, 2004 at 07:59:22PM -0500, William Park wrote:
> > On Mon, Dec 27, 2004 at 10:23:34PM +0100, Andreas Unterkircher wrote:
> > > >>How do I make the kernel to wait about 10s before attempting to
> > > >>mount root filesystem? Is there obscure kernel parameter?
> > > >>
> > > >>I can load the kernel from /dev/fd0, then mount /dev/hda2 as root
> > > >>filesystem. But, I can't seem to mount /dev/sda1 (USB key drive) as
> > > >>root filesystem. All relevant USB and SCSI modules are compiled
> > > >>into the kernel. I think kernel is too fast in panicking. I would
> > > >>like the kernel to wait about 10s until 'usb-storage' and 'sd_mod'
> > > >>work out all the details.
> > > >
> > > >This is really suited to the task of an initrd, then you can spin
> > > >until the usb storage device comes up in a bash script or something
> > > >similar.
> > >
> > > Or you could try a patch from Randy Dunlap & Eric Lammerts [1] which
> > > loops around in do_mounts.c
> > > until the root filesystem can be mounted.... not that beautiful - but it
> > > works :)
> > >
> > > [1] http://www.xenotime.net/linux/usb/usbboot-2422.patch
> > >
> > > Cheers,
> > > Andreas
> > >
> > > PS: In the same manner you can do it with 2.6
> >
> > Thanks Andreas. I can now boot from my el-cheapo USB key drive (256MB
> > SanDisk Cruzer Mini). Since mine takes about 5sec to show up, I decided
> > to wait 5sec instead of 1sec. Here is diff for 2.6.10:
> >
> > --- ./init/do_mounts.c--orig 2004-12-27 17:36:35.000000000 -0500
> > +++ ./init/do_mounts.c 2004-12-28 17:27:26.000000000 -0500
> > @@ -301,7 +301,14 @@ retry:
> > root_device_name, b);
> > printk("Please append a correct \"root=\" boot option\n");
> >
> > +#if 0 /* original code */
> > panic("VFS: Unable to mount root fs on %s", b);
> > +#else
> > + printk ("Waiting 5 seconds to try again...\n");
> > + set_current_state(TASK_INTERRUPTIBLE);
> > + schedule_timeout(5 * HZ);
> > + goto retry;
> > +#endif
> > }
> > panic("VFS: Unable to mount root fs on %s", __bdevname(ROOT_DEV, b));
> > out:
>
> William,
>
> Solar version which is now merged in v2.4 looks better (5s sleep is too long and only one try) IMO.
>
> It sleeps 1s each time, 10 times. More reliable and faster.
>
> http://linux.bkbits.net:8080/linux-2.4/patch@xxxxxxxxxxx?nav=index.html|ChangeSet@-3w|cset@xxxxxxxxxxx

That's a nice patch. Why not make the same change in 2.6?
I forward ported the patch linked above with a few minor changes - my
version differs from the original in these ways :
- use ssleep() instead of schedule_timeout.
- rename tries to retries and actually retry the specified nr of times
( if (retries--) {...} instead of if (--tries) {...} ).
- use a short instead of int to hold the retry count.
- change the text outputted a little bit.
- retry a few more times (15 instead of 9) since if we fail here we are
going to panic() we might as well try hard, and who knows how slow some
devices can be?

Andrew, would you consider including the patch below in 2.6 ?


Signed-off-by: Jesper Juhl <juhl-lkml@xxxxxx>

diff -up linux-2.6.10-bk2-orig/init/do_mounts.c linux-2.6.10-bk2/init/do_mounts.c
--- linux-2.6.10-bk2-orig/init/do_mounts.c 2004-12-24 22:34:31.000000000 +0100
+++ linux-2.6.10-bk2/init/do_mounts.c 2004-12-31 00:00:37.000000000 +0100
@@ -6,6 +6,7 @@
#include <linux/suspend.h>
#include <linux/root_dev.h>
#include <linux/security.h>
+#include <linux/delay.h>

#include <linux/nfs_fs.h>
#include <linux/nfs_fs_sb.h>
@@ -278,6 +279,7 @@ void __init mount_block_root(char *name,
char *fs_names = __getname();
char *p;
char b[BDEVNAME_SIZE];
+ short retries = 15;

get_fs_names(fs_names);
retry:
@@ -297,9 +299,16 @@ retry:
* and bad superblock on root device.
*/
__bdevname(ROOT_DEV, b);
- printk("VFS: Cannot open root device \"%s\" or %s\n",
+ if (retries--) {
+ printk(KERN_WARNING "VFS: Cannot open root device "
+ "\"%s\" or %s, retrying in 1s.\n",
root_device_name, b);
- printk("Please append a correct \"root=\" boot option\n");
+ ssleep(1);
+ goto retry;
+ }
+ printk(KERN_CRIT "VFS: Cannot open root device \"%s\" or %s, giving up.\n",
+ root_device_name, b);
+ printk(KERN_CRIT "Please append a correct \"root=\" boot option\n");

panic("VFS: Unable to mount root fs on %s", b);
}


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/