You are not logged in.

#1 2010-07-02 09:15:27

useradded
Member
From: Edinburgh, UK
Registered: 2010-05-15
Posts: 77

[SOLVED]system fails to boot since adding udev rules for automounting

Hello

I have recently been trying to use udev rules to automount, and putting together stuff from the wiki, forums and general googling around have produced the following set of rules:

# automounts usb hdd and pendrives as usbhd-sdx; no messing around with
# volume labels or other confusing stuff

# matches all sdx devices except the internal hdd, sda
KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule"

# imports filesystem information
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"

# creates mount points and sets up symlinks
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/ln -s /media/usbhd-%k /mnt/usbhd-%k"

# global mount options
ACTION=="add", ENV{mount_options}="relatime"

# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"

# automount ntfs filesystem with ntfs-3g driver
ACTION=="add", KERNEL=="sd[b-z][0-9]", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k /media/usbhd-%k", OPTIONS="last_r$

# automount all other file systems
ACTION=="add", KERNEL=="sd[b-z][0-9]", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k /media/usbhd-%k", OPTIONS="last_rule"

# unmounts and removes the mount points
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd-%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /media/usbhd-%k", OPTIONS="last_rule"

This seemed to be working very well unitl I tried to boot this morning and the boot process stopped at "processing UDev events" with the following message:

iTCO_wdt: Unexpected close, not stopping watchdog!

It pauses at this point for 10-15 seconds and then reboots.

Having searched a bit, I found the following similar post on the forums:  http://bbs.archlinux.org/viewtopic.php?pid=459375

Which suggests that the problem might lie with this line:

ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"

I have renamed the file so that it no longer has the udev .rules extension and now the system boots fine.  Does anyone have any suggestions as to why the above rules might be causing this behaviour and how I might go about fixing it?

Thanks

Last edited by useradded (2010-07-02 22:58:14)

Offline

#2 2010-07-02 12:04:40

useradded
Member
From: Edinburgh, UK
Registered: 2010-05-15
Posts: 77

Re: [SOLVED]system fails to boot since adding udev rules for automounting

Update:

It seems that however I try to include a call to /sbin/blkid in my udev rules I end up with the same problem


I have tried all these variations:

IMPORT{program}="/sbin/blkid -o udev -p %N"

IMPORT{program}="/sbin/blkid -o udev -p $tempnode"

IMPORT{program}="/sbin/blkid -o udev $tempnode"

ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"

I have also tried accessing blkid differently

ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %N", ENV{fs_type}="%c"

All with the same result as described above:

iTCO_wdt: Unexpected close, not stopping watchdog!

Hanging and then rebooting.


If the line referencing /sbin/blkid is commented out then the system boots fine.

I want my rules to take account of different filesystems, but when I use blkid to do this my system won't boot.

Offline

#3 2010-07-02 15:35:29

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED]system fails to boot since adding udev rules for automounting

At least part of your rule is running for every device, not just events coming from sdxy devices.

The typical method of avoiding this is to do something like:

KERNEL!="sd[b-z][0-9]", GOTO="removeable_media_auto_mount_end"
...
...
more code...
...
...
LABEL="removeable_media_auto_mount_end"

This way, you're sure that the actual body of the rule only executes when udev is parsing events from a valid block device. Note that your goto needs to be very specific, as all udev rules exist in the same namespace.

Offline

#4 2010-07-02 22:56:35

useradded
Member
From: Edinburgh, UK
Registered: 2010-05-15
Posts: 77

Re: [SOLVED]system fails to boot since adding udev rules for automounting

Hey falconindy

That was the final kick up the logical a$$ that I needed to get some kind of grip on udev rules.  I now have a fully functional rule that applies only to /dev/sdxy and not to everything else as well, so no more boot trauma, THANK YOU.


I will mark this thread as solved and post my new rule for the benefit of anyone who might read this.

New rule (no boot problems):

# automounts usb hdd and pendrives as label or as usbhd-sdxy if no label present


# ensures the following is _only_ run for sdxy devices excluding internal hdd, sda
KERNEL!="sd[b-z][0-9]", GOTO="personal_usb_automount_settings_end"

# imports filesystem information
# provides access to following variables:
# ID_FS_UUID; ID_FS_UUID_ENC; ID_FS_VERSION; ID_FS_TYPE; ID_FS_VERSION; ID_FS_LABEL
# accessible via ENV{variable}; $env{variable}|%E{variable}

IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise name usbhd-%k
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# creates mount points and sets up symlinks
ACTION=="add", SYMLINK+="%E{dir_name}", GROUP="users", NAME="%k"
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}"
ACTION=="add", RUN+="/bin/ln -s /media/%E{dir_name} /mnt/%E{dir_name}"

# global mount options
ACTION=="add", ENV{mount_options}="relatime"

# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"

# automount ntfs filesystem with ntfs-3g driver
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k /media/%E{dir_name}", OPTIONS="last_rule"

# automount all other file systems
ACTION=="add",ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k /media/%E{dir_name}", OPTIONS="last_rule"

# unmounts and removes the mount points
ACTION=="remove", RUN+="/bin/rm -f /mnt/%E{dir_name}"
ACTION=="remove", RUN+="/bin/umount -l /media/%E{dir_name}"
ACTION=="remove", RUN+="/bin/rmdir /media/%E{dir_name}", OPTIONS="last_rule"

# exit
LABEL=="personal_usb_automount_settings_end"

Last edited by useradded (2010-07-02 22:59:20)

Offline

Board footer

Powered by FluxBB