6

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?

Raffa
  • 34,963
ammcom
  • 183

2 Answers2

8

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.

Artur Meinild
  • 31,035
6

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 +++
Raffa
  • 34,963