• Post author:Bhaskar Soni
  • Post published:
  • Post category:Linux
  • Post comments:2 Comments
  • Reading time:3 mins read

A partition is a separate section of a disk that the operating system treats as its own unit. Partitioning lets you keep the operating system, user data and swap apart, use different file systems or install more than one OS. This guide explains partition tables and types, then shows how to create a disk partition in Linux step by step.

disk partition in Linux

Why partition a disk?

  • Separate system files from data, so reinstalling the OS keeps data safe.
  • Stop log files or user data from filling the root file system.
  • Use different file systems or mount options for different purposes.
  • Dual-boot several operating systems.

Partition tables: MBR vs GPT

FeatureMBRGPT
Maximum disk size2 TiB (with 512-byte sectors)Practically unlimited (zettabytes)
Number of partitions4 primary, or 3 primary + 1 extended128 by default
FirmwareLegacy BIOSUEFI (and BIOS with a small boot partition)
RedundancySingle partition tableBackup table at the end of the disk

GPT is the modern standard. Use it for new systems unless you must support very old hardware.

Primary, extended and logical partitions

On MBR disks, you can have at most four primary partitions. To get more, one of them can be an extended partition, which holds several logical partitions. GPT does not need this workaround.

Partition naming in Linux

  • SATA and SAS disks: /dev/sda, partitions /dev/sda1, /dev/sda2.
  • NVMe drives: /dev/nvme0n1, partitions /dev/nvme0n1p1.
  • Virtual disks: often /dev/vda or /dev/xvda.

Step-by-step: create a partition

In this example, /dev/sdb is a new, empty disk. Warning: partitioning the wrong disk destroys data, so check carefully with lsblk.

1. List disks

lsblk
sudo fdisk -l

2. Create a GPT partition table and partition with parted

sudo parted /dev/sdb --script mklabel gpt
sudo parted /dev/sdb --script mkpart data xfs 0% 100%

Alternatively, use fdisk /dev/sdb interactively: press g for a new GPT table, n for a new partition, accept the defaults and press w to write.

3. Create a file system

sudo mkfs.xfs /dev/sdb1
# or: sudo mkfs.ext4 /dev/sdb1

4. Mount the partition

sudo mkdir -p /data
sudo mount /dev/sdb1 /data
df -h /data

5. Mount it automatically at boot

Find the UUID with blkid /dev/sdb1, then add a line to /etc/fstab:

UUID=your-uuid-here  /data  xfs  defaults,nofail  0 0

Run sudo mount -a to test. The nofail option lets the system boot even if this disk is missing.

Common file systems

File systemBest for
ext4General purpose; default on many distributions
XFSLarge files and servers; default on RHEL-family systems
BtrfsSnapshots, checksums and compression
vfat (FAT32)EFI system partition and USB drives

Partitions vs LVM

Plain partitions are simple, but resizing them is hard. LVM adds a flexible layer on top, so you can grow volumes online. See how to create an LVM partition.

Related guides

Sources

Running Linux servers in production? Our Linux server hardening & security audit checks configuration, patching, SSH and logging. You can also use our free Linux server hardening checklist, or contact us.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

This Post Has 2 Comments

Leave a Reply