I'm trying to set a particular USB drive to always mount read only. If I plug it in, it is seen as sdb
with a single partition, sdb1
. Here are some relevant udevadm
lines (not the entire output of course):
$ udevadm info -a -n /dev/sdb1
looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/host21/target21:0:0/21:0:0:0/block/sdb/sdb1':
KERNEL=="sdb1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="976768002"
ATTR{stat}==" 473 30586 33938 3460 5 0 40 1624 0 2268 5084"
ATTR{partition}=="1"
OK, so I wrote the following udev
rule and saved it as /etc/udev/rules.d/10-usbdisk.rules
:
SUBSYSTEM=="block",
ATTR{size}=="976768002",
MODE="0555"
According to this, using size
should be enough but I have also tried other permutations. In any case, the rule does seem to be read (again, selected output lines, you can see the entire output here:
$ udevadm test $(udevadm info -q path -n /dev/sdb1) 2>&1
[...]
read rules file: /etc/udev/rules.d/10-usbdisk.rules
[...]
MODE 0555 /etc/udev/rules.d/10-usbdisk.rules:4
So, it looks like the rule should be applied and it looks like the MODE="0555"
is the correct syntax. However, when I actually plug the disk in, I can happily create/delete files on it.
OS: Debian testing (LMDE)
So, what am I doing wrong? How can I mount a particular USB drive as read only automatically using udev1?
1 I know how to do this with fstab but fstab settings are ignored by gvfs. My objective is to have this mounted automatically as read only in the GUI. Presumably this will have to be done via udev or gvfs somehow.