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
- 167 LFX Mentorship
- 219 LFX Mentorship: Linux Kernel
- 799 Linux Foundation IT Professional Programs
- 357 Cloud Engineer IT Professional Program
- 180 Advanced Cloud Engineer IT Professional Program
- 82 DevOps Engineer IT Professional Program
- 149 Cloud Native Developer IT Professional Program
- 112 Express Training Courses
- 138 Express Courses - Discussion Forum
- 6.2K Training Courses
- 48 LFC110 Class Forum - Discontinued
- 17 LFC131 Class Forum
- 42 LFD102 Class Forum
- 227 LFD103 Class Forum
- 19 LFD110 Class Forum
- 39 LFD121 Class Forum
- 15 LFD133 Class Forum
- 7 LFD134 Class Forum
- 17 LFD137 Class Forum
- 63 LFD201 Class Forum
- 3 LFD210 Class Forum
- 5 LFD210-CN Class Forum
- 2 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum - Discontinued
- 1 LFD233 Class Forum
- 2 LFD237 Class Forum
- 23 LFD254 Class Forum
- 697 LFD259 Class Forum
- 109 LFD272 Class Forum
- 3 LFD272-JP クラス フォーラム
- 10 LFD273 Class Forum
- 154 LFS101 Class Forum
- 1 LFS111 Class Forum
- 1 LFS112 Class Forum
- 1 LFS116 Class Forum
- 1 LFS118 Class Forum
- LFS120 Class Forum
- 7 LFS142 Class Forum
- 7 LFS144 Class Forum
- 3 LFS145 Class Forum
- 1 LFS146 Class Forum
- 3 LFS147 Class Forum
- 1 LFS148 Class Forum
- 15 LFS151 Class Forum
- 1 LFS157 Class Forum
- 34 LFS158 Class Forum
- 8 LFS162 Class Forum
- 1 LFS166 Class Forum
- 1 LFS167 Class Forum
- 3 LFS170 Class Forum
- 2 LFS171 Class Forum
- 1 LFS178 Class Forum
- 1 LFS180 Class Forum
- 1 LFS182 Class Forum
- 1 LFS183 Class Forum
- 29 LFS200 Class Forum
- 736 LFS201 Class Forum - Discontinued
- 2 LFS201-JP クラス フォーラム
- 14 LFS203 Class Forum
- 135 LFS207 Class Forum
- 1 LFS207-DE-Klassenforum
- 1 LFS207-JP クラス フォーラム
- 301 LFS211 Class Forum
- 55 LFS216 Class Forum
- 48 LFS241 Class Forum
- 48 LFS242 Class Forum
- 37 LFS243 Class Forum
- 15 LFS244 Class Forum
- LFS245 Class Forum
- LFS246 Class Forum
- 50 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- LFS251 Class Forum
- 155 LFS253 Class Forum
- LFS254 Class Forum
- LFS255 Class Forum
- 5 LFS256 Class Forum
- 1 LFS257 Class Forum
- 1.3K LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 122 LFS260 Class Forum
- 159 LFS261 Class Forum
- 42 LFS262 Class Forum
- 82 LFS263 Class Forum - Discontinued
- 15 LFS264 Class Forum - Discontinued
- 11 LFS266 Class Forum - Discontinued
- 20 LFS267 Class Forum
- 25 LFS268 Class Forum
- 31 LFS269 Class Forum
- 3 LFS270 Class Forum
- 199 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- LFS274 Class Forum
- 3 LFS281 Class Forum
- 10 LFW111 Class Forum
- 261 LFW211 Class Forum
- 182 LFW212 Class Forum
- 15 SKF100 Class Forum
- 1 SKF200 Class Forum
- 1 SKF201 Class Forum
- 782 Hardware
- 198 Drivers
- 68 I/O Devices
- 37 Monitors
- 96 Multimedia
- 174 Networking
- 91 Printers & Scanners
- 83 Storage
- 758 Linux Distributions
- 80 Debian
- 67 Fedora
- 15 Linux Mint
- 13 Mageia
- 23 openSUSE
- 143 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 348 Ubuntu
- 461 Linux System Administration
- 39 Cloud Computing
- 70 Command Line/Scripting
- Github systems admin projects
- 90 Linux Security
- 77 Network Management
- 101 System Management
- 46 Web Management
- 64 Mobile Computing
- 17 Android
- 34 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 371 Off Topic
- 114 Introductions
- 174 Small Talk
- 19 Study Material
- 806 Programming and Development
- 304 Kernel Development
- 204 Software Development
- 1.8K Software
- 263 Applications
- 180 Command Line
- 3 Compiling/Installing
- 405 Games
- 309 Installation
- 97 All In Program
- 97 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)