A partition or a disk drive’s organized collection of files is referred to as a “Linux file system.” A memory section known as a “partition” carries a particular set of data. Different memory divisions may exist in our computers. Typically, a file system is present on every partition. The Linux operating system’s built-in layer known as the file system is often utilized to manage the storage’s data. Arranging the file on disk storage is helpful. It controls a file’s name, size, creation date, and a great deal more information. So let’s dive into the depths of the Linux filesystem.
Filesystem Hierarchy Standard (FHS)
Although filesystems might differ in their organizational structure, they should generally follow the Filesystem Hierarchy Standard. By the Linux Foundation, it is kept up to date. In the FHS, regardless of whether they are stored on various physical or virtual media, all files and directories are found under the root directory /. Some of these folders are installed with certain subsystems, such as the X Window System, in order to function on a specific system. Go to the terminal and type the following to see the directories listed under the root directory.
$ ls -l /
Your results might not exactly match mine. Nonetheless, the directories should generally appear as follows:
- /root: The top-level directory in the filesystem hierarchy, beneath which everything else is nested. Every single file and directory starts in the root directory. The only root user can write in this directory.
- /bin: This directory contains the common Linux commands you’ll need to utilize in single-user modes; for all users, e.g., cat, ls, cp.
- /boot: Contains kernel boot loader files.
- /dev : Essential device files, e.g., /dev/null.
- /etc: The core system Configuration directory, should hold only configuration files and not any binaries. Additionally, this provides shell scripts for program starting and termination.
- /home: Personal directories for users, hold your documents, files, settings, etc.
- /lib: Holds library files that binaries can use.
- /media: used as a point of attachment for portable storage devices like USB drives.
- /mnt: Temporarily mounted filesystems.
- /opt: bundles of optional application software. Contains supplemental programs from various suppliers. Applications for add-ons ought to be installed in the /opt/ or /opt/subdirectory.
- /tmp: Storage allocated for temporary files
- /usr: Unfortunately, despite its name, this rarely contains user files in the sense of a home folder. Although this is intended for user-installed applications and utilities, personal folders may still be added. There are subdirectories for /usr/bin, /usr/local, etc. inside of this directory.
Other than that, there are also some additional directories that are listed under the root directory such as /proc, /run, /sbin, /var.
Filesystem implementations come in a wide variety. Some support bigger capacity storage, while others can only function with less capacity storage, and some are quicker than others. We’ll go into detail about the numerous kinds of filesystems that exist and how they organize data differently. The kernel makes it possible to get in touch with the filesystem for the users. Users run different kinds of commands based on their necessity. As there are many types of filesystems available, you might guess that there should be a common way to interact with the filesystem regardless of its type. And yes, you have guessed it right. It is called a virtual file system. Applications can work with any filesystem since there is a layer (virtual filesystem) between them and the various filesystem types. Now, let’s talk about some common filesystems available on Linux.
- EXT4: The file system Ext stands for Extended File System. The native Linux filesystems are now running at this most recent version. The earlier ext2 and ext3 versions are compatible. File sizes up to 16 terabytes, disk volumes up to 1 exabyte, and a lot more are supported. The default option for Linux filesystems is this one.
- XFS: The XFS file system, which was created for parallel I/O processing, was seen as a high-speed version of JFS (Journaled File System). While having a huge storage server (300+ Terabyte server), NASA continues to use this file system.
- NTFS and FAT: Windows filesystems.
- Btrfs: The B tree file system is referred to as Btrfs. It is utilized for fault tolerance, comprehensive storage configuration, fun administration, and more. It does not fit the manufacturing system well.
Now it’s time to check the filesystems on your machine. Just run the command below and existing file systems on the system will be listed in the terminal.
$ df -T
Almost always is journaling included by default with the filesystem types. But you should be aware of it just in case. To grasp the fundamental idea, consider a scenario where a machine is transmitting a huge file when it suddenly loses power. If we were using a non-journaled filesystem in this situation, the file would be corrupted. The system will inspect the filesystem upon restart in an effort to fix the problem. However, depending on the size of the file, it can take some time.
In contrast, a journaled filesystem keeps a running journal to record each process. Therefore, keep a log of the file system before transferring it and mark it as finished when the process is done. As a result, the system is constantly aware of the precise condition of the process. In this way, the system’s boot time is decreased and its efficiency is raised.
Structure of a Disk
The hard disk of your system can be divided into small partitions of varying sizes. You may have seen /dev/sdb1 and /dev/sdb2. Here, /dev/sdb is the whole disk, but /dev/sdb1 and /dev/sdb2 are the partitions of the disk. It is very useful to separate and organize the data on your system.
A partition table is included on each disk, and this table informs the operating system of the disk’s partitioning. This table provides information on partition boundaries, bootable partitions, the sectors of the disk that each partition is assigned to, and more. The Master Boot Record (MBR) and the GUID Partition Table (GPT) are the two primary types of partition tables utilized. Let’s look at the basic ideas and features behind these two partition tables.
- It is able to have logical, extended, and main partitions.
- It was used as the standard partition table.
- It has a limit of four primary partitions. Primary partitions can be divided into more extended partitions. Then these extended partitions can be further divided into more logical partitions. thereby making more partitions inside the primary partitions.
- It can support disks of up to 2 terabytes.
- It has become more popular nowadays.
- There is only one type of partition that exists here. More partitions can be made from this.
- A global unique ID (GUID) is associated with every partition.
Now, let’s look at the existing partitions of your system. To do this, you have to run the following command in the terminal.
$ sudo parted -l
You can see that there are 6 partitions and a GPT filesystem being used on my system. Additionally, more specific information is provided, such as the filesystem type, location, and partition size.
It seems appropriate that we take a closer look at some actual disk partitioning applications. In this section, we’ll look at how to partition a certain disk on our system. For this, a number of utilities are available, including gparted, parted, fdisk, and gdisk, the latter of which only supports GPT and the former MBR. But for both the MBR and GPT, we may utilize parted. We will use only parted here. To launch parted let’s run the command below.
$ sudo parted
Now, we have entered into the parted tool. We can select a partition by running the following command.
$ select /dev/sda2
We can view the current partition tool by running the print command in the terminal.
We can see the partition on the disk. Now, we can make a new partition using the mkpart command.
To see the disk usage of a disk you can run the following command.
$ df -h
This will show you the used and available spaces on the disk. The ‘-h’ denotes the human-readable format.
Repair a Filesystem
Any filesystem on the computer may get damaged or corrupted for a variety of causes. Therefore, the need to repair a damaged filesystem arises. To fix it, use the “fsck” (filesystem check) command. Normally, the command is automatically performed in the background when the Linux system boots. However, occasionally your filesystem could be too damaged to perform the program. You will then need to manually execute it.
$ sudo fsck /dev/sda