3

I have this entry in fstab:

LABEL=cache /disks/cache ext4 rw,user,x-mount.mkdir,relatime,noauto,errors=remount-ro,x-systemd.idle-timeout=120min  0 0

What I expoect to do is:

  1. to mount the disk with the label cache on /disks/cache any time I demand it
  2. to create the path /dsisks/cache if it doesn't exist
  3. To give +rwx permission to my user or any user in it's deffect
  4. to atomatically unmount the disk if it's idle after 1 hour

Why step 4 which is isn't working and how to make that the folder be removed after unmounting, is it there a x-umount.rmdir option?

Marcus Müller
  • 21,602
  • 2
  • 39
  • 54
ape1
  • 41
  • 5
  • You should try autofs instead of fstab. It does exactly this. – user10489 Nov 02 '21 at 23:01
  • 1
    @user10489 are you sure there-s no way to do it with fstab? Because I don't want to over complicate it plus why if not is option 4 already specified? – ape1 Nov 03 '21 at 19:08
  • Yes, autofs is the only way to automatically mount and unmount. fstab either mounts once at boot or it mounts manually, it does not handle automatic on demand mounts. Only autofs does that. – user10489 Nov 04 '21 at 02:49
  • 1
    So then, for what is a do nothing function written on the man then? – ape1 Nov 05 '21 at 19:04
  • I'm sorry I am unable to parse any meaning from that. – user10489 Nov 05 '21 at 22:02

1 Answers1

0

What you describe can't be done in fstab.

The following are the typical ways to mount disks:

  • Add them to fstab so they are automatically mounted at boot. (The option defaults or auto in fstab does this.)
  • Mount them manually, either as root with all parameters specified, or manually as only a mount point or device with remaining options from fstab, or as a user for entries listed in fstab with the noauto,user options in the fourth column.
  • Use udisks to automatically mount hot insert disks, such as cdroms and usb sticks, usually on the /media directory. This however, only unmounts on user demand. Udisks typically mounts on device insertion, but it can also be triggered from the command line.
  • Use autofs to mount them on demand, when the directory is referenced, and unmount them after a timeout and they are no longer in use.

Autofs is configured by listing managed top directories one per line in /etc/auto.master with a config file per managed directory, with each config file listing subdirectories of the managed directories.

For example, auto.master may list /etc/auto.misc which in turn may list a number of filesystems or devices with potential filesystems. The default auto.misc that comes with autofs lists floppy (commented out by default) which would be mounted on /misc/floppy if it was accessed and a filesystem was available on that device.

Sample lines from auto.master:

/misc  /etc/auto.misc
/home  /etc/auto.home
/disks  /etc/auto.disks   --timeout=3600

Sample line from auto.misc:

floppy         -fstype=auto            :/dev/fd0

Sample line from auto.home:

someuser         homeserver:/export/home/someuser

Autofs can do everything you asked for except set the permissions, which typically are inherited from the permissions of the root directory on the mounted filesystem, or mount options if the filesystem supports that. The above (untested) disks line would require a corresponding /etc/auto.disks file describing the filesystems you want mounted in /disks/

user10489
  • 5,834
  • 1
  • 10
  • 22