This article explores disk partitions, file systems, external storage devices, and the Logical Volume Manager, with hands-on labs to enhance learning.
In this lesson, we explore disk partitions, file systems (including the EXT series and NFS), external storage devices (DAS, NAS, and SAN), and the Logical Volume Manager (LVM) in action. Each section is enhanced with hands-on labs to reinforce your learning.
Before diving into partitions, it’s essential to understand some basic storage concepts. A block device is typically represented as a file in the /dev directory and denotes a hardware component used for data storage. Devices such as traditional spinning hard disks and solid-state disks (SSD) are common examples. Data on these devices is accessed in fixed-size blocks.You can list the block devices on your system using the lsblk command. Additionally, using ls -l in the /dev directory and filtering for lines starting with “b” helps you identify block files.
Copy
Ask AI
$ lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 119.2G 0 disk├─sda1 8:1 0 100M 0 part /boot/efi├─sda2 8:2 0 72.5G 0 part /media/MM/Data└─sda3 8:3 0 46.6G 0 part /$ ls -l /dev/ | grep "^b"brw-rw---- 1 root disk 8, 0 Mar 19 17:43 sdabrw-rw---- 1 root disk 8, 1 Mar 19 17:42 sda1
In the above lsblk output, the device sda represents the entire disk (approximately 119GB), while sda1 through sda3 indicate the individual partitions.Each block device is assigned a major and minor number:
The major number (8 in this case) identifies the type of block device (commonly associated with SCSI devices, hence the “sd” prefix).
The minor numbers differentiate among individual physical or logical devices, such as the whole disk and its partitions.
Disk partitions allow you to subdivide an entire disk into smaller segments. In our example, the SSD disk is divided into three partitions:
Copy
Ask AI
$ lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 119.2G 0 disk├─sda1 8:1 0 100M 0 part /boot/efi├─sda2 8:2 0 72.5G 0 part /media/MM/Data└─sda3 8:3 0 46.6G 0 part /
sda3 is used as the root partition.
sda2 (72.5GB) is mounted at /media/MM/Data and is typically used for storing backup data.
sda1 is mounted at /boot/efi to store boot loader files needed during system startup.
It is possible to use a disk without partitioning; however, partitioning is generally recommended because it offers improved flexibility and organization. The partition table, which holds the partition details, can be viewed using tools like lsblk or fdisk.
Copy
Ask AI
$ lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 119.2G 0 disk├─sda1 8:1 0 100M 0 part /boot/efi├─sda2 8:2 0 72.5G 0 part /media/MM/Data└─sda3 8:3 0 46.6G 0 part /
Another useful command is fdisk, which not only lists the partition table but also allows you to create or delete partitions. Running fdisk -l /dev/sda provides detailed information such as partition type, disk size in bytes, and sector details.
The disk label type in this example is GPT (GUID Partition Table), which offers improvements over the older MBR (Master Boot Record) scheme such as support for larger disk sizes and more partitions.
Primary Partition: Used for booting an operating system. Traditionally, disks could have a maximum of four primary partitions.
Extended Partition: Acts as a container for logical partitions; it cannot be used directly.
Logical Partition: Created within an extended partition to bypass the four primary partition limitation.
A partitioning scheme, or partition table, defines how these partitions are organized on a disk. The older MBR partitioning scheme permits only four primary partitions and limits disk sizes to 2TB (unless using an extended partition). In contrast, GPT (GUID Partition Table) supports an almost unlimited number of partitions—often limited only by the operating system, such as RHEL’s limit of 128 partitions per disk—and eliminates the 2TB disk size restriction.
Unless your operating system requires MBR, GPT is generally the preferred choice due to its enhanced capacity and flexibility.
For practical experience, Mohan grants Bob access to a lab machine. Bob’s system contains two disks: one (SDA) with existing partitions and another (SDB) that is unpartitioned. Running lsblk clearly indicates the unpartitioned state of SDB:
Since SDB is unpartitioned, Mohan instructs Bob to create a new partition using the gdisk command—an improved alternative to fdisk that supports GPT.
Copy
Ask AI
$ lsblkfd0 2:0 1 4K 0 disksr0 11:0 1 1024M 0 romsda 8:0 0 97.7G 0 disk|-sda1 8:1 0 93.7G 0 part /|-sda2 8:2 0 1K 0 part|-sda5 8:5 0 3.9G 0 partsdb 8:15 0 20G 0 disk$ gdisk /dev/sdbGPT fdisk (gdisk) version 1.0.1Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help):
Within the gdisk interface, type ? to view all available commands. To add a new partition, press n and follow the interactive prompts:
Copy
Ask AI
Command (? for help): ?b back up GPT data to a filec change a partition's named delete a partitioni show detailed information on a partitionl list known partition typesn add a new partitiono create a new empty GUID partition table (GPT)p print the partition tableq quit without saving changesr recovery and transformation options (experts only)s sort partitionst change a partition's type codev verify diskw write table to disk and exitx extra functionality (experts only)? print this menuCommand (? for help): nPartition number (1-128, default 1): 1First sector (34-419430006, default = 2048) or {+-}size{KMGT}: 2048Information: Moved requested sector from 34 to 2048 in order to align on 2048-sector boundaries.Use 'l' on the experts' menu to adjust alignmentLast sector (2048-419430006, default = 419430006)Current type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300):Changed type of partition to 'Linux filesystem'Command (? for help):
After providing the partition details and confirming with the default hex code (8300 for Linux filesystem), finalize the changes by writing the new partition table to disk. Press W at the prompt:
Copy
Ask AI
Command (? for help): WFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!Do you want to proceed? (Y/N): YOK; writing new GUID partition table (GPT) to /dev/sdb.The operation has completed successfully.
The new partition (/dev/sdb1) is now available. Verify the partition creation using lsblk or fdisk -l.
This article covered the fundamentals of block devices, disk partitions, partitioning schemes (MBR and GPT), and demonstrated how to create a new partition using gdisk. For more detailed exercises and troubleshooting—such as addressing why Bob’s system might not display the full physical disk size—please consult the hands-on labs.For additional resources, consider exploring the following: