Technical Tip

QUESTION

How can I create a systemd mount unit in Oracle/RedHat/CentOS Enterprise Linux 7?

ANSWER
Although you can still place entries in /etc/fstab, file system mounts can be created using
a systemd mount unit, as follows.

A filesystem mount can be defined in a unit file of type mount.
Traditionally, mounts are defined in the file /etc/fstab, and this file can still be used.
Note that entries in /etc/fstab are dynamically converted in to unit files when the file is read during booting.

There are conflicting views on which method should be used.

The /etc/fstab method is well known, so we will cover a mount example using a systemd unit file.

This example mounts /dev/sdb1, containing an XFS file system, on /oradata.
# cd  /etc/systemd/system
# vi  oradata.mount
Insert the following entries in oradata.mount:-

[Unit]
Description = Mount for Oracle DB
[Mount]
What = /dev/sdb1
Where = /oradata
Type = xfs
Options = uqnoenforce
[Install]
WantedBy = local-fs.target

The mount unit name must be the same as the Where value, e.g. if you are mounting on /oradata,
then the mount unit name must be oradata.mount. See below for more complex mount points.

The What value can be a UUID, but use the full path as found in /dev/disk/by-uuid, not the /etc/fstab format.

We now have to run:-
# systemctl  daemon-reload
# systemctl  enable  oradata.mount
# systemctl  start  oradata.mount
# systemctl  status oradata.mount
● oradata.mount - Mount for Oracle DB
  Loaded: loaded (/etc/systemd/system/oradata.mount; enabled; vendor preset: disabled)
   Active: active (mounted) since Wed 2016-06-01 11:05:45 BST; 20s ago
    Where: /oradata
     What: /dev/sdb1
  Process: 31073 ExecMount=/bin/mount /dev/sdb1 /oradata -n -t xfs -o uqnoenforce (code=exited, status=0/SUCCESS)
   Memory: 0B

Jun 01 11:05:45 buzz systemd[1]: Mounting Mount for Oracle DB...
Jun 01 11:05:45 buzz systemd[1]: Mounted Mount for Oracle DB.

Note that the uqnoenforce option turns on disk quotas, but does not enforce any limits.
It is used this way for reporting purposes.
Finally, if you wish to have a mount point /export/home/joe, then the mount unit must be called export-home-joe.mount.


We hope this has been useful, see below for additional notes
Mick Hosegood - First Alternative.

NOTES

  • All this is covered on the Enterprise Linux 7 administration courses!

First Alternative course tutors can answer questions like this ... and are happy to do so. Look around our site for relevant courses in Linux -Unix - Solaris

close window