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:
$ ls -lF /usr/bin/mount.ntfs* lrwxrwxrwx 1 root root 16 Aug 30 12:50 /usr/bin/mount.ntfs -> /usr/bin/ntfs-3g* 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:
/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
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.
Comments
-
I rechecked the setup. It turns out I had created a media-heiko-wdbook.mount file with the following content:
# https://www.golinuxcloud.com/automount-file-system-systemd-rhel-centos-7-8/ [Unit] Description=Western Digital Book wdbook external drive DefaultDependencies=no Conflicts=umount.target Before=local-fs.target umount.target After=swap.target [Mount] What=/dev/disk/by-partlabel/wdbook Where=/media/heiko/wdbook Type=ntfs-3g Options=noauto,rw,user,nls=utf8,uid=1000,gid=1000,dmask=027,fmask=137,nofail,windows_names,locale=en_US.utf8 [Install] WantedBy=multi-user.target
This mount option was enabled.
When I stopped and disabled the mount service the drive does NOT auto-mount:
$ systemctl status media-heiko-wdbook.mount ● media-heiko-wdbook.mount - Western Digital Book wdbook external drive Loaded: loaded (/etc/systemd/system/media-heiko-wdbook.mount; disabled; vendor preset: disabled) Active: inactive (dead) Where: /media/heiko/wdbook What: /dev/disk/by-partlabel/wdbook
To check it:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdf 8:80 0 3.6T 0 disk └─sdf1 8:81 0 3.6T 0 part
or better:
$ systemctl -t mount UNIT LOAD ACTIVE SUB DESCRIPTION -.mount loaded active mounted Root Mount boot-efi.mount loaded active mounted /boot/efi dev-hugepages.mount loaded active mounted /dev/hugepages dev-mqueue.mount loaded active mounted POSIX Message Queue File System home.mount loaded active mounted /home run-user-1000-gvfs.mount loaded active mounted /run/user/1000/gvfs run-user-1000.mount loaded active mounted /run/user/1000 sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System sys-kernel-config.mount loaded active mounted Kernel Configuration File System sys-kernel-debug.mount loaded active mounted Kernel Debug File System sys-kernel-tracing.mount loaded active mounted Kernel Trace File System tmp.mount loaded active mounted Temporary Directory (/tmp)
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:
- 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.
- /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.
- With fstab entry, media-heiko-wdbook.mount enabled and running:
sudo systemctl enable media-heiko-wdbook.mount
sudo systemctl start media-heiko-wdbook.mountThe 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:
$ sudo mount /media/heiko/wdbook/ [heiko@woody ~]$ cat /proc/mounts | grep sdf1 /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:
$ mount /media/heiko/wdbook/ Unprivileged user can not mount NTFS block devices using the external FUSE library. Either mount the volume as root, or rebuild NTFS-3G with integrated FUSE support and make it setuid root. Please see more information at http://tuxera.com/community/ntfs-3g-faq/#unprivileged
- 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:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdf 8:80 0 3.6T 0 disk └─sdf1 8:81 0 3.6T 0 part /media/heiko/wdbook
A look at /proc/mounts shows the mount options used:
$ cat /proc/mounts | grep sdf1 /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:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdf 8:80 0 3.6T 0 disk └─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:
$ cat /proc/mounts | grep sdf1 /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
- Some higher-level convenience tools don't play nicely with "low-level" configurations, overriding manual systemd and fstab configurations.
- 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?
- As far as I can tell, thunar-volman is using udev to automount? If yes, how does that work?
- 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.
0 -
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.
0 -
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.
1 -
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:
heiko@worker4:~$ ls -lF /dev/disk/by-partlabel/ total 0 lrwxrwxrwx 1 root root 10 Oct 5 19:30 wdbook -> ../../sda1
Then I entered:
root@worker4:/etc# systemctl daemon-reload root@worker4:/etc# systemctl restart local-fs.target root@worker4:/etc# lsblk -o name,mountpoint,partlabel,fstype NAME MOUNTPOINT PARTLABEL FSTYPE ... sda └─sda1 wdbook ntfs ...
The drive is not mounted automatically, just as expected.
As non-root user I subsequently entered:
heiko@worker4:~$ ls /mnt '$RECYCLE.BIN' 'My File Backup' 'System Volume Information'
and my drive content shows up magically.
heiko@worker4:~$ lsblk -o name,mountpoint,partlabel,fstype NAME MOUNTPOINT PARTLABEL FSTYPE ... sda └─sda1 /mnt wdbook ntfs ... heiko@worker4:~$ cat /proc/mounts | grep mnt systemd-1 /mnt autofs rw,relatime,fd=41,pgrp=1,timeout=60,minproto=5,maxproto=5,direct,pipe_ino=24929 0 0 /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:
heiko@worker4:~$ lsblk -o name,mountpoint,partlabel,fstype NAME MOUNTPOINT PARTLABEL FSTYPE ... sda └─sda1 wdbook ntfs ...
Systemd automount works as advertised.
1 -
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.0 -
@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.
0 -
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 0As 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.
1 -
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.
1
Categories
- All Categories
- 50 LFX Mentorship
- 103 LFX Mentorship: Linux Kernel
- 575 Linux Foundation IT Professional Programs
- 304 Cloud Engineer IT Professional Program
- 125 Advanced Cloud Engineer IT Professional Program
- 53 DevOps Engineer IT Professional Program
- 60 Cloud Native Developer IT Professional Program
- 5 Express Training Courses
- 5 Express Courses - Discussion Forum
- 2K Training Courses
- 19 LFC110 Class Forum
- 7 LFC131 Class Forum
- 27 LFD102 Class Forum
- 156 LFD103 Class Forum
- 20 LFD121 Class Forum
- 1 LFD137 Class Forum
- 61 LFD201 Class Forum
- 1 LFD210 Class Forum
- LFD210-CN Class Forum
- 1 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum
- LFD237 Class Forum
- 23 LFD254 Class Forum
- 611 LFD259 Class Forum
- 105 LFD272 Class Forum
- 1 LFD272-JP クラス フォーラム
- 1 LFD273 Class Forum
- 2 LFS145 Class Forum
- 24 LFS200 Class Forum
- 739 LFS201 Class Forum
- 1 LFS201-JP クラス フォーラム
- 10 LFS203 Class Forum
- 75 LFS207 Class Forum
- 300 LFS211 Class Forum
- 54 LFS216 Class Forum
- 47 LFS241 Class Forum
- 41 LFS242 Class Forum
- 37 LFS243 Class Forum
- 11 LFS244 Class Forum
- 34 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- LFS251 Class Forum
- 140 LFS253 Class Forum
- LFS254 Class Forum
- 1.1K LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 93 LFS260 Class Forum
- 132 LFS261 Class Forum
- 33 LFS262 Class Forum
- 80 LFS263 Class Forum
- 15 LFS264 Class Forum
- 11 LFS266 Class Forum
- 18 LFS267 Class Forum
- 17 LFS268 Class Forum
- 23 LFS269 Class Forum
- 203 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- LFS274 Class Forum
- LFS281 Class Forum
- 233 LFW211 Class Forum
- 172 LFW212 Class Forum
- 7 SKF100 Class Forum
- SKF200 Class Forum
- 902 Hardware
- 219 Drivers
- 74 I/O Devices
- 44 Monitors
- 115 Multimedia
- 209 Networking
- 101 Printers & Scanners
- 85 Storage
- 763 Linux Distributions
- 88 Debian
- 66 Fedora
- 15 Linux Mint
- 13 Mageia
- 24 openSUSE
- 142 Red Hat Enterprise
- 33 Slackware
- 13 SUSE Enterprise
- 357 Ubuntu
- 479 Linux System Administration
- 41 Cloud Computing
- 70 Command Line/Scripting
- Github systems admin projects
- 95 Linux Security
- 78 Network Management
- 108 System Management
- 49 Web Management
- 68 Mobile Computing
- 23 Android
- 30 Development
- 1.2K New to Linux
- 1.1K Getting Started with Linux
- 537 Off Topic
- 131 Introductions
- 217 Small Talk
- 21 Study Material
- 826 Programming and Development
- 278 Kernel Development
- 514 Software Development
- 928 Software
- 260 Applications
- 184 Command Line
- 3 Compiling/Installing
- 76 Games
- 316 Installation
- 62 All In Program
- 62 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)