What does these udev rules mean?

0

The following is taken from an embedded system which does not have hard drive in it.

KERNEL=="sd?", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", NAME="sda"
KERNEL=="sd?2", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", NAME="sda2" RUN+="/bin/mount -n -o sync /dev/sda2 /media/usb2"
KERNEL=="sda2" ACTION=="remove", RUN+="/bin/umount -n /media/usb2"

Is it for auto mount and unmount? Can anyone provide brief explanation?

Thanks.

New to Rails

Posted 2013-11-25T06:12:46.137

Reputation: 113

Answers

1

This is for both mounting and unmounting, the clue is in the RUN+= command.

KERNEL=="sd?", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", NAME="sda"

# mounting
KERNEL=="sd?2", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", NAME="sda2" RUN+="/bin/mount -n -o sync /dev/sda2 /media/usb2"

# unmounting
KERNEL=="sda2" ACTION=="remove", RUN+="/bin/umount -n /media/usb2" 

Particularly for USB devices that get mapped to sda2. Usually your fixed drive gets mapped to the sda space, so this rule might not ever get triggered, unless it is on an embedded system without an internal drive or running in a live environment.

I see you tagged with embedded so this rule seems valid indeed.

invert

Posted 2013-11-25T06:12:46.137

Reputation: 4 918

Thanks invert. Could you please share what does the first line mean? – New to Rails – 2013-11-25T07:46:19.630

The first line will match like the rest of the rules, but there is no action associated with it. It is obviously added as a template for you to reuse in your own rules. For more on udev see http://reactivated.net/writing_udev_rules.html

– invert – 2013-11-26T13:44:43.993