Is there any difference between /run
directory and var/run
directory. It seems the latter is a link to the former. If the contents are one and the same what is the need for two directories?
2 Answers
From the Wikipedia page on the Filesystem Hierarchy Standard:
Modern Linux distributions include a
/run
directory as a temporary filesystem (tmpfs) which stores volatile runtime data, following the FHS version 3.0. According to the FHS version 2.3, this data should be stored in/var/run
but this was a problem in some cases because this directory isn't always available at early boot. As a result, these programs have had to resort to trickery, such as using/dev/.udev
,/dev/.mdadm
,/dev/.systemd
or/dev/.mount
directories, even though the device directory isn't intended for such data. Among other advantages, this makes the system easier to use normally with the root filesystem mounted read-only.
So if you have already made a temporary filesystem for /run
, linking /var/run
to it would be the next logical step (as opposed to keeping the files on disk or creating a separate tmpfs
).
-
13To make it clear,
/run
is new/var/run
. So,/var/run
is generally symlinked to/run
.– x-yuriCommented Mar 31, 2019 at 1:30 -
"this directory isn't always available at early boot" -- Why? Commented Feb 7, 2023 at 15:21
-
2@КонстантинВан good question. In the early stage of the boot process everything runs from RAM. Even the root filesystem is initially temporary, using initrd or initramfs. Filesystems on physical media, where
/var
may be, are typically mounted relatively late in the process.– GraemeCommented Feb 7, 2023 at 20:09
Some utilities traditionally used /var/run
, other /run
to store their process related material. When these were real on disc directories it did not matter too much that these were separate directories.
Nowadays /run/
is often implemented as a tmpfs
( mount | fgrep run
) and data in those directories won't survive a reboot (which is a good thing). It makes a little more sense to map these together using a symbolic link, and save a mount, especially as the permissions and settings for these directories would be the same anyway (in contrast to some other "directories" that are on tmpfs
)