Welcome to the Linux Foundation Forum!

Chapter 18 - Automatic Filesystem Mounting - doesn't work for me

I was trying to implement "Automatic Filesystem Mounting" using the systemd way. As mentioned in this chapter, in the past the autofs package did the job and I had used it several times without issues.

My host system: Manjaro
Kernel: 5.8.11-1-MANJARO
systemd: systemd 246 (246.6-1-manjaro)

My idea was to automount an external backup drive connected via USB. The filesystem on the backup drive is NTFS, since it backs up the photo collection on my Windows 10 VM. The NTFS driver I use is NTFS-3g which is the default nowadays:

  1. $ ls -lF /usr/bin/mount.ntfs*
  2. lrwxrwxrwx 1 root root 16 Aug 30 12:50 /usr/bin/mount.ntfs -> /usr/bin/ntfs-3g*
  3. lrwxrwxrwx 1 root root 16 Aug 30 12:50 /usr/bin/mount.ntfs-3g -> /usr/bin/ntfs-3g*

The mount options in my fstab before using the systemd approach are as follows:
/dev/disk/by-partlabel/wdbook /media/heiko/wdbook ntfs-3g noauto,rw,user,nls=utf8,uid=1000,gid=1000,dmask=027,fmask=137,nofail,windows_names,locale=en_US.utf8 0 0

which should translate into: noauto = don't mount at boot or with mount -a, rw = read-write access, user = let non-root user mount the filesystem, nls = enable utf8 character encoding, uid/gid = set the file ownership and group to myself (1000), dmask/fmask = mask the directory and file permissions (restrict access), nofail = don't cry if the drive isn't there, windows_names = prevent files, directories and extended attributes to be created with a name not allowed by windows, locale = set the locale (needed for sorting etc.), 0 0 = don't dump and don't fsck. I know it's a mouthful of options, but that worked fine so far.

If I comment out the line in fstab (no entry for the drive), the drive is shown in the file browser but not mounted. I can easily mount it via the file browser. I guess that's the default setting for this desktop OS.

However, the drive doesn't spin down and I was hoping that the systemd approach would allow me to spin down the disk when not in use. Here are the settings I used:

  1. /dev/disk/by-partlabel/wdbook /media/heiko/wdbook ntfs-3g noauto,x-systemd.automount,x-systemd.device-timeout=10,x-systemd.idle-timeout=60,rw,user,nls=utf8,uid=1000,gid=1000,dmask=027,fmask=137,nofail,windows_names,locale=en_US.utf8 0 0
  2.  

The timeout settings had absolutely no effect. By the way, I found the following website: https://www.golinuxcloud.com/automount-file-system-systemd-rhel-centos-7-8/

The article describes how to set up automount using systemd. It talks about first creating a .mount file for the drive, then a .automount config file to have it automounted. If I understand that correctly, the .mount file would be in lieu of the /etc/fstab entry?

I think this whole systemd approach is messing up my mind. What would be the right approach - using systemd - to have an external drive recognized and mounted "on demand", that is not automatically at boot. Also, the drive should spin down after a given idle time.

Thanks for looking into it.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 99

    I rechecked the setup. It turns out I had created a media-heiko-wdbook.mount file with the following content:

    1. # https://www.golinuxcloud.com/automount-file-system-systemd-rhel-centos-7-8/
    2.  
    3. [Unit]
    4. Description=Western Digital Book wdbook external drive
    5. DefaultDependencies=no
    6. Conflicts=umount.target
    7. Before=local-fs.target umount.target
    8. After=swap.target
    9.  
    10. [Mount]
    11. What=/dev/disk/by-partlabel/wdbook
    12. Where=/media/heiko/wdbook
    13. Type=ntfs-3g
    14. Options=noauto,rw,user,nls=utf8,uid=1000,gid=1000,dmask=027,fmask=137,nofail,windows_names,locale=en_US.utf8
    15.  
    16. [Install]
    17. WantedBy=multi-user.target
    18.  

    This mount option was enabled.

    When I stopped and disabled the mount service the drive does NOT auto-mount:

    1. $ systemctl status media-heiko-wdbook.mount
    2. media-heiko-wdbook.mount - Western Digital Book wdbook external drive
    3. Loaded: loaded (/etc/systemd/system/media-heiko-wdbook.mount; disabled; vendor preset: disabled)
    4. Active: inactive (dead)
    5. Where: /media/heiko/wdbook
    6. What: /dev/disk/by-partlabel/wdbook

    To check it:

    1. $ lsblk
    2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    3. sdf 8:80 0 3.6T 0 disk
    4. └─sdf1 8:81 0 3.6T 0 part

    or better:

    1. $ systemctl -t mount
    2. UNIT LOAD ACTIVE SUB DESCRIPTION
    3. -.mount loaded active mounted Root Mount
    4. boot-efi.mount loaded active mounted /boot/efi
    5. dev-hugepages.mount loaded active mounted /dev/hugepages
    6. dev-mqueue.mount loaded active mounted POSIX Message Queue File System
    7. home.mount loaded active mounted /home
    8. run-user-1000-gvfs.mount loaded active mounted /run/user/1000/gvfs
    9. run-user-1000.mount loaded active mounted /run/user/1000
    10. sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System
    11. sys-kernel-config.mount loaded active mounted Kernel Configuration File System
    12. sys-kernel-debug.mount loaded active mounted Kernel Debug File System
    13. sys-kernel-tracing.mount loaded active mounted Kernel Trace File System
    14. tmp.mount loaded active mounted Temporary Directory (/tmp)
    15.  

    It turns out thunar-volman was installed which handles removable drives automatically. Thunar is the file manager on XFCE Arch Linux (and Manjaro) and it's quite convenient.

    Below is a summary of tests I've done:

    1. No /etc/fstab entry, media-heiko-wdbook.mount disabled:

    Using the Thunar file manager I can manually mount/unmount the drive. However, the disk never spins down.

    1. /etc/fstab entry, media-heiko-wdbook.mount disabled:

    I can no more mount the volume via Thunar and get the following error:

    Here is the fstab entry:

    /dev/disk/by-partlabel/wdbook /media/heiko/wdbook ntfs-3g noauto,rw,user,nls=utf8,uid=1000,gid=1000,dmask=027,fmask=137,nofail,windows_names,locale=en_US.utf8 0 0

    Note the "user" option which should allow me to mount the drive.

    1. With fstab entry, media-heiko-wdbook.mount enabled and running:

    sudo systemctl enable media-heiko-wdbook.mount
    sudo systemctl start media-heiko-wdbook.mount

    The moment I enter systemctl start media...mount command the drive is mounted.

    I can unmount the drive using the Thunar file manager, but when I try to mount it again using Thunar, I get the error window shown above.

    Trying to remount the drive with root privileges works:

    1. $ sudo mount /media/heiko/wdbook/
    2. [heiko@woody ~]$ cat /proc/mounts | grep sdf1
    3. /dev/sdf1 /media/heiko/wdbook fuseblk rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0

    But trying to mount as regular user doesn't:

    1. $ mount /media/heiko/wdbook/
    2. Unprivileged user can not mount NTFS block devices using the external FUSE
    3. library. Either mount the volume as root, or rebuild NTFS-3G with integrated
    4. FUSE support and make it setuid root. Please see more information at
    5. http://tuxera.com/community/ntfs-3g-faq/#unprivileged
    1. No /etc/fstab entry, media-heiko-wdbook.mount enabled and running:

    I commented out the /etc/fstab entry and rebooted.

    The drive is automatically mounted under /media/heiko/wdbook:

    1. $ lsblk
    2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    3. sdf 8:80 0 3.6T 0 disk
    4. └─sdf1 8:81 0 3.6T 0 part /media/heiko/wdbook

    A look at /proc/mounts shows the mount options used:

    1. $ cat /proc/mounts | grep sdf1
    2. /dev/sdf1 /media/heiko/wdbook fuseblk rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0

    Seems like the only thing taken from media-heiko-wdbook.mount options is the mount point.

    I can unmount the drive using Thunar, and remount it again. This time, however, it mounts under a different folder:

    1. $ lsblk
    2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    3. sdf 8:80 0 3.6T 0 disk
    4. └─sdf1 8:81 0 3.6T 0 part /run/media/heiko/32BB56432280CBF1

    The Thunar volume mounter has disregarded both the mount point and the mount options specified in media-heiko-wdbook.mount:

    /proc/mounts reveals the following:

    1. $ cat /proc/mounts | grep sdf1
    2. /dev/sdf1 /run/media/heiko/32BB56432280CBF1 fuseblk rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0

    My conclusion and questions

    1. Some higher-level convenience tools don't play nicely with "low-level" configurations, overriding manual systemd and fstab configurations.
    2. The ntfs-3g driver complains about non-root user trying to use external FUSE library. This may explain why I always get user_id=0 and group_id=0. Any ideas?
    3. As far as I can tell, thunar-volman is using udev to automount? If yes, how does that work?
    4. Is there an easy way to let both methods live side by side - that is systemd mounting and udev / thunar-volman mounting - without one interfering with the other?

    In any case, the automount systemd feature doesn't seem to be that straightforward.

  • Note: we were taking a look to this on the Office Hours. Heiko will do another test on Ubuntu, as Manjaro was doing weird for some things. He was able to expose the external disk to a guest, using virsh/quemu.

    Heiko will update this thread with his findings :)

    Luis.

  • Posts: 916

    Just a reminder:

    We make no attempt to make sure anything works on Manjaro or with thunar etc, as we do not try to cover the entire universe of distributions and versions. We test on CentOS and Ubuntu primarily, and OpenSUSE secondarily, and this almost always means Red Hat, Fedora, Debian and SLES provide no real problems.

    The LFCS and LFCE exams are on CentOS and Ubuntu and getting absorbed with the variations for Manjaro, Kali, Mint etc may be fun but are unlikely to get much attention here, at least not mine. The same goes for trying to run complex stuff on RPI etc. Have fun but our help will be (consciously) limited.

  • Posts: 99

    Update

    I've passed through the external hard drive to a Ubuntu 18.04 server VM and edited the /etc/fstab file as follows:

    /dev/disk/by-partlabel/wdbook /mnt ntfs-3g noauto,rw,user,x-systemd.automount,x-systemd.device-timeout=10,x-systemd.idle-timeout=60,nls=utf8,uid=1000,gid=1000,dmask=027,fmask=137,nofail,windows_names,locale=en_US.utf8 0 0

    The drive is mounted as /dev/sda1:

    1. heiko@worker4:~$ ls -lF /dev/disk/by-partlabel/
    2. total 0
    3. lrwxrwxrwx 1 root root 10 Oct 5 19:30 wdbook -> ../../sda1

    Then I entered:

    1. root@worker4:/etc# systemctl daemon-reload
    2. root@worker4:/etc# systemctl restart local-fs.target
    3. root@worker4:/etc# lsblk -o name,mountpoint,partlabel,fstype
    4. NAME MOUNTPOINT PARTLABEL FSTYPE
    5. ...
    6. sda
    7. └─sda1 wdbook ntfs
    8. ...
    9.  

    The drive is not mounted automatically, just as expected.

    As non-root user I subsequently entered:

    1. heiko@worker4:~$ ls /mnt
    2. '$RECYCLE.BIN' 'My File Backup' 'System Volume Information'

    and my drive content shows up magically.

    1. heiko@worker4:~$ lsblk -o name,mountpoint,partlabel,fstype
    2. NAME MOUNTPOINT PARTLABEL FSTYPE
    3. ...
    4. sda
    5. └─sda1 /mnt wdbook ntfs
    6. ...
    7.  
    8. heiko@worker4:~$ cat /proc/mounts | grep mnt
    9. systemd-1 /mnt autofs rw,relatime,fd=41,pgrp=1,timeout=60,minproto=5,maxproto=5,direct,pipe_ino=24929 0 0
    10. /dev/sda1 /mnt fuseblk rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0

    After the specified timeout the drive automatically unmounts:

    1. heiko@worker4:~$ lsblk -o name,mountpoint,partlabel,fstype
    2. NAME MOUNTPOINT PARTLABEL FSTYPE
    3. ...
    4. sda
    5. └─sda1 wdbook ntfs
    6. ...

    Systemd automount works as advertised.

  • That's pretty good, @heiko_s !!

    I'm glad it worked as advertised, hehehe. Now it's more interesting because you are passing the device through the host to the guest. Oh, I don't forget it's a NTFS fs using the ntfs-3g driver ;)

    Many regards,
    Luis.

  • Posts: 99

    @coop said:
    Just a reminder:

    We make no attempt to make sure anything works on Manjaro or with thunar etc, as we do not try to cover the entire universe of distributions and versions. We test on CentOS and Ubuntu primarily, and OpenSUSE secondarily, and this almost always means Red Hat, Fedora, Debian and SLES provide no real problems.

    The LFCS and LFCE exams are on CentOS and Ubuntu and getting absorbed with the variations for Manjaro, Kali, Mint etc may be fun but are unlikely to get much attention here, at least not mine. The same goes for trying to run complex stuff on RPI etc. Have fun but our help will be (consciously) limited.

    Thanks for the comment. From now on I will only present issues that pertain to CentOS or Ubuntu. The reason I brought it up was that this was such a basic exercise and something that should just work. Normally I do all my labs and exercises on a Ubuntu or Centos VM, but that harddrive being attached and used by my host OS enticed me to do the exercise on the Manjaro (Arch Linux) host. Lesson learned, as you can see in my previous post.

  • Posts: 380

    I also re tested this on Ubuntu20-04 my fstab:

    /dev/nvme0n1p3 /home/win10 ntfs noauto,x-systemd.idle-timeout=30,x-
    systemd.automount,rw,relatime,user_id=0,group_id=0,allow_other 0 0

    As expected it worked as documented, one observation to keep in mind with the idle timer, the gnome GUI keeps the mount active and does not unmount automaticly. If a text console login used the automounter works.

  • Posts: 99

    Thanks Lee, that's good to know. Well, it's the same with trying to umount a drive with an open file browser - it won't work.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training