There is an inefficient way to mount external storage (local or remote). An
hard to die habit: fstab
. Let’s try autofs
.
The issue with fstab
Ok, maybe fstab is a simple way, and the most immediate way to mount resources at boot. And we are used to it. But if this external storage (i.e. a CIFS/SAMBA share, an sshfs filesystem) is not available during boot, or if the connection get lost while mounted, it could lead to undesired behaviours.
Using autofs
Install autofs
If it isn’t already installed
sudo dnf install autofs
Mount an USB disk
Using the disk label instead of /dev/sdX
Let’s suppose that you have a BTRFS filesystem on the USB disk. Let’s label it (in this way we will not use the classical /dev/sdX since it is unpredictable, and we don’t have to deal with esoteric UUIDs).
sudo btrfs filesystem label /dev/sda1 btrfs300
(For ext4 there are the e2label
and tune2fs
commands).
Configure autofs
Create a file like /etc/auto.master.d/trecento.autofs
|
|
Timeoud should umount the disk after 5 minutes, so in theory putting it to sleep.
Create the /etc/auto.ext-usb
file containing
|
|
As you can see, we are using the disk label to point the BTRFS partition.
Enable and start the autofs service
sudo systemctl enable autofs --now
Done
Issuing the mount
command
|
|
You see that the USB disk is not mounted. Listing or accessing the defined directory will automatically mount it
ll /media/trecento
mount
|
|
sshfs
Install the sshfs
package.
Create the /etc/auto.master.d/conta.autofs
file.
|
|
Create the /etc/auto.sshfs
file.
|
|
Of course you have to configure ssh keys in order to log in without a password.
CIFS/SAMBA
Same steps. Create a /etc/auto.master.d/cifs.autofs
file
|
|
Then /etc/auto.samba
|
|
You can create a /etc/.credentials/
directory and then a file containing the
credentials, /etc/.credentials/windows
|
|
Reload the changes
sudo systemctl restart autofs