1

I have a USB device, formatted FAT32 (for the widest possible compatibility), plugged into a system running CentOS 5 (yes, I know it's antiquated).

The whole purpose of its being plugged in is to receive backup files sent from two other systems.

But because (apparently) of UDEV default behavior, it mounts (along with its subdirectories) as "drwxr-xr-x 5 root root," refusing to accept anything sent to it, and refusing any "chown" (with an error message) or "chmod" (quietly failing).

Is there a way to change the default mounting behavior for USB FAT32 devices? I will note that /etc/udev/rules.d on this box contains:

05-udev-early.rules 60-pcmcia.rules 90-alsa.rules 40-multipath.rules 60-raw.rules 90-dm.rules 50-udev.rules 60-wacom.rules 90-hal.rules 51-hotplug.rules 61-uinput-stddev.rules 95-pam-console.rules 60-libsane.rules 61-uinput-wacom.rules 98-kexec.rules 60-net.rules 85-pcscd_ccid.rules bluetooth.rules 

Note that the object here is to specifically avoid having to explicitly mount the bloody thing (and to not have to add a new fstab entry every time we plug in a different device)!

I've found "udevmonitor" (no "udevadm"), and when I plug the device in:

UEVENT[1618003563.847325] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5 UEVENT[1618003563.847392] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/usbdev1.4_ep00 UEVENT[1618003563.849089] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0 UEVENT[1618003563.849130] add@/class/scsi_host/host4 UEVENT[1618003563.849155] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/usbdev1.4_ep8b UEVENT[1618003563.849180] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/usbdev1.4_ep0a UEVENT[1618003563.849203] add@/class/usb_device/usbdev1.4 UDEV [1618003563.850150] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5 UDEV [1618003564.062789] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/usbdev1.4_ep00 UDEV [1618003564.186813] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0 UDEV [1618003564.298705] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/usbdev1.4_ep8b UDEV [1618003564.298769] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/usbdev1.4_ep0a UDEV [1618003564.308695] add@/class/scsi_host/host4 UDEV [1618003564.614084] add@/class/usb_device/usbdev1.4 UEVENT[1618003569.124366] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/host4/target4:0:0/4:0:0:0 UEVENT[1618003569.124416] add@/class/scsi_disk/4:0:0:0 UEVENT[1618003569.179432] add@/block/sda UEVENT[1618003569.179466] add@/block/sda/sda1 UEVENT[1618003569.179485] add@/block/sda/sda2 UEVENT[1618003569.179508] add@/class/scsi_device/4:0:0:0 UEVENT[1618003569.179612] add@/class/scsi_generic/sg0 UDEV [1618003569.290405] add@/devices/pci0000:00/0000:00:1d.7/usb1/1-5/1-5:1.0/host4/target4:0:0/4:0:0:0 UDEV [1618003569.423752] add@/class/scsi_generic/sg0 UDEV [1618003569.423806] add@/class/scsi_disk/4:0:0:0 UDEV [1618003569.474344] add@/class/scsi_device/4:0:0:0 UDEV [1618003569.505476] add@/block/sda UDEV [1618003569.861895] add@/block/sda/sda1 UDEV [1618003569.919434] add@/block/sda/sda2 UEVENT[1618003570.253329] mount@/block/sda/sda2 UDEV [1618003570.254399] mount@/block/sda/sda2 

A udevinfo -p /block/sda/sda2 -q all gives me:

P: /block/sda/sda2 N: sda2 S: disk/by-id/usb-Seagate_BUP_Slim_BK_NA7LFNNT-part2 S: disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0-part2 S: disk/by-uuid/6D63-17F2 S: disk/by-label/BACKUP E: ID_VENDOR=Seagate E: ID_MODEL=BUP_Slim_BK E: ID_REVISION=0143 E: ID_SERIAL=Seagate_BUP_Slim_BK_NA7LFNNT E: ID_TYPE=disk E: ID_BUS=usb E: ID_PATH=pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0 E: ID_FS_USAGE=filesystem E: ID_FS_TYPE=vfat E: ID_FS_VERSION=FAT32 E: ID_FS_UUID=6D63-17F2 E: ID_FS_LABEL=BACKUP E: ID_FS_LABEL_SAFE=BACKUP 

and a udevinfo -p /block/sda2 -1 gives me:

 looking at device '/block/sda/sda2': KERNEL=="sda2" SUBSYSTEM=="block" SYSFS{stat}==" 38 329 661 163 1 1 2 4 0 139 167" SYSFS{size}=="1952849920" SYSFS{start}=="411648" SYSFS{dev}=="8:2" looking at parent device '/block/sda': ID=="sda" BUS=="block" DRIVER=="" SYSFS{stat}==" 112 1237 1811 361 1 1 2 4 0 241 365" SYSFS{size}=="1953525167" SYSFS{removable}=="0" SYSFS{range}=="16" SYSFS{dev}=="8:0" . . . 

I tried going into /etc/udev/rules.d/50-udev.rules, and changing

# all block devices SUBSYSTEM=="block", GROUP="disk", MODE="0640" KERNEL=="root", GROUP="disk", MODE="0640" 

to

# all block devices SUBSYSTEM=="block", GROUP="disk", MODE="0660" KERNEL=="root", GROUP="disk", MODE="0640" 

and rebooting; no effect

Further down I found this (AFTER "persistent_end"):

ACTION=="add", SUBSYSTEM=="usb_device", \ PROGRAM="/bin/sh -c 'K=%k; K=$${K#usbdev}; printf bus/usb/%%03i/%%03i $${K%%%%.*} $${K#*.}'", \ NAME="%c", MODE="0644" 

and tried changing 644 to 664; also no effect (and besides, the subsystem is supposed to be "block").

Is there someplace else I could put something to specify a MODE parameter that would open USB device access up?

I noticed the

UEVENT[1618003570.253329] mount@/block/sda/sda2 UDEV [1618003570.254399] mount@/block/sda/sda2 

at the bottom of the udevmonitor output. I note that a grep on "mount" doesn't find a single rule responding to a "mount" event. Is there something I could add, that would respond to this, either changing the mount parameters or remounting the device?

3 Answers 3

1

chown and chmod doesn't work as FAT doesn't implement them, but when mounting, you can specify umask to allow everybody to wite to it or uid to set owner of everything on the flashdrive. If you are talking about ability to mount it, you can add entry into /etc/fstab with appropriate options and users. I guess with CentOS 5, you don't have that many things connecting to the device to warrant anything more complex then static fstab.

4
  • Right, but how do either of those options affect how it automounts? The whole point is to avoid having to explicitly mount it every time it's plugged in. Commented Apr 9, 2021 at 20:54
  • If you add correct uid and umask options to whatever is automounting your flashdrive, it should help. Alternatively, you can easily mount it manually with users option in fstab. Depends how do you do the automounting and whether you really need it. Commented Apr 10, 2021 at 10:49
  • udev is almost certainly what's doing the automounting. And I've added all I could find so far about the details of that process to the question Commented Apr 10, 2021 at 16:00
  • udev by itself doesn't do any auto-mounting, it just creates/manages devices. You can add RUN option to mount, but most likely it is something else that handles automounting for you, either autofs, udisk or something even older. But there is a chance that if you add a static entry into fstab with options, disk and directory where to mount it, those deamons might pick it up. Commented Apr 12, 2021 at 8:55
1

If you want to automount using udev you can add something like this to your udev rules:

# Symlinks SUBSYSTEM=="block", KERNEL=="sd?", ACTION=="add", PROGRAM="/etc/udev/scripts/isremovable.sh %k", RESULT=="YES", SYMLINK="usb_flash_raw", RUN+="/etc/udev/scripts/mount.sh %k" SUBSYSTEM=="block", KERNEL=="sd?[0-9]*", ACTION=="add", PROGRAM="/etc/udev/scripts/isremovable.sh %k", RESULT=="YES", SYMLINK="usb_flash_p%n", RUN+="/etc/udev/scripts/mount.sh %k" # umount SUBSYSTEM=="block", KERNEL=="sd?", ACTION=="remove", RUN+="/etc/udev/scripts/umount.sh > /dev/null 2> /dev/null" 

Where the is removable can be something like this:

#!/bin/sh DEV="`basename "$1" | sed 's|[0-9]*$||'`" if [ "`find /sys -name "$DEV" | grep usb`" ]; then echo "YES" exit 0 else echo "NO" exit 1 fi 

And the mount/umount scripts can be whatever you want, but be aware that handling safe unmounting is not easy.

0

I ultimately took a different approach.

I set up a cron job, running every five minutes, to transfer files uploaded to the backup users' home directories over to the USB drives, under root authority, and to keep them from transferring before the upload is complete, I have the upload client set up to send the files without an extension, then rename them to add the extension once the upload is complete.

Then I discovered that signing off the console unmounts the USB device. So much for using udev-based automounting.

So since the cron job's script was already present, I set up my own mountpoint, then added code to see if a properly set up USB device is present at the mountpoint, and if not, it attempts to mount the device.

Then I found the first pleasant surprise of this whole exercise: while mounting the device at my mountpoint keeps it from showing up under /media, it somehow does not stop Gnome from making it available on the desktop when I sign on.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.