0

I need help with autofs. It is a little complicated.

I am stuck at this point. I have no /data directory.

The/data directory and the subdirectories fs1/, fs2/, and fs3/ should be automatically created, as you can see in the screenshot below.
$ ls /data

https://i.stack.imgur.com/Lg79a.jpg

https://linuxhint.com/mount-filesystems-automatically-on-demand-using-autofs/

This is my auto.sda2

/dev/sda2   ext3    UUID=5b4b2ae5-9aaa-4559-9f41-afb313998c75

My auto.master

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#/misc  /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#   "nosuid" and "nodev" options unless the "suid" and "dev"
#   options are explicitly given.
#
#/net   -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/etc/auto.sda2
3
  • systemd can do that. This is a good comparison between the two...
    – kanehekili
    Sep 30, 2022 at 22:20
  • I am talking about autofs not automount. @kanehekili
    – fixit7
    Oct 1, 2022 at 0:26
  • What version of Ubuntu are you using? Why is drive formatted as ext3 and not the more common ext4?
    – David
    Oct 1, 2022 at 5:36

1 Answer 1

1

First of all, automount is the daemon part of autofs, but systemd uses the name automount in his context, too (see man systemd.automount).

Second, I assume you use an Ubuntu version still under support (e.g. 20.04, 22.04, ...).

As far as I understood you want to automount /dev/sda2 as /data/fs2.

You need to have the package autofs installed (sudo apt-get install autofs). With it there are some example files in /etc where you can see how it works.

In your case there are multiple files involved.

  1. /etc/auto.master (see man auto.master for complete syntax and options) There you already added the line /etc/auto.sda2 which is not correct. The mountpoint is missing as you can see from the examples in the file. Correct is /data /etc/auto.sda2, but I would rather name it auto.data. But let's stick with auto.sda2
  2. /etc/auto.sda2 There this line needs to be inside (see man 5 autofs for complete syntax and options):
fs2 -fstype=ext3 :/dev/sda2
  1. You have to create the root directories of the mountpoint: sudo mkdir /data
  2. restart autofs: sudo systemctl restart autofs
  3. at this point all is ready and you should be able to do ls /data/fs2

As the name "automount" says, it is mounted only on "demand", means when accessed. Usually ls /data would show an empty directory.

In the file /etc/autofs.conf (see man 5 autofs.conf for complete syntax and options) you can change several options. One is named browse_mode which is set to no by default. Search in the existing /etc/autofs.conf file for it, uncomment it and set it to yes (browse_mode = yes). Restart autofs (see above). Now you will always see the directories in /data, even if they are not yet mounted.

1
  • Where do I make this/ sudo mkdir /data ? @Marco
    – fixit7
    Oct 1, 2022 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .