Linux – Understanding the Linux boot process, subsystem initialization, & udev rules

automountbootdebianlinuxudev

I'm creating UDEV rules for automounting external drives on a headless server, much in the same way as Gnome-VFS does automounting during a user session.

I'm concerned with the rule's behavior at boot-time. There's a good chance one of these drives will be connected during a boot, and I'd prefer any connected drives get mounted in the right place. The drives might be either USB or Firewire, and they are mounted from a shell script fired off by UDEV on detecting an "add".

Here are my questions:

  1. When UDEV runs the mount for these devices at boot, will the system be ready to mount it? Or will the script get triggered too early?

  2. If it's too early, what's a good way for a script to tell that the system isn't ready yet (so sleep a while before checking again)?

  3. The UDEV rule matches ACTION=="add". Does this event even fire at system boot?

Best Answer

Having just crammed up on udev to get USB stick to automount when not running a gui, (and not using autofs.)

  1. Yes veronica, udev does run awfully early.

    agent scripts can happily fork off and run after a sleep.

  2. udevadm settle might help you out here in addition to checking runlevel.

  3. action="Add" is run at boot, not just hotplug.

Whether action="remove" is run at shutdown, now that's a fish of a different colour.