FS#18428 - [mkinitcpio] waiting for usb devices to settle

Attached to Project: Arch Linux
Opened by Michael Gutmann (Gutnix) - Monday, 22 February 2010, 09:29 GMT
Last edited by Thomas Bächler (brain0) - Sunday, 27 February 2011, 11:33 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Thomas Bächler (brain0)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

Booting a normal Arch installation from USB sticks makes problems with slow usb sticks
and f.e. root fs on lvm. The lvm hook runs when the device has'nt appeared and therefore a root fs
on lvm is not found. I propose to add a usb hook (there is none at the moment), which waits a
configurable amount of seconds defined via a kernel commandline variable "usbdelay".
A reasonable default could be 10 (at least it works with my usb stick ;-)).
For it to work the usb hook should be put before mdadm, lvm2 and filesystems in HOOKS in mkinitcpio.conf.

Package: mkinitcpio

New file: /lib/initcpio/hooks/usb

# vim: set ft=sh:
run_hook ()
{
if [ -z "${usbdelay}" ] || ! [ "${usbdelay}" -ge 0 ]; then
export usbdelay=10
fi
msg ":: waiting $usbdelay seconds for usb devices to settle..."
sleep $usbdelay
msg ":: waiting for usbdevices done."
}


Changes to: /lib/initcpio/install/usb
14c14
< SCRIPT=""
---
> SCRIPT="usb"

This task depends upon

Closed by  Thomas Bächler (brain0)
Sunday, 27 February 2011, 11:33 GMT
Reason for closing:  Fixed
Comment by Jan de Groot (JGC) - Monday, 22 February 2010, 10:29 GMT
Isn't this what the rootdelay variable was used for?
Comment by Michael Gutmann (Gutnix) - Monday, 22 February 2010, 10:40 GMT
No, rootdelay comes to work _after_ mdadm and lvm2 hooks are called. I don't know, if we should better call this a bug ;-)
Comment by Thomas Bächler (brain0) - Monday, 22 February 2010, 12:22 GMT
I am aware of the problem. Using USB without LVM will work fine, as the poll_device logic we use will take care of everything. This is also what any kernel developer will recommend, as the trend generally goes into the direction of asynchronous device scanning/detection (I had a statement about that by an upstream dev on LKML, but I can't find it right now). I thought about several different solutions:

1) Have LVM auto-assembled by udev. I have no idea if this is easily possible, and it probably requires changes in the upstream device-mapper code. This would be the most elegant solution as our usual poll_device logic will start working with slow devices.
2) Try vgscan && vgchange in a loop until a certain volume group has been found. This will be very ugly code.
3) Add a possiblity to specify a device to "wait" for before assembling LVM (using the poll_device method).
4) Add a generic "sleep" hook with which we can insert arbitrary sleeps in the mkinitcpio configuration. This would be similar to the solution propsed above, only that it would be done separately of the usb hook and thus be a more generic solution.

Solution 1) would be the most favorable, but is probably not possible right now. 2) is ugly and I don't want it. 3) seems like a good idea (you could use the UUID of the physical volume and specify lvmwait=/dev/disk/by-uuid/$uuid on the command line) as it would only wait as long as needed, but requires specific user configuration (in particular: knowledge of the UUID of the physical volume). 4) could be useful for many more things and should be implemented in any case.
Comment by Michael Gutmann (Gutnix) - Monday, 22 February 2010, 13:02 GMT
Thanks for your detailed explanation. I'll take a look a 3) and how feasible it is. But if I do LVM partitions by hand during install, it should be easy to check up the UUID.
On the other hand I was thinking about something like 4) too. It would be nice to have a method to delay booting between hooks, although I don't know, if a boot delay is necessary elsewhere than waiting for /.
Comment by Michael Gutmann (Gutnix) - Monday, 22 February 2010, 14:45 GMT
Hmm, lvmwait seems to be too late. poll_device is called in init _after_ the lvm2 hook is run. What I need is a rerun of lvm2 or waiting for a device to appear, before running lvm2.
Comment by Thomas Bächler (brain0) - Monday, 22 February 2010, 15:50 GMT
You got me wrong earlier, just wait a few hours until I do this.
Comment by Thomas Bächler (brain0) - Monday, 22 February 2010, 17:49 GMT Comment by Thomas Bächler (brain0) - Monday, 22 February 2010, 18:06 GMT
And 3): http://repos.archlinux.org/wsvn/packages/?op=comp&compare[]=%2Flvm2%2Ftrunk@69783&compare[]=%2Flvm2%2Ftrunk@69788

Can you test this please? Just download the lvm2_install and lvm2_hook files from websvn and put them to /lib/initcpio/install/lvm2 and /lib/initcpio/hooks/lvm2 respectively.
Comment by Michael Gutmann (Gutnix) - Tuesday, 23 February 2010, 12:47 GMT
Hi Thomas, sorry for the delay!

3) works like a charm! But there is a problem with the uuid: the uudis from PVs are not shown in /dev/disk/by-uuid, although blkid reports a uuid for the device. Where does poll_wait look for the uuid?
Comment by Thomas Bächler (brain0) - Tuesday, 23 February 2010, 15:19 GMT
Okay, this is bad and it means the solution 3) is not as good as I thought. We could fix that by changing
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
to
ENV{ID_FS_USAGE}=="filesystem|other|crypto|raid", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
in /lib/udev/rules.d/13-dm-disk.rules and /lib/udev/rules.d/60-persistent-storage.rules. I don't know if that is a good idea, or a bad one, from what I see it shouldn't harm anyone. It probably won't be accepted upstream though. I may have to take this problem to the dm-devel mailing list.
Comment by Eric Belanger (Snowman) - Sunday, 28 February 2010, 08:57 GMT
FYI: I've just push lvm2/device-mapper 2.02.61-1 in testing. It contains the new lvm2_install and lvm2_hook files. I presume they are working.

Thomas: Feel free to remove lvm2/device-mapper from testing if the hooks changes are not ready yet.
Comment by Thomas Bächler (brain0) - Saturday, 06 March 2010, 14:12 GMT
The hook changes are okay, just not as useful as I thought.

Michael, can you please try this? The solution should be much cleaner: http://mailman.archlinux.org/pipermail/arch-general/2010-March/011746.html
It should work without any additional kernel parameters and replaces the lvm2 hook.
Comment by Michael Gutmann (Gutnix) - Monday, 08 March 2010, 10:22 GMT
It works with one flaw: dm-mod is not loaded automatically. I was dropped to initrd cmdline without loading dm-mod. After doing modprobe dm-mod, lvm vgscan, lvm vgchange -a y (and exit of course ;-)) the system started as usual. Well, I'm not sure, what to blame; assuming you need dm-mod when enabling the hook lvm_autoassemble, can/should dm-mod be loaded by the hook? Or should it be necessary to add dm-mod to MODULES in mkinitcpio.conf by hand?
Comment by Thomas Bächler (brain0) - Monday, 08 March 2010, 10:30 GMT
Okay, I completely forgot about that. With MODULES="dm_mod" it should work (I only tested with lvm oder dm-crypt, and thus dm-mod was already loaded). I'll think about a better solution.
Comment by Thomas Bächler (brain0) - Sunday, 27 February 2011, 11:32 GMT
I am not going to continue working on lvm_autoassemble until upstream provides a nice method to do this. A possible solution is provided by this extenstion to the sleep hook: https://projects.archlinux.org/mkinitcpio.git/commit/?id=02e263c5bcec23f9134140dcef5b6f5a4412ed2b

Closing.

Loading...