Linux: How to Work with the Linux File System

Home /

Table of Contents

Linux filesystem

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 /

 0Y zB8A55YYDG4ez4iJ4wnoVnskO4NUmA87ZR7yWHq9 A bxgEl7uNMHQTX roLdvKLRxRwuxGcjnaSbotwHkESCaySJrZYX73SyGG9 X3HaLgZAXDrVWFnHfH WLW YyIh52 iw66ErDnuEPhuuHzzvrVKR5OsW8 - Linux: How to Work with the Linux File System

Your results might not exactly match mine. Nonetheless, the directories should generally appear as follows: 

Ew C9LEhm94 JeTpkGH8mH30yj4Gtg4anJzmHYmDHqZso7leWiVUTLCy02UtFMEti2sBLA8hhPy1CfOlR5c6eDtKBHll6Ru2AEutD1OgEsv7DhuvjN3P7NjSBwRM7wmty c0UsGIAYmmFuSzFkdydP0MYuSD961QKKvyEoznhS5EzYc 31mDBgwMGg - Linux: How to Work with the Linux File System

  1. /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. 
  2. /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. 
  3. /boot: Contains kernel boot loader files.
  4. /dev : Essential device files, e.g., /dev/null.
  5. /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.
  6. /home: Personal directories for users, hold your documents, files, settings, etc.
  7. /lib: Holds library files that binaries can use.
  8. /media: used as a point of attachment for portable storage devices like USB drives.
  9. /mnt: Temporarily mounted filesystems.
  10. /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.
  11. /tmp: Storage allocated for temporary files
  12. /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 Types

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. 

UhXSGNFoV6RHiFAtUb7vIVoO0GovE4cqAp2H7aMBNVklxQrxSXG8toYWMJa1D - Linux: How to Work with the Linux File System

  • 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


CpsTIZrSnWod7vxeX9l1DHNhSEQO4Z6kOxXC2guezPIj2FBUfYvrb2Jd1zD03GRuUDLwLX5 R8p9IrcAfCpjzLsMdYC13lTZCUvXdjkBhgpypPY77aNS5FvIjQSkz1Asgymik - Linux: How to Work with the Linux File System

Journaling

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. 

Partition Table

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.

MBR:

  • 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. 

GPT:

  • 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
hOQXaB 9N9Ak3iP 7vJh29bfJM42G0ZQOal q3oiS66dcAwbSVQN1VI0QtCK0R vFxq09T 4D4FdrldP3UdAbdGU Tu62lN 9qCax2DAaQJDJRV1ZWFzX 2TZJ eXh0lY3QbNV7X2kHG Myp0dUTbH970 QzHDg2fUjrISUX9w FFAwfVm4dpKwYIQ - Linux: How to Work with the Linux File System

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. 

Disk Partitioning

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 
YdnTXPZHXNr9FdYDDKO nbxfGLTBaw5LVBCjiT4sIDm2NC9BdVp7nnYTguP YyIesk Ky1JquUakiKa2fRs23nXiD8Vngq4D0HD2H7Tgz01aUZI0rl2J 82uRfeZyiuZR 9YQIi3w0b UeHnsyGw8mb22awFoUaqiv 2io1Ohe4coyL87zYMlk2hYg - Linux: How to Work with the Linux File System

Now, we have entered into the parted tool. We can select a partition by running the following command.

$ select /dev/sda2


USQHCc5HcMJH05nStx0RtsoN7eJaXkufkteUPivhCULz6n8H7oX DWoLaE8daD3Xp7zUrQRo - Linux: How to Work with the Linux File System

We can view the current partition tool by running the print command in the terminal.

$ print 


Gx4Sp F4fzEdMMxeM7ru8jBoHMzAuq753YpTOLNh9WAiQbvo zuvSFpMCOxFrAbUw8dIpBJyuFwvVTGusSzUZHwXJOiuiZcqFvH5mC7ZUUfLFPbwJLwObtT1Nl8hcnjlSBduwgHTjp4RNxITEBye0goaj - Linux: How to Work with the Linux File System

We can see the partition on the disk. Now, we can make a new partition using the mkpart command. 

Disk Usage

To see the disk usage of a disk you can run the following command.

$ df -h 


- Linux: How to Work with the Linux File System

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 
Share The Tutorial With Your Friends
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Check Our Ebook for This Online Course

Advanced topics are covered in this ebook with many practical examples.

Other Recommended Article