Skip to main content

Working with Systemd Mount Units

Hands-On Lab

 

Photo of Matthew Pearson

Matthew Pearson

Linux Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

Systemd automatically manages mounts for entries that are listed in systemd, and allows you to manually create mount units. In this hands-on lab, you will be tasked with creating systemd mount and automount units.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Systemd Mount Units

In this hands-on lab, we will create systemd mount and automount units. We will create the two new mount units on our host.

The first mount unit should comply with the following:

  • File system:/dev/xvdg1
  • Mounted on /mnt/data
  • Filesystem: xfs
  • Description: "Data mount"
  • Should be wanted by the multi-user.target

The second mount should comply with the following:

  • File system: /dev/xvdg2
  • Mounted on /mnt/backup
  • Filesystem:ext4
  • Mounted as read-only.
  • Description: "Backup mount"
  • Should be wanted by the multi-user.target.

The file system should comply with the following:

  • Automatically mounted using an automount unit
  • An idle timeout of 10 minutes
  • Description: "Automount backup directory”
  • Should be wanted by the multi-user.target.

Note:

  • Creat all unit files in /etc/systemd/system
  • The UUIDs of the filesystems will change with each attempt

Before We Begin

To get started, we need to log in to our Linux server using the provided credentials. Make sure to become the root user once logged in.

Create a Unit File for the Data Mount

Create a unit file for the data mount based on the information provided in the instructions and ensure that it is started and enabled:

  1. First, we need to change our directory to the system directory using cd /etc/systemd/system.
  2. Run lsblk -f to obtain the UUID for xvdg1 xfs for use in the file.
  3. Create a unit file in /etc/systemd/system named mnt-data.mount. For our example, we're using vim:
    vim mnt-data.mount
  4. Enter the following into the file:
[Unit]
Description=Data mount

[Mount]
What=/dev/disk/by-uuid/Filesystem_UUID
Where=/mnt/data
Type=xfs
Options=defaults

[Install]
WantedBy=multi-user.target
  1. Save and quit with :wq.
  2. Update the systemd manager configuration to include the new unit file:

systemctl daemon-reload

  1. Start and enable the mnt-data.mount unit:

systemctl enable mnt-data.mount --now

Create a Unit File for the Backup Mount

Create a unit file for the backup mount:

  1. Create a mountpoint for mnt-backup.mount at /mnt/backup:

mkdir /mnt/backup

  1. Use lsblk -f and coppy the UUID for xvdg2 ext4 for the mnt-backup.mount file.
  2. Create a unit file in /etc/systemd/system named mnt-backup.mount using vim: vim mnt-backup.mount
  3. Enter the following contents:
[Unit]
Description=Backup mount

[Mount]
What=/dev/disk/by-uuid/Filesystem_UUID
Where=/mnt/backup
Type=ext4
Options=ro

[Install]
WantedBy=multi-user.target
  1. Save and quit.
  2. Update the systemd manager configuration to include a new unit file:

systemctl daemon-reload

Create an Automount Unit File

Create an automount unit file for mnt-backup.mount based on the information provided:

  1. Create a unit file in /etc/systemd/system named mnt-backup.automount using vim: vim mnt-backup.automount.
  2. Enter the following contents:
[Unit]
Description=Automount backup directory

[Automount]
Where=/mnt/backup
TimeoutIdleSec=600

[Install]
WantedBy=multi-user.target
  1. Save and quit.
  2. Update the systemd manager configuration to include the new unit file:

systemctl daemon-reload

  1. Start and enable the mnt-backup.automount unit:

systemctl enable mnt-backup.automount --now

  1. Check that the status is running:
    systemctl status mnt-backup.automount

Conclusion

Congratulations! You've completed the lab!