Skip to contentSkip to conversation

Possible to delay boot process to boot from USB subsystem?

PATCH Bill Catlan 4 participants 9 messages May 3, 2004 – May 5, 2004 VFS

lore
Share & tools
lore
#0 lore raw

Hello,

The below message appeared on linux-kernel in June 2002. The patch allows booting from a USB harddrive and was designed for the 2.4.14-pre8-ext3 kernel, but I was able to manually apply it to a Debian 2.4.18 kernel.

I am now trying to upgrade to a 2.4.26 kernel, and I am unable to create the same "boot from floppy with rootfs on a USB drive" scenario that I created with the modified 2.4.18 kernel. I believe my current issue with the 2.4.26 kernel is the same race condition as on the 2.4.18 kernel since I get the "Initializing USB Mass Storage driver..." notice, but then i get "Kernel panic: No init found. Try passing init= option to kernel." Given time, I suspect that the USB storage subsystem would come online and the kernel would be able to mount the rootfs on it.

fs/super.c has change dramatically and the below patch now seems obsolete.

Is there a similar patch for newer kernels - or any other way to cause the boot process to pause between loading the kernel and modules and running /sbin/init?

TIA.

Bill

Quoted 4 lines · Paul Stoeber

It simply sleeps 10 seconds before mount_block_root().

I get an 'Unable to mount root' panic if I don't apply it, because the attached device rolls in too late.

A while ago I made the patch below. I retries every second until the root device appears. Advantages:
- no delay when the device is already there
- it also works if it takes longer than 10s to find the harddisk (for example, if you plug it in later)

I don't know if it applies cleanly to current kernels.

Eric

fs/super.c renamed from fs/super.c.orig +6 -4
@@ -1009,11 +1009,13 @@
 		 * Allow the user to distinguish between failed open
 		 * and bad superblock on root device.
 		 */
-		printk ("VFS: Cannot open root device \"%s\" or %s\n",
+		printk ("VFS: Cannot open root device \"%s\" or %s, retrying in 1s.\n",
 			root_device_name, kdevname (ROOT_DEV));
-		printk ("Please append a correct \"root=\" boot option\n");
-		panic("VFS: Unable to mount root fs on %s",
-			kdevname(ROOT_DEV));
+
+		/* wait 1 second and try again */
+		current->state = TASK_INTERRUPTIBLE;
+		schedule_timeout(HZ);
+		goto retry;
 	}
 
 	check_disk_change(ROOT_DEV);

-

#1 lore raw

On Sun, 2 May 2004 19:27:08 -0400 "Bill Catlan" <[email protected]> wrote:

| Hello,
| 
| The below message appeared on linux-kernel in June 2002.  The patch allows
| booting from a USB harddrive and was designed for the 2.4.14-pre8-ext3 kernel,
| but I was able to manually apply it to a Debian 2.4.18 kernel.
| 
| I am now trying to upgrade to a 2.4.26 kernel, and I am unable to create the
| same "boot from floppy with rootfs on a USB drive" scenario that I created with
| the modified 2.4.18 kernel.  I believe my current issue with the 2.4.26 kernel
| is the same race condition as on the 2.4.18 kernel since I get the "Initializing
| USB Mass Storage driver..." notice, but then i get "Kernel panic: No init found.
| Try passing init= option to kernel."  Given time, I suspect that the USB storage
| subsystem would come online and the kernel would be able to mount the rootfs on
| it.
| 
| fs/super.c has change dramatically and the below patch now seems obsolete.
| 
| Is there a similar patch for newer kernels - or any other way to cause the boot
| process to pause between loading the kernel and modules and running /sbin/init?
| 
| TIA.
| 
| Bill
| 
| On Sun, Jun 02, 2002 at 10:13:22PM +0200, Paul Stoeber wrote:
| > It simply sleeps 10 seconds before mount_block_root().
| >
| > I get an 'Unable to mount root' panic if I don't apply it,
| > because the attached device rolls in too late.
| 
| A while ago I made the patch below. I retries every second until the root
| device appears. Advantages:
| - no delay when the device is already there
| - it also works if it takes longer than 10s to find the harddisk
|   (for example, if you plug it in later)
| 
| I don't know if it applies cleanly to current kernels.
| 
| Eric
| 
| --- linux-2.4.14-pre8-ext3/fs/super.c.orig	Fri Nov 16 00:59:18 2001
| +++ linux-2.4.14-pre8-ext3/fs/super.c	Fri Nov 16 01:07:26 2001
| @@ -1009,11 +1009,13 @@
|  		 * Allow the user to distinguish between failed open
|  		 * and bad superblock on root device.
|  		 */
| -		printk ("VFS: Cannot open root device \"%s\" or %s\n",
| +		printk ("VFS: Cannot open root device \"%s\" or %s, retrying in 1s.\n",
|  			root_device_name, kdevname (ROOT_DEV));
| -		printk ("Please append a correct \"root=\" boot option\n");
| -		panic("VFS: Unable to mount root fs on %s",
| -			kdevname(ROOT_DEV));
| +
| +		/* wait 1 second and try again */
| +		current->state = TASK_INTERRUPTIBLE;
| +		schedule_timeout(HZ);
| +		goto retry;
|  	}
| 
|  	check_disk_change(ROOT_DEV);
| -

I updated that patch to 2.4.22 but haven't checked it since then. I can't test it... if you can, that would be great.
If it doesn't apply cleanly to 2.4.26, let me know and I'll work on it.

Patch is here:
http://www.xenotime.net/linux/usb/usbboot-2422.patch

--
~Randy

#2 lore raw

Thanks Randy. As the below output shows, your patch applies cleanly to 2.4.26 source, but I have not yet had the chance to compile and test my configuration.

[root@plain linux-2.4.26]# patch init/do_mounts.c
usbboot-2422.patch
patching file init/do_mounts.c
Hunk #1 succeeded at 367 (offset 1 line).

Bill

Quoted 7 lines · --- "Randy.Dunlap

I updated that patch to 2.4.22 but haven't checked it since then.
I can't test it... if you can, that would be great. If it doesn't apply cleanly to 2.4.26, let me know and I'll work
on it.

Quoted 6 lines

Patch is here:

http://www.xenotime.net/linux/usb/usbboot-2422.patch

--
~Randy

__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover

#6 lore raw
In reply to Bill Catlan

Hi,

I include the following patch in all my kernels. It adds a "setuptime" boot option which allows one to specify how many milliseconds to wait before mounting the root FS. I usually wait 2500 ms to boot on USB flash, but I once saw a machine which required a bit more (4 sec). The advantage is that if it isn't enough, just reboot and change the paramter.

Regards,
Willy

init/main.c +24 -0
diff -urN linux-2.4.23-rc3/init/main.c linux-2.4.23-rc3-setuptime/init/main.c
@@ -127,6 +127,7 @@
 
 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
+static int setuptime;	/* time(ms) to let devices set up before root mount */
 
 static int __init profile_setup(char *str)
 {
@@ -137,6 +138,15 @@
 
 __setup("profile=", profile_setup);
 
+static int __init setuptime_setup(char *str)
+{
+    int par;
+    if (get_option(&str,&par)) setuptime = par;
+	return 1;
+}
+
+__setup("setuptime=", setuptime_setup);
+
 static int __init checksetup(char *line)
 {
 	struct kernel_param *p;
@@ -553,12 +563,26 @@
 
 extern void prepare_namespace(void);
 
+static int finish_setup()
+{
+	int tleft;
+	if (setuptime) {
+		printk("Waiting %d ms for devices to set up.\n", setuptime);
+		tleft = setuptime * HZ / 1000;
+		while (tleft) {
+			set_current_state(TASK_INTERRUPTIBLE);
+			tleft = schedule_timeout(tleft);
+		}
+	}
+}
+
 static int init(void * unused)
 {
 	struct files_struct *files;
 	lock_kernel();
 	do_basic_setup();
 
+	finish_setup();
 	prepare_namespace();
 
 	/*
#3 lore raw
In reply to Randy.Dunlap

Randy,

Thanks for the patch, but it does not work for 2.4.26. The kernel panic I get ("Kernel panic: No init found. Try passing init= option to kernel.") is generated by the init() function in init/main.c. Willy's patch applies to init/main.c, perhaps yours should now as well (i.e., in later kernels)? (I have not tested Willy's patch, but he claims success with a 2.4.23 kernel.)

I like your approach better because I do not have to set a time, it just keeps trying in a loop. Since mounting the rootfs is a critical step, I don't mind the infinite looping until success - especially with hot swappable devices. I had nice functionality on a 2.4.18 kernel, but would rather keep current with the kernel.

Hope this helps. Please let me know what you think might be possible, as well as a timeframe, if at all possible. Thanks.

Bill

----- Original Message -----
From: "Randy.Dunlap" <[email protected]>
To: "Bill Catlan" <[email protected]>
Cc: <[email protected]>
Sent: Sunday, May 02, 2004 9:27 PM
Subject: Re: Possible to delay boot process to boot from USB subsystem?

Quoted 6 lines · On Sun, 2 May 2004 19:27:08 -0400 "Bill Catlan" <[email protected]> wrote:
| Hello,
|
| The below message appeared on linux-kernel in June 2002.  The patch allows
| booting from a USB harddrive and was designed for the 2.4.14-pre8-ext3

kernel,

Quoted 4 lines
| but I was able to manually apply it to a Debian 2.4.18 kernel.
|
| I am now trying to upgrade to a 2.4.26 kernel, and I am unable to create the
| same "boot from floppy with rootfs on a USB drive" scenario that I created

with

Quoted 1 line

| the modified 2.4.18 kernel. I believe my current issue with the 2.4.26

kernel

Quoted 1 line

| is the same race condition as on the 2.4.18 kernel since I get the

"Initializing

Quoted 1 line

| USB Mass Storage driver..." notice, but then i get "Kernel panic: No init

found.

Quoted 1 line

| Try passing init= option to kernel." Given time, I suspect that the USB

storage

Quoted 1 line

| subsystem would come online and the kernel would be able to mount the rootfs

on

Quoted 5 lines
| it.
|
| fs/super.c has change dramatically and the below patch now seems obsolete.
|
| Is there a similar patch for newer kernels - or any other way to cause the

boot

Quoted 1 line

| process to pause between loading the kernel and modules and running

/sbin/init?

Quoted 53 lines
|
| TIA.
|
| Bill
|
| On Sun, Jun 02, 2002 at 10:13:22PM +0200, Paul Stoeber wrote:
| > It simply sleeps 10 seconds before mount_block_root().
| >
| > I get an 'Unable to mount root' panic if I don't apply it,
| > because the attached device rolls in too late.
|
| A while ago I made the patch below. I retries every second until the root
| device appears. Advantages:
| - no delay when the device is already there
| - it also works if it takes longer than 10s to find the harddisk
|   (for example, if you plug it in later)
|
| I don't know if it applies cleanly to current kernels.
|
| Eric
|
| --- linux-2.4.14-pre8-ext3/fs/super.c.orig Fri Nov 16 00:59:18 2001
| +++ linux-2.4.14-pre8-ext3/fs/super.c Fri Nov 16 01:07:26 2001
| @@ -1009,11 +1009,13 @@
|  * Allow the user to distinguish between failed open
|  * and bad superblock on root device.
|  */
| - printk ("VFS: Cannot open root device \"%s\" or %s\n",
| + printk ("VFS: Cannot open root device \"%s\" or %s, retrying in 1s.\n",
|  root_device_name, kdevname (ROOT_DEV));
| - printk ("Please append a correct \"root=\" boot option\n");
| - panic("VFS: Unable to mount root fs on %s",
| - kdevname(ROOT_DEV));
| +
| + /* wait 1 second and try again */
| + current->state = TASK_INTERRUPTIBLE;
| + schedule_timeout(HZ);
| + goto retry;
|  }
|
|  check_disk_change(ROOT_DEV);
| -

I updated that patch to 2.4.22 but haven't checked it since then. I can't test it... if you can, that would be great.
If it doesn't apply cleanly to 2.4.26, let me know and I'll work on it.

Patch is here:
http://www.xenotime.net/linux/usb/usbboot-2422.patch

--
~Randy

#7 lore raw
In reply to Willy Tarreau

Thanks Willy. I like to automatic looping of Randy's patch (I had it working nicely on a 2.4.18 kernel) because I don't have to set a time in case one machine takes longer than another.

So far, however, I haven't got Randy's patch working for a newer kernel, so I may try yours.

Would I only have to run make in the directory where I'm patching the file, then make bzImage, make modules_install, and make install from the top level to apply your patch? Compiling all of my modules takes a long time, with random lock-ups during compile gumming up the works as well. :-/ Any tips appreciated.

Thanks.

Bill

----- Original Message -----
From: "Willy Tarreau" <[email protected]>
To: "Bill Catlan" <[email protected]>
Cc: <[email protected]>
Sent: Monday, May 03, 2004 1:34 AM
Subject: Re: Possible to delay boot process to boot from USB subsystem?

Quoted 67 lines

Hi,

I include the following patch in all my kernels. It adds a "setuptime" boot option which allows one to specify how many milliseconds to wait before mounting the root FS. I usually wait 2500 ms to boot on USB flash, but I once saw a machine which required a bit more (4 sec). The advantage is that if it isn't enough, just reboot and change the paramter.

Regards,
Willy

diff -urN linux-2.4.23-rc3/init/main.c linux-2.4.23-rc3-setuptime/init/main.c

init/main.c Sun Nov 23 18:12:19 2003 renamed from init/main.c Fri Oct 10 08:47:16 2003 +24 -0
@@ -127,6 +127,7 @@
 
 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
+static int setuptime; /* time(ms) to let devices set up before root mount */
 
 static int __init profile_setup(char *str)
 {
@@ -137,6 +138,15 @@
 
 __setup("profile=", profile_setup);
 
+static int __init setuptime_setup(char *str)
+{
+    int par;
+    if (get_option(&str,&par)) setuptime = par;
+ return 1;
+}
+
+__setup("setuptime=", setuptime_setup);
+
 static int __init checksetup(char *line)
 {
  struct kernel_param *p;
@@ -553,12 +563,26 @@
 
 extern void prepare_namespace(void);
 
+static int finish_setup()
+{
+ int tleft;
+ if (setuptime) {
+ printk("Waiting %d ms for devices to set up.\n", setuptime);
+ tleft = setuptime * HZ / 1000;
+ while (tleft) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ tleft = schedule_timeout(tleft);
+ }
+ }
+}
+
 static int init(void * unused)
 {
  struct files_struct *files;
  lock_kernel();
  do_basic_setup();
 
+ finish_setup();
  prepare_namespace();
 
  /*
#8 lore raw
Quoted 3 lines · Bill Catlan

Thanks Willy. I like to automatic looping of Randy's patch (I had it working nicely on a 2.4.18 kernel) because I don't have to set a time in case one machine takes longer than another.

I certainly can understand this, although I've never tried it yet.

Quoted 7 lines

So far, however, I haven't got Randy's patch working for a newer kernel, so I may try yours.

Would I only have to run make in the directory where I'm patching the file, then make bzImage, make modules_install, and make install from the top level to apply your patch? Compiling all of my modules takes a long time, with random lock-ups during compile gumming up the works as well. :-/ Any tips appreciated.

No exactly, you should not run 'make' from the 'init' directory, but rather tell 'make' where you want it to check for changes :

# make bzImage SUBDIRS=init

It will skip over other directories (such as drivers, fs, net, ...) and only recompile below 'init'. I do this very often and it's very convenient. However, you should not do this if you have changed certain compile options or things that might imply different dependencies.

A hint to check if it has been correctly configured :

# nm vmlinux | grep setuptime
c01b2b80 d __setup_setuptime_setup
c01ab039 d __setup_str_setuptime_setup
c015700c b setuptime
c01b31b0 t setuptime_setup

Regards,
Willy

#4 lore raw
In reply to Bill Catlan
Quoted 7 lines · Bill Catlan

Randy,

Thanks for the patch, but it does not work for 2.4.26. The kernel panic I get ("Kernel panic: No init found. Try passing init= option to kernel.") is generated by the init() function in init/main.c. Willy's patch applies to init/main.c, perhaps yours should now as well (i.e., in later kernels)? (I have not tested Willy's patch, but he claims success with a 2.4.23 kernel.)

This is a completely different error from "VFS: Cannot open root device" or "unable to mount root".

Are you sure you have a "/sbin" directory with an *executable* "init" file on the usb harddrive?

Does your init file depend on libraries that you do not have under "/lib"? (you can check with "ldd init")

If your init is a script, does it specify a complete path to the interpreter, and do you have an *executable* interpreter there? Does the interpreter require libraries or is it static?

I hope this helps,

Signature · 2 lines
Paulo Marques - www.grupopie.com
"In a world without walls and fences who needs windows and gates?"
#5 lore raw

Hi Paulo,

Thanks for the feedback. I was starting to think the same thing myself, but it turns out the root cause is the same thing - namely, slow startup of the USB storage subsystem.

The differing symptom (i.e., different error messages) is entirely due to the difference in kernel versions. I got my setup (2.4.26) working with Willy's patch. I am going to re-test Randy's patch as I needed to modify the "preload" order of my modules in my initrd image in order to even get Willy's patch to work. With the reordering, I suspect (50/50 chance I think) that Randy's patch for the 2.4.22 kernel may work on the 2.4.26 kernel as well.

I originally thought that I had compiled the necessary scsi and usb stuff into the kernel, but upon eventually revisiting my kernel config file I learned along the way and to my chagrin that I had left them as modules, adding this slight complication.

Stay tuned for our next episode! :)

Bill

----- Original Message -----
From: "Paulo Marques" <[email protected]>
To: "Bill Catlan" <[email protected]>
Cc: "Randy.Dunlap" <[email protected]>; <[email protected]>
Sent: Tuesday, May 04, 2004 2:53 PM
Subject: Re: Possible to delay boot process to boot from USB subsystem?

Quoted 5 lines
Quoted 3 lines · Bill Catlan

Randy,

Thanks for the patch, but it does not work for 2.4.26. The kernel panic I

get

Quoted 3 lines
Quoted 3 lines

("Kernel panic: No init found. Try passing init= option to kernel.") is generated by the init() function in init/main.c. Willy's patch applies to init/main.c, perhaps yours should now as well (i.e., in later kernels)? (I

have

Quoted 10 lines
Quoted 1 line

not tested Willy's patch, but he claims success with a 2.4.23 kernel.)

This is a completely different error from "VFS: Cannot open root device" or "unable to mount root".

Are you sure you have a "/sbin" directory with an *executable* "init" file on the usb harddrive?

Does your init file depend on libraries that you do not have under "/lib"?

(you

Quoted 4 lines

can check with "ldd init")

If your init is a script, does it specify a complete path to the interpreter, and do you have an *executable* interpreter there? Does the interpreter

require

Quoted 7 lines

libraries or is it static?

I hope this helps,

Signature · 2 lines
Paulo Marques - www.grupopie.com
"In a world without walls and fences who needs windows and gates?"