fstab automatically creates mount points

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


Solution 1:

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.

Solution 2:

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.