udev rules not working

raj

Active Member
Sep 17, 2011
217
4
38
www.businessparksolutions.com
Hi team,

I run a weekly backup to a usb HDD and used to mount it with a udev rule.

Since I updated from proxmox 4.4 to 5, the rule is not working anymore. Could anyone advise please?

Here is the rule:

11-media-by-label-auto-mount.rules

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,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"



The error in the log is :


Jul 16 19:54:01 master systemd[1]: Started Proxmox VE replication runner.
Jul 16 19:54:25 master kernel: [200141.520135] usb 1-8: USB disconnect, device number 10
Jul 16 19:54:25 master kernel: [200141.520588] blk_update_request: I/O error, dev sdc, sector 0
Jul 16 19:54:25 master kernel: [200141.523019] sd 4:0:0:0: [sdc] Synchronizing SCSI cache
Jul 16 19:54:25 master kernel: [200141.572037] blk_update_request: I/O error, dev sdc, sector 0
Jul 16 19:54:25 master kernel: [200141.581810] VFS: Dirty inode writeback failed for block device sdc1 (err=-5).
Jul 16 19:54:25 master systemd-udevd[12049]: Process '/bin/rmdir /media//offsite' failed with exit code 1.
Jul 16 19:54:25 master kernel: [200141.756074] sd 4:0:0:0: [sdc] Synchronize Cache(10) failed: Result: hostbyte=DID_ERROR driverbyte=DRIVER_OK
Jul 16 19:54:29 master kernel: [200145.196083] usb 1-8: new high-speed USB device number 11 using ehci-pci
Jul 16 19:54:29 master kernel: [200145.346037] usb 1-8: New USB device found, idVendor=0bc2, idProduct=ab28
Jul 16 19:54:29 master kernel: [200145.346041] usb 1-8: New USB device strings: Mfr=2, Product=3, SerialNumber=1
Jul 16 19:54:29 master kernel: [200145.346043] usb 1-8: Product: BUP BK
Jul 16 19:54:29 master kernel: [200145.346044] usb 1-8: Manufacturer: Seagate
Jul 16 19:54:29 master kernel: [200145.346046] usb 1-8: SerialNumber: NA7P3ZXV
Jul 16 19:54:29 master kernel: [200145.347089] scsi host4: uas
Jul 16 19:54:29 master kernel: [200145.348907] scsi 4:0:0:0: Direct-Access Seagate BUP BK 0304 PQ: 0 ANSI: 6
Jul 16 19:54:29 master kernel: [200145.404998] sd 4:0:0:0: Attached scsi generic sg4 type 0
Jul 16 19:54:29 master kernel: [200145.405517] sd 4:0:0:0: [sdc] Spinning up disk...
Jul 16 19:54:31 master kernel: [200146.428032] .
Jul 16 19:54:32 master kernel: [200147.452036] .
Jul 16 19:54:33 master kernel: [200148.476035] .
Jul 16 19:54:34 master kernel: [200149.500103] .
Jul 16 19:54:35 master kernel: [200150.524095] .
Jul 16 19:54:35 master kernel: [200151.548027] .
Jul 16 19:54:35 master kernel: [200151.548202] ready
Jul 16 19:54:35 master kernel: [200151.549428] sd 4:0:0:0: [sdc] 7814037167 512-byte logical blocks: (4.00 TB/3.64 TiB)
Jul 16 19:54:35 master kernel: [200151.549430] sd 4:0:0:0: [sdc] 2048-byte physical blocks
Jul 16 19:54:35 master kernel: [200151.663983] sd 4:0:0:0: [sdc] Write Protect is off
Jul 16 19:54:35 master kernel: [200151.663987] sd 4:0:0:0: [sdc] Mode Sense: 4f 00 00 00
Jul 16 19:54:35 master kernel: [200151.665061] sd 4:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Jul 16 19:54:35 master kernel: [200151.834113] sdc: sdc1
Jul 16 19:54:35 master kernel: [200151.838185] sd 4:0:0:0: [sdc] Attached SCSI disk
Jul 16 19:54:36 master kernel: [200152.808746] EXT4-fs (sdc1): recovery complete
Jul 16 19:54:36 master kernel: [200152.808753] EXT4-fs (sdc1): mounted filesystem with ordered data mode. Opts: (null)
Jul 16 19:55:00 master systemd[1]: Starting Proxmox VE replication runner...


Rajbps
 
Hi team,

I run a weekly backup to a usb HDD and used to mount it with a udev rule.

Since I updated from proxmox 4.4 to 5, the rule is not working anymore. Could anyone advise please?

Here is the rule:

11-media-by-label-auto-mount.rules

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,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"



The error in the log is :


Jul 16 19:54:01 master systemd[1]: Started Proxmox VE replication runner.
Jul 16 19:54:25 master kernel: [200141.520135] usb 1-8: USB disconnect, device number 10
Jul 16 19:54:25 master kernel: [200141.520588] blk_update_request: I/O error, dev sdc, sector 0
Jul 16 19:54:25 master kernel: [200141.523019] sd 4:0:0:0: [sdc] Synchronizing SCSI cache
Jul 16 19:54:25 master kernel: [200141.572037] blk_update_request: I/O error, dev sdc, sector 0
Jul 16 19:54:25 master kernel: [200141.581810] VFS: Dirty inode writeback failed for block device sdc1 (err=-5).
Jul 16 19:54:25 master systemd-udevd[12049]: Process '/bin/rmdir /media//offsite' failed with exit code 1.
Jul 16 19:54:25 master kernel: [200141.756074] sd 4:0:0:0: [sdc] Synchronize Cache(10) failed: Result: hostbyte=DID_ERROR driverbyte=DRIVER_OK
Jul 16 19:54:29 master kernel: [200145.196083] usb 1-8: new high-speed USB device number 11 using ehci-pci
Jul 16 19:54:29 master kernel: [200145.346037] usb 1-8: New USB device found, idVendor=0bc2, idProduct=ab28
Jul 16 19:54:29 master kernel: [200145.346041] usb 1-8: New USB device strings: Mfr=2, Product=3, SerialNumber=1
Jul 16 19:54:29 master kernel: [200145.346043] usb 1-8: Product: BUP BK
Jul 16 19:54:29 master kernel: [200145.346044] usb 1-8: Manufacturer: Seagate
Jul 16 19:54:29 master kernel: [200145.346046] usb 1-8: SerialNumber: NA7P3ZXV
Jul 16 19:54:29 master kernel: [200145.347089] scsi host4: uas
Jul 16 19:54:29 master kernel: [200145.348907] scsi 4:0:0:0: Direct-Access Seagate BUP BK 0304 PQ: 0 ANSI: 6
Jul 16 19:54:29 master kernel: [200145.404998] sd 4:0:0:0: Attached scsi generic sg4 type 0
Jul 16 19:54:29 master kernel: [200145.405517] sd 4:0:0:0: [sdc] Spinning up disk...
Jul 16 19:54:31 master kernel: [200146.428032] .
Jul 16 19:54:32 master kernel: [200147.452036] .
Jul 16 19:54:33 master kernel: [200148.476035] .
Jul 16 19:54:34 master kernel: [200149.500103] .
Jul 16 19:54:35 master kernel: [200150.524095] .
Jul 16 19:54:35 master kernel: [200151.548027] .
Jul 16 19:54:35 master kernel: [200151.548202] ready
Jul 16 19:54:35 master kernel: [200151.549428] sd 4:0:0:0: [sdc] 7814037167 512-byte logical blocks: (4.00 TB/3.64 TiB)
Jul 16 19:54:35 master kernel: [200151.549430] sd 4:0:0:0: [sdc] 2048-byte physical blocks
Jul 16 19:54:35 master kernel: [200151.663983] sd 4:0:0:0: [sdc] Write Protect is off
Jul 16 19:54:35 master kernel: [200151.663987] sd 4:0:0:0: [sdc] Mode Sense: 4f 00 00 00
Jul 16 19:54:35 master kernel: [200151.665061] sd 4:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Jul 16 19:54:35 master kernel: [200151.834113] sdc: sdc1
Jul 16 19:54:35 master kernel: [200151.838185] sd 4:0:0:0: [sdc] Attached SCSI disk
Jul 16 19:54:36 master kernel: [200152.808746] EXT4-fs (sdc1): recovery complete
Jul 16 19:54:36 master kernel: [200152.808753] EXT4-fs (sdc1): mounted filesystem with ordered data mode. Opts: (null)
Jul 16 19:55:00 master systemd[1]: Starting Proxmox VE replication runner...


Rajbps

for me, too

has something changed in systemd?
 
Jul 16 19:54:25 master kernel: [200141.572037] blk_update_request: I/O error, dev sdc, sector 0
Jul 16 19:54:25 master kernel: [200141.581810] VFS: Dirty inode writeback failed for block device sdc1 (err=-5).
Jul 16 19:54:25 master systemd-udevd[12049]: Process '/bin/rmdir /media//offsite' failed with exit code 1.
Jul 16 19:54:25 master kernel: [200141.756074] sd 4:0:0:0: [sdc] Synchronize Cache(10) failed: Result: hostbyte=DID_ERROR driverbyte=DRIVER_OK

I can guess that yiur usb drive is almost broken - see the first line ... with sector 0
 
Is there any particular reason why you're using udev rules for this?
There are 2 other much more convenient choices which I'm writing down here since this has come up in a few other places as well already:

1) an fstab entry with x-systemd.automount

Since fstab entries can use UUID=, LABEL= and PARTLABEL= lines to mount by uuid/labels, this is much easier to manage.
Another big plus is that the automount method will cause errors if the device is not available, rather than data being written onto whatever partition the directory resides on.

2) a systemd.mount file

Doesn't need more than the usual fstab entry, and its automatic mounting can be systemctl en/disabled.
The only inconvenient part is that they need to be named after the mount point (with systemd's escaping in the name, eg. minus instead of slash, and \x2d instead of minus...
Eg.
Code:
# /etc/systemd/system/mnt-usb.mount
[Unit]
Description=Mount partition labeled StickL2

[Mount]
What=/dev/disk/by-label/StickL2
Where=/mnt/usb

[Install]
WantedBy=multi-user.target

This automatically implies a Requires= and BindsTo=dev-disk-by\x2dlabel-StickL2.device and once enabled via systemctl enable mnt-usb.mount, inserting the stick with that partition will automatically mount it.
 
  • Like
Reactions: Symbol and guletz

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!