1

I am trying to wrap my head around filesystems in Linux, but there is still something that I do not understand. So far, what I got right is that a filesystem is the set of methods and data structures for retrieving a file from a partition of a volume. Filesystems can be listed by the Linux command df So far, so good.

Additionally, Linux creates synthetic file systems as proc that appears to be a regular filesystem to non-file objects. An example is the proc filesystem. Synthetic filsystem can be listed with the df command if we add the flag -a.

Now the question: why is then the /usr/ folder called a filesystem (https://tldp.org/LDP/sag/html/usr-fs.html)? To me, it seems just a folder that belongs to the root file system. So why people call it a filesystem?

Additionally, why people say that the root file system should be small (https://tldp.org/LDP/sag/html/root-fs.html)?

Indeed if I call df command:

Filesystem     1K-blocks      Used Available Use% Mounted on
udev            32866696         0  32866696   0% /dev
tmpfs            6578976      2484   6576492   1% /run
/dev/nvme0n1p5 959862832 101610168 809424504  12% /
tmpfs           32894876    109020  32785856   1% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs           32894876         0  32894876   0% /sys/fs/cgroup
/dev/loop1         56704     56704         0 100% /snap/core18/1885
/dev/loop2        261760    261760         0 100% /snap/gnome-3-34-1804/36
/dev/nvme0n1p1    523248         4    523244   1% /boot/efi
/dev/loop3         63616     63616         0 100% /snap/gtk-common-themes/1506
/dev/loop4         51968     51968         0 100% /snap/snap-store/481
/dev/loop5         31744     31744         0 100% /snap/snapd/9721
/dev/loop6         30720     30720         0 100% /snap/snapd/8542
/dev/loop7        223232    223232         0 100% /snap/gnome-3-34-1804/60
/dev/loop8         51072     51072         0 100% /snap/snap-store/467
tmpfs            6578972        20   6578952   1% /run/user/125
tmpfs            6578972        40   6578932   1% /run/user/1000
/dev/sda1       30702592   2498400  28204192   9% /media/tommaso/USB
/dev/loop9         56704     56704         0 100% /snap/core18/1932

It seems that the root filesystem actually includes everything on my computer, so why should it be small?

2
  • 1
    Did you also read the Background chapter?
    – Kusalananda
    Nov 4, 2020 at 17:24
  • 1
    In particular the sentence which says “Although the different parts have been called filesystems above, there is no requirement that they actually be on separate filesystems.” Nov 4, 2020 at 17:26

2 Answers 2

2

The rationale is given in the background section. It was relevant up to the mid-to-late 2000s, but is no longer relevant these days.

The reason to make /usr a separate filesystem is to keep the root filesystem small. The /usr directory tree is for installed software.

  • Installed software doesn't change often, so you can mount /usr read-only. The root filesystem typically can't be mounted read-only because /etc usually needs to be modified fairly often¹. The main advantage of keeping /usr read-only is to avoid a long filesystem check if the system crashes while it's mounted read-write. This is no longer relevant with modern filesystem that have a journal or other mechanism that let them recover directly from a crash.

  • Installed software can be identical on a park of identical machines, so /usr can be read-only and if you have a local network, you can store it on a single server and have the other machines mount it. It's more complicated to boot from a root filesystem that's over the network (relies on more bootloader and kernel support, makes the machine completely unusable if the network is down). This was common back when /usr might cost $200 worth of disk space, and is irrelevant these days when it only costs a few cents.

So nowadays /usr is rarely a separate filesystem, and it's even become more and more common to just make /usr a symbolic link to /.

¹ On Linux at least this isn't as true nowadays as it used to be: the main culprit was /etc/mtab, which used to be a regular file, but nowadays /proc/mounts is good enough to serve as /etc/mtab and so /etc/mtab is usually a symbolic link to it). However new culprits have arisen, for example Cups and NetworkManager like to update files containing a time stamp of when they last saw a printer/network.

3
  • Thank you! Just another small question, as the link you point me to, it seems like we are mounting filesystems (such as /usr) into other filesystems (the root / filesystem). Is it correct? Nov 5, 2020 at 8:23
  • 1
    @TommasoBendinelli Yes. Apart from the root filesystem, every filesystem is mounted on a directory which has to be on some other filesystem. Nov 5, 2020 at 8:54
  • There's actually another reason why it used to be. Read-only / on early boot wasn't always a thing the kernel knew how to do, so fsck had to run with a / mounted write enabled. The smaller that partition, the better. But that's truly ancient history now.
    – Joshua
    Feb 22 at 4:05
0

You're reading a very old manual which is in some ways deprecated.

In the past for some Unix'es there used to be a separate /usr mount point and the rest of the files (/bin /etc /root /usr /sbin) - were required only for successful booting.

Nowadays, Linux distros are getting rid of /bin /sbin and /lib and moving everything in them to /usr/{bin,sbin,lib} which means that /usr (along with /etc /root and /var) is well positioned to belong to the root filesystem.

Modern Linux'es in 2020 feature this hierarchy:

/bin     -> /usr/bin
/boot     : a separate FS for storing kernel images and initial ram disks
/boot/efi : an EFI system partition - not specific to Linux
/dev      : tmpfs
/etc
/home
/lib     -> /usr/lib
/lib64   -> /usr/lib64
/media
/mnt
/opt
/proc      : virtual fs
/run       : tmpfs
/sbin     -> /usr/sbin
/sys       : virtual fs
/tmp       : tmpfs
/usr
/var

So at the very least you're obliged to have a filesystem for / and /boot. However no one stops you from putting any other prefixes into their own separate filesystems.

It's a good practice however to:

  • have /home as a separate FS because it will allow you to switch distros easily
  • maybe have /var/lib/{mysql|postgres|something else} as a separate FS to increase speed and decreased fragmentation
  • some people choose to install proprietary large applications into /opt or /usr/local which could warrant a separate FS

That's it.

3
  • 1
    Does /boot really have to be a separate file system? It isn’t on some of my systems. /var has been a symlink to /usr/var for a long time in many distros too. Nov 4, 2020 at 19:39
  • I'm not sure it's required but I create it out of habit. If I'm not mistaken Fedora and RHEL/CentOS create it automatically on EFI enabled systems. Nov 4, 2020 at 23:14
  • It used to be that certain systems for loading the kernel into RAM and executing it could only read from the first 1024 cylinders of a disc, so in order to ensure that the kernel would reside there, people made a small boot at the start of the disc. This isn't a relevant concern with current hardware and software.
    – Agrajag
    Jun 7, 2023 at 9:30

You must log in to answer this question.

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