Partitioning is the process of dividing storage drives into distinct sections for better data management. In Linux, there are commands to view Partition information, as well as commands to deal with Partition management.

CommandDescription
lsblkProvides a high-level view of block devices, partitions, and mounts
blkidRetrieves detailed metadata, including UUID, labels, etc. from storage
fdisk/gdiskCreate and edit partition tables on MBR and GPT disks
partedA utility for working with large, complex disks
growpartA command used to expand the size of an existing partition

Partition information

lsblk

Displays a structured view of block devices, such as HDD, SSD, partitions, and mounts.

Example

lsblk -f will provide a table with detailed information about the name of a device, its partitions, the filesystem type, the UUID of each partition, and the mountpoint of that partition.


NAME        FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
zram0       swap   1     zram0 3051e27f-7522-4d73-aa75-5c559234fd63                [SWAP]
nvme0n1
├─nvme0n1p1 vfat   FAT32       39C7-3E50                             688.8M    33% /boot
└─nvme0n1p2 btrfs              83325285-9a7e-4f4b-ac2a-2798baf58135  535.9G    42% /home
                                                                                 /var/cache/pacman/pkg
                                                                                  /var/log
                                                                                 /

blkid

While lsblk provides an overview of devices and mount points in the system, blkid provides specific details about block devices, including their UUIDs, fs-types, and partition labels:

Example

sudo blkid /dev/nvme0n1p1 will provide information about the nvme0n1p1 partition of the nvme0n1 drive (which can be found using lsblk). The output will look something like the following:

/dev/nvme0n1p1: UUID="39C7-3E50" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="f9bfc4f6-01"

fstab

The File System Table, also known as the fstab, is used to defines and configure how filesystems, partitions, and network drives are mounted at boot time or upon access.

Partition management

fdisk/gdisk

These commands are used to create, delete, and edit MBR and GPT partitions respectively.

Example

To create a new MBR partition on a specific device, such as /dev/sda we might do the following:

sudo fdisk /dev/sda

This leads to an interactive prompt with detailed information and steps on how to manage the partition.

Note

gdisk functions in a very similar way.

parted

Parted can also be used to select a disk, create a partition, print partition tables, resize, and remove. It functions with CLI arguments:

Example

Supposing you want to create a 20GB partition in the /dev/sdb disk, you might run the following:

sudo parted /dev/sdb mkpart primary ext4 1MiB 20GiB

This creates a new ext4 partition starting at 1 MiB and ending at 20GiB.

You can also used to to create a partition with a specified label:

sudo parted /dev/sdX mklabel aix|amiga|bsd|dvh|gpt|loop|mac|msdos|pc98|sun

Important

parted is particularly useful when managing large disks and GPT paritions, since it allows non-destructive resizing.

growpart

Although parted is able to resize disks, growpart is a more specialized tool used for extending partitions, particularly useful in cloud environments and VMs.

Important

growpart does not create or delete partitions: all it does is extend an existing partition to fill available space

Example

To extend partition n from sdX to fill empty space until end of disk or beginning of next partition:

sudo growpart /dev/sdX n

The output from growpart will be something like:

CHANGED: partition=n start=2048 old: [50G] new: [100G]