Linux what is root filesystem

Root Filesystem Definition

The root filesystem is the filesystem that is contained on the same partition on which the root directory is located, and it is the filesystem on which all the other filesystems are mounted (i.e., logically attached to the system) as the system is booted up (i.e., started up).

A partition is a logically independent section of a hard disk drive (HDD). A filesystem is a hierarchy of directories (also referred to as a directory tree) that is used to organize files on a computer system. On Linux and and other Unix-like operating systems, the directories start with the root directory, which contains a series of subdirectories, each of which, in turn, contains further subdirectories, etc. A variant of this definition is the part of the entire hierarchy of directories (i.e., of the directory tree) that is located on a single partition or disk.

The exact contents of the root filesystem will vary according to the computer, but they will include the files that are necessary for booting the system and for bringing it up to such a state that the other filesystems can be mounted as well as tools for fixing a broken system and for recovering lost files from backups. The contents will include the root directory together with a minimal set of subdirectories and files including /boot, /dev, /etc, /bin, /sbin and sometimes /tmp (for temporary files).

Only the root filesystem is available when a system is brought up in single user mode. Single user mode is a way of booting a damaged system that has very limited capabilities so that repairs can be made to it. After repairs have been completed, the other filesystems that are located on different partitions or on different media can then be mounted on (i.e., attached to) the root filesystem in order to restore full system functionality. The directories on which they are mounted are called mount points.

The root filesystem should generally be small, because it contains critical files and a small, infrequently modified filesystem has a better chance of not becoming corrupted. A corrupted root filesystem will generally mean that the system becomes unbootable (i.e., unstartable) from the HDD, and must be booted by special means (e.g., from a boot floppy).

A filesystem can be mounted anywhere in the directory tree; it does not necessarily need to be mounted on the root filesystem. For example, it is possible (and very common) to have one filesystem mounted at a mount point on the root filesystem, and another filesystem mounted at a mount point contained in that filesystem.

Created April 18, 2006.
Copyright © 2006 The Linux Information Project. All Rights Reserved.

Источник

6.1 Basic Root Filesystem Structure

The top-level directories in the root filesystem each have a specific use and purpose. Many of these are meaningful only in multiuser systems in which a system administrator is in charge of many servers and/or workstations used by different users. In most embedded Linux systems, where there are no users and no administrators, the rules to build a root filesystem can be loosely interpreted. This doesn’t mean that all rules can be violated, but it does mean that breaking some rules will have little to no effect on the system’s proper operation. Interestingly, even mainstream commercial distributions for workstations and servers do not always adhere to the established rules for root filesystems.

The «official» rules to build a root filesystem are contained in the Filesystem Hierarchy Standard (FHS) introduced in Chapter 1. The document is less than 30 pages long and is fairly easy to read. If you are looking for answers or clarifications regarding the root filesystem, the FHS is probably the best place to start. Table 6-1 provides the complete list of root filesystem top-level directories and their content as specified by the FHS.

Table 6-1. Root filesystem top-level directories

Essential user command binaries

Static files used by the bootloader

Devices and other special files

System configuration files, including startup files

User home directories, including entries for services such as FTP

Essential libraries, such as the C library, and kernel modules

Mount point for temporarily mounted filesystems

Add-on software packages

Virtual filesystem for kernel and process information

Root user’s home directory

Essential system administration binaries

Secondary hierarchy containing most applications and documents useful to most users, including the X server

Variable data stored by daemons and utilities

If you are using Linux for your day-to-day work, you are already familiar with some of these directories. Nevertheless, let’s take a closer look at the content of a typical root filesystem for use in an embedded Linux system.

Читайте также:  Установка гостевой ос для windows

First, all the directories that pertain to providing a multiuser extensible environment, such as /home , /mnt , /opt , and /root , can be omitted. We could trim the root filesystem even further by removing /tmp and /var , but these omissions may jeopardize the operation of certain programs. I do not encourage such a minimalistic approach.

This discussion does not revolve around size issues, but rather functionality. In fact, omitting a directory entry changes little to the resulting root filesystem’s size. The reason I state that /home can be omitted, for example, is that even if it were present in an embedded Linux system, it would be empty, because its content, as prescribed by the FHS, is useful only in workstation and server setups.

Depending on your bootloader and its configuration, you may not need to have a /boot directory. This will depend on whether your bootloader can retrieve kernel images from your root filesystem before your kernel is booted. You will be able to decide whether you should use a /boot directory and how to use it for your target after you read Chapter 9. Of course, you can redesign the root filesystem at any later time if need be.

The remaining directories, /bin , /dev , /etc , /lib , /proc , /sbin , and /usr , are essential.

At the extreme, you could omit /proc , which is useful only for mounting the virtual filesystem that has the same name. However, it would then become very hard to understand what is happening on your target if you needed to analyze it in the field. If you are very tight for space, you can configure your kernel without /proc support, but I encourage you to enable it whenever possible.

Two of the root directories, /usr and /var , have a predefined hierarchy of their own, much like that of the root directory. We will briefly discuss these hierarchies as we populate both directories in the steps below.

Confusing Similarities

One of the most confusing aspects of the root filesystem is the apparent similarity in purpose of some directories. In particular, newcomers often ask what difference there is between the various directories containing binaries and the various directories containing libraries.

There are four main directories for binaries on the root filesystem: /bin , /sbin , /usr/bin , and /usr/sbin . The directory in which a binary is placed largely depends on its role in the system. Binaries that are essential to both users and system administrators are in /bin . Binaries that are essential to system administration, but will never be used by ordinary users, are located in /sbin . In contrast, most nonessential user binaries are located in /usr/bin and most nonessential system administration tools are in /usr/sbin .

As for the location of libraries, the rationale is similar. The libraries required to boot the system and run the most essential commands are located in /lib , while /usr/lib contains all the other libraries. Often, packages will create subdirectories in /usr/lib to contain their own libraries. The Perl 5.x packages, for instance, have a /usr/lib/perl5 directory that contains all the Perl-related libraries and modules.

A look on your Linux workstation’s own root filesystem in these directories will show you actual examples of the application of these criteria by your distribution’s designers.

To work on the root filesystem, let’s move into the directory we created for this purpose:

We now create the core root filesystem directories required for our system:

Notice that we did not create /boot . We will come back to it later and create it if it becomes necessary. Also, note that we changed the permissions for the /tmp directory to turn the «sticky bit» on. This bit in the directory permissions field will ensure that files created in the /tmp directory can be deleted only by the user that created them. Though most embedded Linux systems are single-user systems, as I said above, there are cases in which embedded applications must not run with root privileges, hence the need to follow some basic rules about root filesystem permission bits. The OpenSSH package we discuss in Chapter 10, for example, is such an application.

We can proceed with the creation of the /usr hierarchy:

On a fully featured root filesystem, the /usr directory usually contains many more entries. A simple demonstration of this is easily conducted by typing ls -al /usr on your workstation. You will find directories such as man , src , and local . The FHS contains a section addressing the layout of this directory in detail. For the purposes of most embedded Linux systems, nonetheless, the three directories we created will suffice.

The last entries to create are in the /var directory:

Here, too, this directory usually contains many more entries. Directories such as cache , mail , and spool are useful for a workstation or a server, but few embedded systems need those directories. The directories we created are the bare minimum required for the normal operation of most applications found in an embedded Linux system. Of course, if you need functionality such as web page serving or printing, then you may want to add some of the additional directories required by the applications providing this functionality. See the FHS and the documentation provided with your application to find out your actual requirements.

With the root filesystem skeleton now ready, let’s place the various software components in their appropriate locations.

Running Linux with a Different root Filesystem Structure

As I said in the previous discussion, the rules for building a root filesystem are found in the FHS. Although most Linux applications and distributions depend on these rules, they are not enforced by the Linux kernel itself. In fact, the kernel source code makes very few assumptions regarding the structure of the root filesystem. It follows from this that you could build an embedded Linux system with a very different root filesystem structure. You would then have to modify the defaults of most software packages to make them comply with your new structure. Some have taken an even more extreme approach by building embedded Linux systems without any root filesystem at all. Needless to say, I don’t encourage you to go down this path. The root filesystem rules I outlined above are recognized and agreed upon by all open source and free software developers. By building your embedded Linux system using other rules, you would be cutting yourself off from most open source and free software packages and their developers.

Источник

Linux Root Folders Explained

In this post, you will finally get the Linux root folders explained. You will learn how these folders are used by your Linux system and how you can use them.

When you open your file manager, you are usually located in your home directory. But if you go two levels up, you will see this set of directories:

This post exactly about all these directories. You can watch the video where these Linux root folders explained or continue reading below.

Linux Root folders

I won’t use the terminal here and I will show you some visual presentation. But you are of course are encouraged to open the terminal and explore all these directories. Let’s get started.

/ – The Root

Everything begins in your system from this directory. All your folders, hard drives, USB drivers, everything is located in this root folder. You cannot go above this directory.

Also, the root directory is designated by the slash sign.

The concept of the root directory may be difficult to understand for Windows users who are used to see something like disk C, disk D and disk E. In Linux, every disk is a represented as a folder that is mounted under this root directory.

This Linux Directory Structure may look like a mess, but believe me when you learn it, you will realize how much sense it makes.

/bin – Binaries

The /bin folder contains programs that are essential for the system to boot and run. So, if you destroy this folder, your system won’t boot and run.

These programs are stored in the binary format. In other words, they are not in text format. You cannot open and read the content of these programs. The advantage of such format is that a computer can read and execute these programs very fast.

/boot – Boot Files

It is easy to guess from the name. This folder is needed to boot your system. It contains the Linux kernel, initial RAM disk image for drives need at boot time, and the bootloader.

I also would like to point out that within this boot folder, you can find the grub folder that contains grub configuration files.

If you read my Arch Linux post, you should remember than I used this command to generate the GRUB configuration file.

The boot folder also contains the Linux kernel.

/dev – Device Nodes

Here, I need to introduce another important concept of Linux – everything is a file. The /dev folder contains files for all devices your Linux is able to recognize.

If you have some Linux experience, you may recall that when you mount a hard drive, you use a name such as /dev/sda1 . The sda is the name of a first hard drive recognized by your Linux kernel and it is located in the dev folder. When the disk is mounted, you see it as a folder in that mounting point.

You can also find here USB devices, CPU etc.

/etc – Configuration Files

The /etc folder comprises all system-wide configuration files and some shell scripts that are executed during the system boot. All files here are text files, so they are human readable.

If you ever did any system-wide configuration, you probably edited some files here.

For example, there is /etc/fstab file that contains a table of storage devices and their mounting points.

/home – Users’ Folder

The home directory contains a home folder for each regular user on your Linux system. For example, I have tow folders in my /home folder. ALU is my home folder. The second folder belongs to another user, whom I named User2. So, the home folder of every user is named by its username.

You have as many folders as many users you have on your system.

These users’ folders are where users store their private data such as documents, videos, picture, music etc. When you open your file manager or your terminal by default you are located in you user’s home folder. It is also often marked as

/lib – Libraries

You already know the /bin directory that contains programs, this /lin folder contains libraries required by those programs from the /bin folder.

A library is a set of functions that are shared between programs. Thus, this /lib folder is also essential for your system to work correctly.

/lost+found – Recovered Files

You will have this directory if you use the ext4 file system. Most of the modern Linux distros use ext4, so most likely you have this folder. This is a file system specific folder that is used for data recovery in case of file corruption. Unless something bad has happened, this folder should be empty on your system.

This /lost+found folder is produced on every separate partition. So, if your /home folder is on a separate partition, you should have this /lost+found folder in your home directory too.

/media – Automatic mount point

This folder is used for automatic mounting of removable media such as USB drives, CD-ROM etc. For example, if your system is configured for automatic mounting, when you insert a USB drive it will be mounted to this folder.

/mnt – Manual mount point

The /mnt folder is similar to the /media folder, it is also used to mount devices, but usually, it is used for manual mounting. You, of course, can manually mount your devices to /media , but to keep some order in your system it is better to separate these two mounting points.

/opt – Optional Software

This folder is not essential for your system to work. Usually, it is used to install commercial programs on your system. For example, my Dropbox installation is located in this folder.

/proc – Kernel Files

This is a virtual file-system maintained by the Linux kernel. Usually, you do not touch anything in this folder. It is needed only for the kernel to run different processes.

/root – Root Home

This is the home directory of your root user. Don’t mix it with the / root directory. The / directory is the parental directory for the whole system, whereas this /root directory is the same as your user home directory but it is for the root account.

If you log in as a root, you will be located in this directory by default. This is a folder for private data and account specific setting of your root account.

/run – Early temp

The /run is a recently introduced folder that is actually a temporary file-system. It is used to store temporary files very early in system boot before the other temporary folders become available.

/sbin – System Binaries

Similar to /bin this folder contains binaries for essential system tasks but they are meant to be run by the super user, in other words, the administrator of the system.

/srv – Service Data

This directory contains service files installed on your system. For example, if you installed a web-served on your Linux system, it will be located in this folder.

/tmp – Temporary Files

This is just a place where programs store temporary files on your system. This directory is usually cleaned on reboot.

/usr – User Binaries

This is probably the largest folder after your home folder. It contains all programs used by a regular user.

I would like to stop little more on sub-directories of this /usr folder.

/usr/bin contains the programs installed by your Linux distribution. There are usually thousands of programs here.

The libraries for this /usr/bin executables are located in the /usr/lib folder.

The /usr/local doesn’t have any programs by default, but if you compile and install a program system-wide it will be placed here.

The most useful folder is /usr/share . It contains all the shared data used by the programs from /usr/bin .

All default configuration files, themes, icons, wallpapers, sound files are stored here, one more folder I would like to mention here is the /usr/share/doc folder, where you can find the documentation files for programs installed on your system.

/var – Variable Files

The /var contains files that are of variable content, so their content is not static and it constantly changes. For example, this is where the log files are stored. If you don’t know, a log file is a file that records all events happening in your system while it is running. These log files often help to find out if something is not working correctly in your system.

Conclusion

Now you have some clue about all those folders in your Linux system.

Please, feel free to add anything in the comments bellow in case I missed something.

Источник

Читайте также:  Установка git astra linux
Оцените статью