1. Overview
In Linux, directories are structured in a tree-like hierarchy. This well-defined directory structure provides easy isolation and identification of data. In this article, we’ll briefly discuss what a filesystem is in Linux. Then, we’ll take a deeper look at the root filesystem (rootfs) and see what it contains.
2. What Is a Filesystem in Linux?
In Linux, the filesystem provides a structural way to store and access our files from the system storage. Linux follows the Filesystem Hierarchy Standard (FHS) as a reference. The FHS defines the structure of the filesystem. In other words, it defines the main directories and their contents.
Linux has various types of filesystems:
- Ext (Extended Filesystem), Ext2, Ext3, Ext4
- JFS (Journaling Filesystem)
- ReiserFS
- XFS (Extent Filesystem)
- Btrfs (B Tree Filesystem)
- Swap
3. What Is the Root Filesystem?
The root filesystem is at the top of the hierarchical file tree (also known as ‘/’). The Linux kernel directly mounts rootfs through the configuration argument ‘*root=*‘. The root filesystem also has mount points where we can mount other filesystems as well in order to connect them to this filesystem hierarchy. It has a number of directories containing files critical for booting the system and system operations.
4. Contents of rootfs
4.1. /bin
The /bin directory contains binaries of essential user commands that can be used by all users of the system. Here we can find ready-to-execute Linux commands like ls, cp, and echo, and shells like bash and csh. Moreover, /bin also contains the ready-to-run executables that may be required in order to boot or repair a system.
4.2. /boot
In the /boot directory we can find files used for booting an operating system, usually kernel images, bootloader (for example LILO, GRUB) related files, configuration files, and map installer. Generally, we can find vmlinuz, System.map, initrd, and config files here. Among them, vmlinuz is our actual kernel. The bootloader loads this kernel and executes it. The System.map file has a list of kernel symbols and respective addresses. The initial ramdisk (initrd) file is useful in loading drivers that are necessary for the initial booting process. The config file contains a list of kernel options, a list of devices, and device options.
4.3. /dev
The /dev directory is where all device files are stored. The device files residing in this directory represent devices attached to our system. Applications can interact with them using system calls to perform I/O operations. The majority of the device drivers that correspond to the hardware devices are one of two types: block device drivers or character device drivers.
4.4. /etc
Configuration files specific to the local machine are contained in the /etc directory. This directory holds most global config files. However, larger software packages can have their own subdirectories under /etc. Some examples are /etc/X11, /etc/sgml, and /etc/xml.
4.5. /home
The /home directory is the default location to create home directories for different users. For example, let’s say there’s a user with the username “Sam“. Then, the default home directory of Sam will be /home/Sam. In other words, directories under /home provide a personal workspace to regular users who don’t have root privileges.
4.6. /lib
The /lib directory contains essential shared libraries for system boot. Device drivers necessary for system boot are placed under subdirectory /lib/modules/’kernel-version’. It also contains the libraries needed by binaries from /bin and /sbin to run the commands in the root filesystem.
4.7. /media
The /media directory contains subdirectories that are utilized as mount points when we connect any removable media devices to the system. We can find subdirectories or symbolic links to directories representing different removable media devices like CD-ROMs and USB sticks. For example, on inserting a CD into our Linux system, a directory will automatically be created inside the /media directory. We can use this to access the contents of the CD inside this directory.
4.8. /mnt
The /mnt directory is a mount point where we can mount a temporary filesystem that resides on a storage device like a hard-disk drive, USB stick, or CD-ROM. Unlike /media, where the system mounts removable media automatically, under /mnt we need to mount manually. This directory can be empty or may have subdirectories to mount individual devices.
4.9. /opt
The /opt directory contains optional software packages. In this context, optional software packages are those that are not part of the system — for instance, third-party software that we install as add-ons.
4.10. /root
The /root directory is the home directory of the root user of the system.
4.11. /run
The /run directory stores the system information data describing the system since its booting. Applications store their transient files like process IDs, socket descriptors, and more in this directory.
4.12. /sbin
Similar to the /bin directory, the /sbin (system binaries) directory contains ready-to-run executables needed to boot our Linux system. However, unlike /bin binaries, /sbin contents are intended to be executed by the root user.
4.13. /srv
The /srv directory has service data. In other words, site-specific data served by our system is likely to be stored here. For instance, if we’re using an HTTP server to serve a website, then we may store files related to our website inside this directory.
4.14. /tmp
The /tmp directory contains files that are temporary. Many of these files are created by currently running processes on our system that store their temporary data under this directory. Therefore, a clearing out of this directory may happen at booting or at system shutdown.
4.15. /usr
The /usr directory contains executables and read-only data. In contrast with files that are used by the system, files under this directory are used by users. So, /usr/sbin and /usr/bin directories contain non-essential /bin and /sbin binaries, respectively. The default installation location for locally compiled applications is under /usr/local.
4.16. /var
The /var (variable) directory contains transient files and temporary files whose size may change. We can find a number of spools and log files here.
5. Conclusion
In this article, we discussed the filesystem of Linux. We explored the top of the filesystem hierarchy and a number of subdirectories beneath it.