0

I am using Debian Buster, 10.7, and I am relatively new to udev/udisks2/systemd and have been making a effort to get to know them better and have learned quite a lot, though I cannot seem to figure out how to both prevent udisks2 from auto mounting a particular volume (an SD card) as /media/$USER/foo, as well as mount it instead as /data.

Here is what I have tried so far:

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

Here is what I see syslog in another terminal window, when the card is inserted (though after logging in to 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

It looks like it mounts to /data but gets unmounted for some reason.

Here is the out of 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: 

Might I be missing something? Is there a better approach to this? I have tried to research this topic before and while trying to get this to work, and I really do't understand why this isn't working.

1 Answer 1

0

Systemd's .mount units (at least ones which originate from fstab) are device-bound. If udev says the device isn't available, systemd will deactivate the mount.

But...the device is marked as available after udev rule processing (because those rules may often have something to do with making it available). So by definition, the device will always be unavailable to systemd when you try to use it from RUN during "add" rule processing. Instead you want ENV{SYSTEMD_WANTS}.

Is there a better approach to this?

Just create a normal fstab entry. Udisks2 will recognize it and will mount the disk at the location specified in fstab.

(You may need to specify the source as UUID=3537-3761 to appease Udisks' fstab parser.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .