2

I have a question about symlinks in (or very close to) the root directory. My kernel version is 5.16.11-arch1-2 at the moment.

When I run ls -l / it prints this:

lrwxrwxrwx   1 root root    7 Dec  6 21:41 bin -> usr/bin
drwxr-xr-x   4 root root 4096 Dec 31  1969 boot
drwxr-xr-x  21 root root 4040 Mar  4 08:33 dev
drwxr-xr-x   1 root root 2932 Mar  4 11:59 etc
drwxr-xr-x   1 root root   18 Jan 17 17:53 home
lrwxrwxrwx   1 root root    7 Dec  6 21:41 lib -> usr/lib
lrwxrwxrwx   1 root root    7 Dec  6 21:41 lib64 -> usr/lib
drwxr-xr-x   1 root root   32 Mar  2 10:00 mnt
drwxr-xr-x   1 root root   46 Mar  3 09:35 opt
dr-xr-xr-x 290 root root    0 Mar  4 08:33 proc
drwxr-x---   1 root root  206 Feb 26 16:37 root
drwxr-xr-x  21 root root  540 Mar  4 08:33 run
lrwxrwxrwx   1 root root    7 Dec  6 21:41 sbin -> usr/bin
drwxr-xr-x   1 root root   16 Feb 28 07:34 snaps
drwxr-xr-x   1 root root   14 Jan 17 15:26 srv
drwxr-xr-x   1 root root   16 Jan 17 13:30 swap
dr-xr-xr-x  13 root root    0 Mar  4 08:33 sys
drwxrwxrwt  19 root root  480 Mar  4 12:15 tmp
drwxr-xr-x   1 root root  116 Mar  3 12:37 usr
drwxr-xr-x   1 root root  106 Mar  4 11:18 var

Nothing abnormal here. However I want to focus on these symlinks:

lrwxrwxrwx   1 root root    7 Dec  6 21:41 bin -> usr/bin
lrwxrwxrwx   1 root root    7 Dec  6 21:41 lib -> usr/lib
lrwxrwxrwx   1 root root    7 Dec  6 21:41 lib64 -> usr/lib
lrwxrwxrwx   1 root root    7 Dec  6 21:41 sbin -> usr/bin

My understanding of symlinks has always been to always use absolute paths. This raised my attention because these symlinks (which were created by Arch upon installation) appear to be relative, not absolute.

Why would you make relative symlinks in the root directory, when you could just make it absolute by prefixing it with a /?

1
  • My understanding of symlinks has always been to always use absolute paths. Where have you read that? The general opinion is rather to prefer relative symlinks as they are more transportable. See for instance the symlinks utility that can fix absolute symlinks by converting them to relative. Mar 4, 2022 at 22:29

1 Answer 1

5

One advantage of relative symlinks, even in the root directory, is that they produce the expected result even when the file system is mounted elsewhere. This can be useful when repairing a system, or even when building one.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .