7

As mentioned here, "you must create the mount point before you mount the partition." But after adding the following lines in fstab and rebooting the system

/dev/sdxy /media/user/hdd_mount_point ext4 defaults 0 0
tmpfs /mnt/tmpfs_mount_point tmpfs rw,nosuid,noatime,nodev,size=4G,mode=1777 0 0

the mount points (target directories) hdd_mount_point and tmpfs_mount_point are automatically created if they do not exist. I know that you can make a mount point if it does not exist by adding the X-mount.mkdir option to mount command as mentioned in its manual page, but I really like to know if this option is implicitly used when mounting file systems via fstab.

And NO, it is not a duplicate of Automatic Adding of Filesystems to /etc/fstab

6
  • part and parcel of the installation process?
    – 24601
    Jan 2, 2021 at 14:45
  • What? Actually I edited fstab many times to be sure it creates the mount point every time and not during a fresh install of OS.
    – Dante
    Jan 2, 2021 at 14:48
  • 1
    Does this answer your question? Automatic Adding of Filesystems to /etc/fstab
    – 24601
    Jan 2, 2021 at 14:55
  • See: help.ubuntu.com/community/Mount/USB It is called Automounting but it only temporarily creates the mount points. If you want them permanently you will have to create them yourself and add them to the /etc/fstab.
    – Terrance
    Jan 2, 2021 at 15:01
  • 2
    @Dante You need to rewrite your question then. I'm not sure what you are asking. The only mount points that are created automatically are done during the initial install of the OS. All others you have to create yourself afterwards or use the automounting where you double-click the drive after each reboot and that one creates the /media/user/mountpoint as you are saying there.
    – Terrance
    Jan 2, 2021 at 15:06

2 Answers 2

7

This used to be true, and still is if you wish to use the classic mount command.

In recent years, the entries in /etc/fstab are mounted at boot time by systemd, which automatically creates missing mountpoints as needed, irrespective of the presence of the X-mount.mkdir option.

It also provides the command systemd-mount as an alternative to mount, should you wish to mount a partition yourself without first manually creating a directory to mount over.

3
  • 1
    But without X-mount.mkdir option, you get mount: my_mount_point: mount point does not exist. error if my_mount_point directory does not exist already.
    – Dante
    Jan 2, 2021 at 17:19
  • Yes, if you still use mount. Jan 2, 2021 at 17:29
  • 1
    @Dante if you still use mount AFTER the system is booted, it bypasses SystemD's "at boot" mountpoint generation mechanism. So if you are not mounting automatically at boot, you need the mountpoint to be created first. SystemD removes most of the "at boot" work but after things are mounted at boot that's about it, it won't go digging afterwards when you call mount to create mountpoints.
    – Thomas Ward
    Jan 2, 2021 at 17:30
3

And here the essential parts from the documentation:

Mount units may either be configured via unit files, or via /etc/fstab
(see fstab(5) for details). Mounts listed in /etc/fstab will be converted
into native units dynamically at boot and when the configuration of the
system manager is reloaded. In general, configuring mount points through
/etc/fstab is the preferred approach. See systemd-fstab-generator(8) for
details about the conversion.

Further down you'll find this:

Where=

    Takes an absolute path of a file or directory for the mount point;
    in particular,the destination cannot be a symbolic link. If the
    mount point does not exist at the time of mounting, it is created
    as directory.
2
  • Thanks for the reference, but what is mentioned here is still weird and misleading IMO.
    – Dante
    Jan 2, 2021 at 18:53
  • The information on that page appears to be outdated regarding this point, it was correct before systemd was used, look at the revision history, since 2014 there are only a few edits made.
    – mook765
    Jan 3, 2021 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.