使用 udev 自动挂载

使用 udev 自动挂载

目前我选择的发行版(ArchLinux)有一个这样的自动挂载脚本:

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

但这只会自动挂载最高到 sdX9 的分区。我的 USB 驱动器确实有 6 个或更多分区(即从 5 开始,一直到 12、13、19)。

所有分区都有 VFAT 并带有标签(标签用于命名挂载点)。

我尝试将其修改为:

KERNEL!="sd[a-z][0-9]+", GOTO="media_by_label_auto_mount_end"

但那不起作用。

那么如何使其同样适用于 sdb5、sdb42 或 sdb31337?

谢谢。

附录

我刚刚尝试了这个\d+?方法,udevadm monitor 说:

KERNEL[1295719513.473653] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb (block)
KERNEL[1295719513.473687] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb1 (block)
KERNEL[1295719513.473706] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb5 (block)
KERNEL[1295719513.473725] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb6 (block)
KERNEL[1295719513.473743] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb7 (block)
KERNEL[1295719513.473761] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb8 (block)
KERNEL[1295719513.473791] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb9 (block)
KERNEL[1295719513.473811] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb10 (block)
KERNEL[1295719513.473830] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb11 (block)
KERNEL[1295719513.473848] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb12 (block)

UDEV  [1295719513.593213] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb (block)
UDEV  [1295719514.959983] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb5 (block)
UDEV  [1295719514.960053] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb1 (block)
UDEV  [1295719514.961528] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb6 (block)
UDEV  [1295719514.963793] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb9 (block)
UDEV  [1295719514.964930] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb10 (block)
UDEV  [1295719514.965794] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb12 (block)
UDEV  [1295719514.967418] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb8 (block)
UDEV  [1295719514.968466] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb7 (block)
UDEV  [1295719514.973757] add      /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host29/target29:0:0/29:0:0:0/block/sdb/sdb11 (block)

但这也不起作用。如果我保留默认规则,sdb5-9 就会正确挂载。

答案1

KERNEL!="sd[a-z]\d+?", GOTO="media_by_label_auto_mount_end"

相关内容