Score:6

Is my /var directory OK, since /var/run isn't a symlink?

in flag

I am running Ubuntu 18.04. When I run:

ls -la /var

I get the following:

drwxr-xr-x 10 root root   4096 Jan  2 15:46 .
drwxr-xr-x 27 root root   4096 Jan 15 06:25 ..
drwxr-xr-x 10 root root   4096 Jan  6 06:15 cache
drwxrwxrwt  2 root root   4096 Jan 12 06:41 crash
drwxr-xr-x 25 root root   4096 Jan  4 11:06 Lib
lrwxrwxrwx  1 root root     11 Dec 27 07:22 lock -> ../run/lock
drwxrwxr-x  8 root syslog 4096 Jan 10 06:06 log
drwx------  6 root root   4096 Jan 15 06:03 run
drwxr-xr-x  4 root root   4096 Jan  3 14:54 snap
drwxr-xr-x  4 root root   4096 Dec 27 07:22 spool
drwxr-xr-x  6 root root   4096 Jan 15 06:03 tmp

AFAIK /var/run should be symlink to /run. I have some problems in my system as described in 'who' command has blank output when using SSH, so is it because /var/run is not a symlink? Can I safely remove it and replace it with a symlink?

Score:8
vn flag

You're right that /var/run is normally a symlink.

However, if /var/run does not contain any files, it should be safe to replace with a symlink. If there are files, you should move them to /run first.

When the directory /var/run is empty, you can replace with a symlink like this:

$ rmdir /var/run
$ ln -s /run /var/run

Referring to your previous question, I guess this could be the cause of failure, since /run contains the socket /run/dbus/system_bus_socket.

ammcom avatar
in flag
Actually it was the problem, after removing /var/run and add the link the service is back to life again thank you very much
Artur Meinild avatar
vn flag
Sounds good.
Peter Cordes avatar
fr flag
On my Arch Linux system, `/var/run` is a symlink to `../run`, which presumably makes it work better if looking at a chroot or container filesystem from outside that container. So I'd recommend `ln -s ../run /var/run`, unless Ubuntu normally uses a different symlink.
Artur Meinild avatar
vn flag
You're probably right. But the default Ubuntu symlink points to just `/run` (and its size is 4 bytes).
Score:5
jp flag

You should never unlink /var/run from /run or use it for any other purpose ... The sole purpose that /var/run existed long time ago was to hold system information data describing the system since it was booted ... This functionality has been moved to /run in modern systems ... However, /var/run still exists to ensure compatibility with systems and software that are still using the old specification.

Your linked other question is a living example of such software ... The who command still uses /var/run as stated in its manual:

If FILE is not specified, use /var/run/utmp.

and an strace on Ubuntu 22.04 confirms that:

strace -e openat who
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/var/run/utmp", O_RDONLY|O_CLOEXEC) = 3 # <-- This one
openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 3
ubuntu   :0           2023-01-12 19:48 (:0)
+++ exited with 0 +++
Artur Meinild avatar
vn flag
Thanks for some additional background information!
Joshua avatar
cz flag
Actually it's more like `/var/run` is the broad-scoped name of the endpoint. `/run` only exists at all if it's a ramdrive. If you don't have a ramdrive (maybe because your memory supply is puny); it's going to be `/var/run` as a directory cleared at boot.
Raffa avatar
jp flag
@Joshua Actually, it's not really about what I or you think of it :-) ... This is how it is and should be since [FHS(*Filesystem Hierarchy Standard*) V. 3](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.