Why has /var/run been migrated to /run?
From the technical overview of Ubuntu 11.10 Oneiric:
Ubuntu 11.10 has migrated away from
/var/run
,/var/lock
and/dev/shm
and now uses/run
,/run/lock
and/run/shm
instead (respectively).
- I hardcode these paths in my applications, why is this change made to Oneiric?
- What can I do to make my applications backwards- and forward-compatible? Is there a better way other than checking first for the existence of
/run
, and then/var/run
?
The intent is to reduce the number of tmpfs
file systems. On 11.04, there are separate tmpfs
file systems at /var/lock
, /var/run
and /dev/shm
. If these directories were all under a single parent directory, then only a single tmpfs
would be needed. It also provides an obvious location for further runtime state data that shouldn't persist over reboots.
Unless your application depends on canonical paths of files, your application should run without modification since the old locations will be symlinked to the new ones. The AppArmor policies are one case that does depend on the real path names, which is why it was mentioned specifically.
The following links should help explain the rationale:
- http://lists.fedoraproject.org/pipermail/devel/2011-March/150031.html
- https://bugs.linuxfoundation.org/show_bug.cgi?id=718
- https://lists.linuxfoundation.org/pipermail/fhs-discuss/2011-May/000061.html
- http://wiki.debian.org/ReleaseGoals/RunDirectory
-
/run
is a new cross-distribution tmpfs location for the storage of transient state files—that is, files containing run-time information that may or may not need to be written early in the boot process and which does not require preserving across reboots.Making the
/run
directory available brings us a step closer to the point where it is possible to use the system normally with the root filesystem mounted read-only, without requiring any clunky workarounds such asaufs/unionfs
overlays./run
replaces several existing locations described in the Filesystem Hierarchy Standard:-
/var/run
→/run
-
/var/lock
→/run/lock
-
/dev/shm
→/run/shm
[currently only Debian plans to do this] -
/tmp
→/run/tmp
[optional; currently only Debian plans to offer this] /run
also replaces some other locations that have been used for transient files:/lib/init/rw
→/run
-
/dev/.*
→/run/*
-
/dev/shm/*
→/run/*
- writable files under
/etc
→/run/*
(so you probably can expect these to move aswell).
Source:debian release goals
-
I would advice on creating a part in your software where you set these directories in variables, change your code to use these variables and then alter the variables based on the system it is used on (but I bet you knew that already).
From what I have read, this was the original explanation given as to why /run was introduced. http://lwn.net/Articles/436012/
You should not hardcode any of these /run
paths!
- Use
/var/run
, because a symlink will be in place to/run
if applicable -
/var/lock
is the same as above - Don't hardcode
/dev/shm
ever, always useshm_open
etc (the posix API)