Mounting Linux volumes with systemd vs fstab

Mounting Linux volumes with systemd vs fstab

fstab file viewed in VIM

What is better, mounting with systemd or fstab. If you have ever done anything more than just an out of the box Linux installation you have more than likely worked with fstab to get your volumes to mount. The screenshot to the left shows an example of a fstab file.

In this example, we are going to look at /dev/sda6 which is mounted to /apps using the XFS file partition and using the defaults. In the sample fstab file you will also notice other volumes mounted using UUID and also the volume label.

The UUID you can get by running blkid at the command prompt. Both the UUID and label methods are best as things can change in the system that would change the /dev/sda6 name at which point you’ll have issues with your mounts.

I know that Red Hat is going to be using the systemd method of mounting in future versions of Red Hat, so it would be good to understand this way of doing it. In all it is not that much more difficult to setup as before, however the mounts will all be controlled via the systemd process and you can use commands such as systemctl status, start, enable, and disable on your individual mounts.

Setting up systemd mounts

The first step is to get a sample .mount file that you can edit for your purposes. These files are located on your system at /lib/systemd/system. When you are in this path you can do an ls *mount to get a listing of all the various .mount files available. A good one to choose is the tmp.mount file. We need to copy this file to /etc/systemd/system/.

# cp tmp.mount /etc/systemd/system/apps.mount

You want to pick a name that will be descriptive of what you are mounting. In this example we are mounting an apps volume, so that is why I chose the apps.mount filename.

Systemd configuration file

We can then use vim to edit the file and change it to meet our requirements. We can remove any information related to the tmp.mount file, and add the proper information to have our apps volume mount. In the screenshot to the right, you see an example of what the file should look like. Under the [Mount] section we can enter the following:

  • what=UUID=”277927f6-a97a-4580-b409-eb9b6cb09fca”
  • where=/apps
  • type=xfs
  • options=defaults

As you can see the format is similar to what you have done in the fstab before. Once you have this done you can save your file, and then it all comes down to standard systemctl commands. Instead of all being on one line, you enter them on four separate lines.

Benefits of using UUID

Also the use of UUID=”277927f6-a97a-4580-b409-eb9b6cb09fca” instead of /dev/sda6 is preferred to prevent issues if the device names change due to a file system reconfiguration later on. Remember, you can see what the UUID of any device is by running the blkid command.

# systemctl daemon-reload
# systemctl start apps.mount
# systemctl status apps.mount
# systemctl enable apps.mount
Systemctl status apps.mount

Don’t forget to add the .mount at the end, as if you forget systemctl will think you are talking about a service and the command will fail. Also be sure as with fstab and any other manual mounting method you have the mount point created, in our case /apps.

At this point, the volume will mount each time the system starts via systemd. You’ll be able to remove this entry from your fstab file.

I hope you found this article informative. If you have any questions, feel free to reach out to me.

Share

Ivan Windon

Ivan Windon is a Site Reliability Engineer at IBM. Ivan is actively engaged in Cloud Technologies with AWS, Google, and Azure. Ivan has extensive experience with Linux and Windows administration, DNS, Networking, IDM, and Security. In his free time, he enjoys being with his wife and two children. The family enjoys hiking, and traveling when able. His favorite locations are Yosemite NPS, and San Francisco, California.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.