在 Debian Buster 下,使用特定卷的自定义固定挂载点覆盖 udisks2 /media/$USER/mount

在 Debian Buster 下,使用特定卷的自定义固定挂载点覆盖 udisks2 /media/$USER/mount

我在用Debian 破坏者、10.7,我对 udev/udisks2/systemd 比较陌生,一直在努力去了解它们,也学到了很多东西,不过我似乎无法弄清楚如何既能防止 udisks2 自动将特定卷(SD 卡)安装为/media/$USER/foo,又能将其安装为/data

以下是我迄今为止尝试过的:

$ grep /data /etc/fstab
UUID="3537-3761"      /data     exfat-fuse    defaults,nofail,x-systemd.device-timeout=2ms  0       0

$ cat /etc/systemd/system/data-sdcard-mount.service   
[Unit]
Description=Mount Data SD Card on /data
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/mount /data
ExecStop=/bin/umount /data

$ cat /etc/udev/rules.d/99-data-sdcard.rules
ACTION=="add", \
    SUBSYSTEM=="block", \
    ENV{DEVTYPE}=="partition", \
    ENV{ID_DRIVE_MEDIA_FLASH_SD}=="1", \
    ENV{ID_NAME}=="SF256", \
    ENV{ID_SERIAL}=="0x3db0a775", \
    RUN+="/bin/systemctl start data-sdcard-mount", \
    ENV{UDISKS_IGNORE}="1", \
    OPTIONS="last_rule"

ACTION=="remove", \
    SUBSYSTEM=="block", \
    ENV{DEVTYPE}=="partition", \
    ENV{ID_DRIVE_MEDIA_FLASH_SD}=="1", \
    ENV{ID_NAME}=="SF256", \
    ENV{ID_SERIAL}=="0x3db0a775", \
    RUN+="/bin/systemctl stop data-sdcard-mount", \
    OPTIONS="last_rule"

这是我在插入卡后(尽管登录到 MATE 后)在另一个终端窗口中看到的系统日志:

Feb  4 13:25:51 localhost kernel: [508706.027711] mmc3: new high speed SDXC card at address aaaa
Feb  4 13:25:51 localhost kernel: [508706.044472] mmcblk3: mmc3:aaaa SF256 238 GiB 
Feb  4 13:25:51 localhost kernel: [508706.058372]  mmcblk3: p1
Feb  4 13:25:51 localhost systemd[1]: Starting Mount Data SD Card on /data...
Feb  4 13:25:51 localhost mount[1734]: FUSE exfat 1.3.0
Feb  4 13:25:51 localhost mount[1734]: WARN: volume was not unmounted cleanly.
Feb  4 13:25:51 localhost mount.exfat-fuse: volume was not unmounted cleanly
Feb  4 13:25:51 localhost systemd[1]: data.mount: Unit is bound to inactive unit dev-disk-by\x2duuid-3537\x2d3761.device. Stopping, too.
Feb  4 13:25:51 localhost systemd[1]: Started Mount Data SD Card on /data.
Feb  4 13:25:51 localhost systemd[1]: Unmounting /data...
Feb  4 13:25:51 localhost systemd[14720]: data.mount: Succeeded.
Feb  4 13:25:51 localhost systemd[2920]: data.mount: Succeeded.
Feb  4 13:25:51 localhost systemd[1]: data.mount: Succeeded.
Feb  4 13:25:51 localhost systemd[1]: Unmounted /data.
Feb  4 13:25:52 localhost systemd[1]: Started Clean the /media/vanfan/Data mount point.
Feb  4 13:25:52 localhost udisksd[2010]: Mounted /dev/mmcblk3p1 at /media/vanfan/Data on behalf of uid 1000

它看起来像是安装到/data 但由于某种原因而被卸载。

以下是udisksctl info -b /dev/mmcblk3p1

$ udisksctl info -b /dev/mmcblk3p1
/org/freedesktop/UDisks2/block_devices/mmcblk3p1:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/mmcblk3p1
    DeviceNumber:               45825
    Drive:                      '/org/freedesktop/UDisks2/drives/SF256_0x3db0a775'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 false
    Id:                         by-uuid-3537-3761
    IdLabel:                    Data
    IdType:                     exfat
    IdUUID:                     3537-3761
    IdUsage:                    filesystem
    IdVersion:                  1.0
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/mmcblk3p1
    ReadOnly:                   false
    Size:                       255835766784
    Symlinks:                   /dev/disk/by-id/mmc-SF256_0x3db0a775-part1
                                /dev/disk/by-label/Data
                                /dev/disk/by-path/platform-4809c000.mmc-part1
                                /dev/disk/by-uuid/3537-3761
    UserspaceMountOptions:      uhelper=udisks2
  org.freedesktop.UDisks2.Filesystem:
    MountPoints:        /media/vanfan/Data
    Size:               0
  org.freedesktop.UDisks2.Partition:
    Flags:              0
    IsContained:        false
    IsContainer:        false
    Name:               
    Number:             1
    Offset:             33554432
    Size:               255835766784
    Table:              '/org/freedesktop/UDisks2/block_devices/mmcblk3'
    Type:               0x07
    UUID: 

我可能遗漏了什么吗? 有没有更好的方法? 我之前和尝试让它工作时都曾尝试研究过这个主题,但我真的不明白为什么它不起作用。

答案1

Systemd 的 .mount 单元(至少源自 fstab 的单元)是设备绑定的。如果 udev 表示设备不可用,systemd 将停用挂载。

但是...该设备被标记为可用udev 规则处理(因为这些规则可能经常与使其可用有关)。因此根据定义,设备将总是在“添加”规则处理期间尝试使用它时,systemd 将无法使用RUN。相反,您需要ENV{SYSTEMD_WANTS}

有没有更好的方法呢?

只需创建一个正常的 fstab 条目。Udisks2将要识别它并将磁盘安装在 fstab 中指定的位置。

(您可能需要指定源以UUID=3537-3761安抚 Udisks 的 fstab 解析器。)

相关内容