You are not logged in.

#1 2012-03-04 17:27:49

kyku
Member
Registered: 2006-02-07
Posts: 24

Assign a group to removable devices.

How do I assign a custom group to newly created usb storage devices in /dev directory? I noticed they are added to "disk" group by default, but I'd like to have them in a different group than non-removable hard disks.

Offline

#2 2012-03-04 17:37:11

JuseBox
Member
Registered: 2009-11-27
Posts: 260

Re: Assign a group to removable devices.


Linux ArchLinux 3.2.8-1-ARCH
#1 SMP PREEMPT Mon Feb 27 21:51:46 CET 2012 x86_64 AMD FX(tm)-8120 Eight-Core Processor AuthenticAMD GNU/Linux
8192MB DDR3 1300MHz | Asus m5a97 | GeForce GTX 550 Ti | 120 GB SSD

Offline

#3 2012-03-04 18:26:51

kyku
Member
Registered: 2006-02-07
Posts: 24

Re: Assign a group to removable devices.

Ok, so I created the file /etc/udev/rules.d/00.rules with the following contents:

SUBSYSTEM=="usb", KERNEL=="sd*", NAME="%k", GROUP="removable"

Then I told udev to reload it's rules with "udevadm control --reload-rules" and plugged in the pendrive. The files /dev/sdb* were not assigned to the 'removable' group, though.

Offline

#4 2012-03-04 19:01:01

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,143

Re: Assign a group to removable devices.

Did you create the group removable?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#5 2012-03-04 19:16:06

kyku
Member
Registered: 2006-02-07
Posts: 24

Re: Assign a group to removable devices.

cfr wrote:

Did you create the group removable?

Yes

Offline

#6 2012-03-04 22:02:39

kyku
Member
Registered: 2006-02-07
Posts: 24

Re: Assign a group to removable devices.

Ok, I managed to do it the following way. First of all I created file /etc/udev/rules.d/xx.rules (it looks like the rules are loaded and applied in alphabetical order, so I added this as the last one to override system defaults). The file contents is as follows:

ENV{ID_USB_DRIVER}="usb-storage", KERNEL=="sd*", GROUP="removable"

I used ENV{ID_USB_DRIVER} instead of SUBSYSTEM=="usb", because the latter didn't work.  Now some testing with:

$ sudo udevadm test $(udevadm info --query=path --name=/dev/sdb)
...
udev_rules_apply_to_event: GROUP 6 /lib/udev/rules.d/50-udev-default.rules:67
....
udev_rules_apply_to_event: GROUP 1000 /etc/udev/rules.d/xx.rules:1

6 is the id of arch's default disk group, 1000 of my new removable group. Voila...

All of the above was infered rather from experimenting than RTFMing so I you can do it better, please leave a comment.

Offline

Board footer

Powered by FluxBB