Understanding Disk concept in Linux

Pradyumna DashPradyumna Dash
4 min read

So basically we all know that Linux is an open-source operating system & mostly it manages the system's hardware components like CPU, memory & storage. As the main feature of this OS is open source so nowadays it is used in most IT industries & by using this we can create our own version of the os.

Disk concept in Linux

The HDD & SDD are the disk component in Linux. The disk is used to store the data in Os. The Os configuration file, software programs & other data can store on the disk.

At the Industry level, there are different kinds of applications used in an OS & we need to store all data related to that application, so we need to create different partitions in the raw disk which is attached to our Os so that we can store the data separately.

Partitioning Of a Disk

In an Os the large storage device needs to be divided into separate sections & that is called the partitioning of the disk. By doing this we can store different files in different partitions & it won't create any clash between the files

for example, the Os configuration-related files needs to store in separate section similarly the different application-related data needs to store in different partitions. Also, we can separate the Os program files from the user files.

We can partition a disk in two ways:- MBR partitioning scheme & GPT partitioning scheme.

Before creating any partition in a disk we have reserved 4 sectors in a disk which contain all the partition-related information & the partition started from 5th sector

The first sector contains the MBR record which scheme we are following to create a partition.

The second partition contains information about LVM(Logical Volume Management), if we are using a disk as a LVM

The third partition contains the metadata & the fourth partition contains the backup of our metadata.

MBR partitioning scheme

The MBR stands for Master Boot Record which was applied for disk partition since 1982 & it is the oldest method for partitioning a disk.

By using the MBR partitioning scheme we can create a maximum of 4 primary partitions or else we can create 3 Primary partitions & 1 extended partition & in the extended partition, we can create further logical drives. In the primary partitions we can install our Os and all the Os-related configuration file can store in it & the logical partition we can use to store user & application-related data. In logical partition we can't store our Os installation files

In the MBR Partitioning scheme, we have a limitation up to 2TB for any partition.

GPT partitioning scheme

In a production environment some time we require some more storage & as MBR has a limitation with 2TB so to overcome this issue we are using the GPT partitioning scheme which stands for GUID partition Table, but the GPT partitioning scheme is attached to UEFI(Unified Extensible Firmware Interface) which was replaced version of BIOS.

For the systems which are running on UEFI firmware, GPT is the standard procedure for partitioning a physical disk but for BIOS firmware systems still MBR is the standard procedure.

The GPT partitioning scheme allows you to create 128 partitions on a disk.

So Generally we are using fdisk & parted commands for creating the partition.

Parted Command

The parted Command is used to create & remove the partitions on any storage disk. By using the parted command we can create a partition under both schemes, but first, we need to specify the partition level to the disk before creating any partition

To specify the partition label to MBR we need to write msdos along with parted command, then the disk will follow MBR partitioning scheme

Now as the partition label specified so now, we can create the partition by using mkpart command

While creating any partition the starting sector is always 2048 because the previous sector from 2048 is reserved.

Then we need to execute udevadm settle command so the system will detect the new partition on the disk

Now in same way we can create the partition under GPT partition scheme but before that we should specify the partition label on that disk.

To remove any partition we can use rm command in parted utility.

fdisk Command

fdisk is a command utility that included in all versions of MS-DOS scheme, by using fdisk command we can create, delete & manage the partitions on any storage disk.

By using fdisk command we can create multiple partition within some seconds.

fdisk -l

By using this command we can how many disks are allocated to our linux machine

Now as we can see that I have two partitions & that is /dev/sda & /dev/sdb. /dev/sda partition stored the Os files so I can start to create partitions on /dev/sdb which was empty.

As I created two partitions on my disk & we can check our partitions by exccuting lsblk command

So That's all for this my first blog!! hope you guys will be very clear what is the disk concept in Linux & how we are managing the partitions.

Stay tuned for more content on this concepts

Happy learning!!

0
Subscribe to my newsletter

Read articles from Pradyumna Dash directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pradyumna Dash
Pradyumna Dash