You are not logged in.

#1 2012-10-04 17:24:49

steelneck
Member
Registered: 2011-08-26
Posts: 57

Huge udev problem

A while ago i dicovered 7 folders under /media that started with usbhd-(devname), i did not investigate them further since i blamed my self. My udev usb-automount rule creates folder named like that. I sometimes forget usb-sticks plugged in when i turn off and then the folder do not get deleted. So i su to root and started to delete what i thought was leftover folders. Suddenly rm took some time and i suspected something was wrong, hit ctrl+c and started to investigate..

Now i got really scared the folder names under /media was usbhd-sda1, usbhd-sda2 and so on, a big chunk of unease crept over me, took a peak if there was someting in the folder usbhd-sda1.. it was my root system! (of course with that name). Though it did seem to be unharmed. Looked under the usbhd-sda2 where i have my old backup Slackware 10 system, the only thing left was some parts of /usr.. What on earth has happened, have i just wiped a whole system by mistake?

My first thing to sheck, still in shock, was ls -al /media just to see if there was any symlinks, no just real folders. When the first shock settled a bit i remembered that usbhd- name, and started to suspect my old udev rule. Typed mount, and yes, all my harddrives had been mounted under /media (normally only a pair of them is mounted by fstab under /mnt). Investigated my running system a bit more to see if i dare to even shut it down, i could not find anything missing.

So i rebooted and tried to start my old Slack system from Grub, of course that did not work. Booted Arch again, it went fine, ls /media and all drives was mounted there again. Now i removed my old udev-rule and rebooted again. The folders where still there but was empty with nothing mounted under them.

So, what change in the system can be reason that my old rule below started to mount my harddrives under /media? My rule has been working for a long time without change, so the culprit must be fund in some recent change.

The rule in question is about the same as the one that earlier could be found in the arch wiki, it is not there anymore.

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

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

# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,shortname=lower,gid=100,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"

Last edited by steelneck (2012-06-12 02:11:18)

Offline

#2 2012-10-04 17:53:47

steelneck
Member
Registered: 2011-08-26
Posts: 57

Re: Huge udev problem

Update.
I also have Arch on one old laptop, both these systems where -Syu two days ago. I have that udev-rule on my laptop too and in that machine the rule works just as it should, no harddrives get mounted under /media there, only what i plug in the usb.

Offline

#3 2012-10-04 19:26:12

aesiris
Member
Registered: 2012-02-25
Posts: 95

Re: Huge udev problem

First of all why did you "rm -rf" instead of the safer "rmdir"?

And why do you expect those rules not to apply to sda?

KERNEL!="sd[a-z][0-9]", GOTO="..."

means go on (=mkdir+mount) even for sda

Offline

#4 2012-10-04 19:39:05

steelneck
Member
Registered: 2011-08-26
Posts: 57

Re: Huge udev problem

Beacause none of my hd partitions are vfat or ntfs, and if you read my update in the second post, you can see that this rule works on my laptop and the two prtitions i have on sda on that machine do not get mounted by this rule, i also wrote that i have used this rule for a long time, infact at least a couple of years, working perfectly.

Something has gone wrong after the latest updates. The system on the faulty machine is about two years old (of course updated), but the old laptop has a clean install just a month old. So i suspect some old things laying around, but what?

Last edited by steelneck (2012-10-04 19:42:38)

Offline

#5 2012-10-04 20:02:03

aesiris
Member
Registered: 2012-02-25
Posts: 95

Re: Huge udev problem

steelneck wrote:

Beacause none of my hd partitions are vfat or ntfs [...]

I don't think that's true, each line is a applied irrespective of the previous ones (see for example http://www.reactivated.net/writing_udev … html#files), so

ACTION=="add", RUN+="/bin/mkdir -p...

will be run for any kind of device

Offline

#6 2012-10-05 13:17:51

steelneck
Member
Registered: 2011-08-26
Posts: 57

Re: Huge udev problem

Well the rule has ben working properly for two years, but this week it suddenly started to behave differently. So if you want to be rude and call me a liar, please do, but it wont be helpful.

Offline

#7 2012-10-05 16:30:21

bgc1954
Member
From: Edmonton, AB, Canada
Registered: 2006-03-14
Posts: 1,124

Re: Huge udev problem

@steelneck:
You're right, something is different.  I was having the same problem on my netbook using the same udev rule as you've posted.  I was noticing it was mounting my other linux partitions under /media/usbhd-sda5, /media/usbhd-sda6, etc. and trying to mount my windows 7 partitions /media/RECOVERY, /media/SYSTEM and throwing errors about the windows partitions.  I stumbled on your thread searching for an answer.  And you're right, the automount udev rule seems to be missing from the wiki now.  It turns out my desktop has a similair rule but the first couple of lines are

# Start at sdb to avoid system harddrive.
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"

The rest of the rule is the same.  So I changed my netbook to the same as my desktop and now it doesn't mount all my hdd partitons and I was able to delete the names in my /media folder as they were empty after a reboot.  But now I have other problems as my syslinux bootloader isn't working after I deleted the empty folders in /media. sad Oh well something to do this morning.


Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz

Offline

#8 2012-10-05 17:59:15

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,079

Re: Huge udev problem

udev rules should probably not be used for auto-mounting. Try udisks and a helper like devmon

@bgc1954, I guess it was removed from the wiki for the same reason because there were many other threads indicating problems with using udev rules for auto-mounting.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#9 2012-10-05 20:09:54

tomegun
Developer
From: France
Registered: 2010-05-28
Posts: 661

Re: Huge udev problem

@steelneck: I don't know why the behavior changed, but reading the rules it seems that the current behavior you are describing is the correct one. I.e., it essentially does:

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"

which means that it should mount all filesystems, not only removable media.

On a related note, it is really discouraged to use udev for this purpose (for instance the "cleanup" logic in that file does not work as it is trying to unmount the fs after the device has already been removed). Use udisks or something similar instead.

Ninja edit: it could be that earlier what is now /dev/sda was called /dev/hda (which means it would not be affected by this rule), but that would have changed a long time ago.

Last edited by tomegun (2012-10-05 20:15:51)

Offline

#10 2012-10-06 00:55:22

steelneck
Member
Registered: 2011-08-26
Posts: 57

Re: Huge udev problem

Any suggestions how to hit both sd[a-z][0-9] and something with usb in it?

A really ugly hack that just popped my mind would be to just cp this rule in place from rc.local, that way there is no add-event for the HDs since they are already mounted, i do that now until i have time to come up with something better.

Offline

#11 2012-10-06 01:14:41

steelneck
Member
Registered: 2011-08-26
Posts: 57

Re: Huge udev problem

steelneck wrote:

.. cp this rule in place from rc.local

Reply to self.
That did the trick, for now. And of course, i did put a corresponding rm in rc.local.shutdown too.

Offline

Board footer

Powered by FluxBB