Partitioning Disks in Linux

In Linux, a disk partition is a logical division of a hard disk drive (HDD) or solid-state drive (SSD) that allows you to manage data in a more organized manner. Partitions enable you to separate data by function, such as isolating system files from user files, or setting up multiple operating systems on a single physical disk.

There are several tools available for creating and managing disk partitions in Linux, including fdisk, parted, and gparted. This article focuses on using the command-line utilities fdisk and parted as they are widely available on most Linux distributions and provide precise control over partitioning operations.

Understanding Disk Structure

Disk Partition Layout /dev/sda (Physical Disk) /dev/sda1 /dev/sda2 /dev/sda3 Free Space Boot (100MB) Root (200GB) Home (50GB) (38GB)

Creating a Partition with fdisk

fdisk is a command-line utility that allows you to create, delete, and modify partitions on a disk. To use fdisk, you must have root privileges.

First, list the available disks and their partitions using the fdisk -l command

sudo fdisk -l
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000dfc6f

Device     Boot   Start       End    Sectors  Size Id Type
/dev/sda1  *       2048    206847     204800  100M  7 HPFS/NTFS/exFAT
/dev/sda2        206848 500117503  499910656  238G  7 HPFS/NTFS/exFAT

In the above example, /dev/sda is the disk and /dev/sda1 and /dev/sda2 are its partitions.

To create a new partition, use the fdisk command followed by the disk name

sudo fdisk /dev/sda

Step-by-Step Partition Creation

Once in the fdisk prompt, follow these steps

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-500118191, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-500118191, default 500118191): +10G

This creates a primary partition with number 1 and a size of 10 GB. After creating the partition, write the changes to disk

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Creating a Partition with parted

parted is another command-line utility that provides more advanced partitioning capabilities, especially for modern partition table formats like GPT. It also requires root privileges.

List available disks and partitions

sudo parted -l
Model: ATA WDC WD25 00AAJS-00L (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size    Type     File system  Flags
 1      1049kB  106MB  105MB   primary  ntfs         boot
 2      106MB   250GB  250GB   primary  ntfs

To create a new partition using parted

sudo parted /dev/sda

In the parted prompt, create a partition with the mkpart command

(parted) mkpart
Partition name?  []? data
File system type?  [ext2]? ext4
Start? 0%
End? 50%

You can also create a partition with a single command

(parted) mkpart data ext4 0% 10GB

Comparison of fdisk vs parted

Feature fdisk parted
Partition Table Support MBR/DOS primarily MBR, GPT, and others
Interactive Mode Yes Yes and scriptable
Disk Size Support Up to 2TB (MBR) No practical limit
Real-time Changes No (requires write) Yes (immediate)
File System Creation No Limited support

Common Commands

Here are essential commands for both utilities

Operation fdisk parted
List partitions p print
Create partition n mkpart
Delete partition d rm [number]
Write changes w Automatic
Quit without saving q quit

Conclusion

Both fdisk and parted are powerful tools for disk partitioning in Linux. fdisk is simpler and widely used for basic MBR partitioning, while parted offers advanced features and GPT support for modern systems. Proper partitioning helps organize data efficiently and can improve system performance by separating different types of data and workloads.

Updated on: 2026-03-17T09:01:38+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements