ArticlesRocky Linux

How to Avoid a Read-only Filesystem When Using a Separate Partition or Volume for /tmp

Introduction

When installing Rocky Linux in a cloud environment, all directories, including /tmp, will typically be installed on a single volume. If you try to use a separate partition or volume for /tmp, you might encounter an issue where the entire root filesystem becomes read-only after a reboot. This occurs because the systemd tmp.mount unit is sometimes masked by default.

When a systemd unit is masked, it is linked to /dev/null, making it impossible to start. This differs from disabling a service, which prevents it from running at startup, but does allow it to be manually started or started by another process or unit.

You want the tmp.mount unit to be disabled so it does not start by default. However, you need systemd to start the tmp.mount service when it runs the systemd-fstab-generator at boot, which converts /etc/fstab entries into native systemd units. If tmp.mount is masked, this process fails, causing the system to mount the root directory as read-only.

Symptoms

After you add an entry for /tmp in /etc/fstab and then reboot, you may see many errors related to a read-only filesystem. You will likely also see the following error when attempting to create a file:

touch /var/tmp/test
touch: cannot touch 'var/tmp/test': Read-only file system

Resolution

Telling systemd to unmask this unit will allow you to mount /tmp according to how /etc/fstab is configured:

sudo systemctl unmask tmp.mount

If you get a read-only filesystem error when attempting this, you need to remount the root volume first:

sudo mount -o remount,rw /

Once the filesystem is remounted and you have verified you can write to it, rerun the unmask command. After a reboot, your server should start up as expected.

There is no need to enable this unit as systemd will dynamically generate it and start it at boot.

Root Cause

This issue arises because cloud servers are primarily used for network-specific tasks such as web hosting.

As a result, the need for an in-memory /tmp directory (which is generated by default when you start tmp.mount), is largely negated because the network is significantly slower than the disk that /tmp would run on.

Additionally, since memory is a significant factor in the cost of cloud services, Rocky Linux does not rely on memory-based tmpfs directories. Moreover, the need for a separate partition or volume for /tmp is only necessary in minimal use cases and is unnecessary for the majority of workloads.

References & related articles

freedesktop.org's page on systemd-fstab-generator: Link Rocky Linux Admin Guide Link