Linux Disk Partitioning
Introduction
Before Linux can use a disk, the disk usually needs to be partitioned.
Partitioning divides a physical storage device into one or more logical sections called partitions.
A partition can then be used for:
- a filesystem
- swap
- LVM
- RAID
- other storage technologies
Understanding partitioning is an important Linux administration skill because storage devices are used everywhere in infrastructure environments, including servers, virtualization hosts, databases, and Kubernetes nodes.
This chapter focuses on the partitioning layer.
LVM is covered separately in the next chapter.
Disk vs Partition
A physical disk is the actual storage device.
Linux exposes storage devices through /dev.
Typical examples are:
/dev/sda
/dev/sdb
/dev/nvme0n1
A disk can contain one or more partitions.
For example:
/dev/sdb
├── /dev/sdb1
├── /dev/sdb2
└── /dev/sdb3
For NVMe devices, the naming is slightly different:
/dev/nvme0n1
├── /dev/nvme0n1p1
├── /dev/nvme0n1p2
└── /dev/nvme0n1p3
The important distinction is:
Physical disk
│
├── Partition 1
├── Partition 2
└── Partition 3
A partition is not a separate physical disk. It is a logical section of the physical device.
Inspecting Disks
Before modifying a disk, always identify the correct device.
The first command to use is:
lsblk
Example:
NAME SIZE TYPE MOUNTPOINTS
nvme0n1 238G disk
├─nvme0n1p1 1G part /boot
├─nvme0n1p2 8G part [SWAP]
└─nvme0n1p3 229G part /
sdb 931G disk
In this example:
/dev/nvme0n1
is the system disk, while:
/dev/sdb
is an additional 931 GB disk.
Never assume that a device such as /dev/sdb has the same meaning on every Linux system.
Device names can change depending on the hardware and boot environment.
For more detailed information:
sudo fdisk -l
You can also inspect a specific disk:
sudo fdisk -l /dev/sdb
Partition Tables
A partition table stores information about the partitions on a disk.
Two important partition table formats are:
- MBR
- GPT
MBR
MBR stands for Master Boot Record.
It is an older partitioning scheme with several limitations.
Among other limitations, traditional MBR partitioning supports:
- up to four primary partitions
- disks up to approximately 2 TiB when using 512-byte sectors
MBR is still encountered on older systems, but it is generally not the preferred choice for new installations.
GPT
GPT stands for GUID Partition Table.
GPT is the modern partitioning standard and is normally the preferred choice for new systems.
Advantages include:
- support for very large disks
- many partitions without the old primary/extended partition model
- redundancy of partition table information
- compatibility with modern UEFI-based systems
For new Linux systems, GPT is usually the sensible default.
A typical modern disk therefore looks like:
/dev/sdb
└── GPT
├── /dev/sdb1
└── /dev/sdb2
Partition Types
Partitions can be used for different purposes.
Examples include:
- Linux filesystem
- Linux swap
- Linux LVM
- Linux RAID
The partition type provides information about how the partition is intended to be used.
For example, an LVM partition can be marked as:
Linux LVM
A RAID partition can be marked as:
Linux RAID
This does not create LVM or RAID by itself.
It only identifies the intended purpose of the partition.
This distinction is important.
Partition type: Linux LVM
≠
Actual LVM configuration
LVM is covered in the next chapter.
Partitioning Tools
Linux provides several tools for managing partitions.
Two common interactive tools are:
fdiskparted
Both can:
- create partition tables
- create partitions
- delete partitions
- resize partitions in supported situations
- display partition information
- work with GPT
The commands and interface are different, but the final result can be the same.
parted
parted is a command-line partitioning tool designed to work with modern partition tables.
It supports GPT and provides convenient commands for specifying partition boundaries using percentages and human-readable units.
Start parted with:
sudo parted /dev/sdb
Inside parted, use:
print
to display the current partition table.
Creating a GPT Partition Table with parted
To create a new GPT partition table:
mklabel gpt
You may receive a warning that the existing partition table will be destroyed.
Confirm only if you are certain that you selected the correct disk.
For a new empty disk, this gives us:
/dev/sdb
└── GPT
Creating a Partition with parted
Create one partition using the entire disk:
mkpart primary 0% 100%
This creates:
/dev/sdb1
using the available space.
The command is convenient because the boundaries can be expressed as percentages.
For example:
mkpart primary 0% 50%
creates a partition using approximately the first half of the disk.
A second partition could then use:
mkpart primary 50% 100%
The resulting layout would be approximately:
/dev/sdb
├── /dev/sdb1 0% - 50%
└── /dev/sdb2 50% - 100%
Setting a Partition Type with parted
For an LVM partition, use:
set 1 lvm on
The number 1 refers to partition 1.
Verify the result:
print
Example:
Number Start End Size File system Name Flags
1 1049kB 1000GB 1000GB primary lvm
The lvm flag indicates that the partition is intended for LVM.
Exiting parted
Use:
quit
Then verify the result from the shell:
lsblk
You should see something similar to:
NAME SIZE TYPE
sdb 931G disk
└─sdb1 931G part
Practical parted Example
Suppose you have a new 1 TB disk at /dev/sdb and want one LVM partition covering the entire disk.
The complete interactive session can look like:
$ sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart primary 0% 100%
(parted) set 1 lvm on
(parted) print
(parted) quit
Then verify:
lsblk
At this point:
/dev/sdb
└── /dev/sdb1
is ready to be used by LVM.
The next chapter will start with:
sudo pvcreate /dev/sdb1
Parted is preferred for scripting as you can configre it directly with lines:
Build partition
# 1. Disk sdb
sudo parted /dev/sdb mklabel gpt
sudo parted /dev/sdb mkpart primary ext4 1MiB 50%
sudo parted /dev/sdb mkpart primary ext4 50% 100%
# 2. Disk sdc
sudo parted /dev/sdc mklabel gpt
sudo parted /dev/sdc mkpart primary ext4 1MiB 50%
sudo parted /dev/sdc mkpart primary ext4 50% 100%
# 3. Disk sdd
sudo parted /dev/sdd mklabel gpt
sudo parted /dev/sdd mkpart primary ext4 1MiB 50%
sudo parted /dev/sdd mkpart primary ext4 50% 100%
# 4. Set type flag
sudo parted /dev/sdb set 1 lvm on
sudo parted /dev/sdc set 1 lvm on
sudo parted /dev/sdd set 1 lvm on
Format partition
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.ext4 /dev/sdc1
sudo mkfs.ext4 /dev/sdd1
Create mount point
sudo mkdir -p /mnt/diskA
sudo mkdir -p /mnt/diskB
sudo mkdir -p /mnt/diskC
Manual mount point
sudo mount /dev/sda1 /mnt/diskA
sudo mount /dev/sdb1 /mnt/diskB
sudo mount /dev/sdc1 /mnt/diskC
fdisk
fdisk is one of the traditional Linux partitioning tools.
It provides an interactive interface where single-letter commands are used to perform operations.
Start it with:
sudo fdisk /dev/sdb
Inside fdisk, type:
m
to display the available commands.
Common commands include:
| Command | Purpose |
|---|---|
g |
Create a new GPT partition table |
o |
Create a new MBR/DOS partition table |
n |
Create a new partition |
d |
Delete a partition |
t |
Change partition type |
p |
Print the partition table |
l |
List partition types |
w |
Write changes and exit |
q |
Quit without writing changes |
Creating a GPT Partition Table with fdisk
Start:
sudo fdisk /dev/sdb
Then press:
g
This creates a new GPT partition table.
You can check it with:
p
Creating a Partition with fdisk
Press:
n
fdisk will ask for:
Partition number
First sector
Last sector
If you want one partition using the entire disk, accept the defaults:
Partition number: 1
First sector: [Enter]
Last sector: [Enter]
This creates:
/dev/sdb1
Setting the Partition Type with fdisk
Press:
t
Then select the Linux LVM type.
On current versions of fdisk, the code is commonly:
30
If you do not remember the code, use:
L
to list the available partition types.
Look for:
Linux LVM
Then use:
p
to verify the configuration.
You should see something similar to:
Device Start End Sectors Size Type
/dev/sdb1 2048 1953523711 1953521664 931.5G Linux LVM
Writing Changes with fdisk
This is an important difference between fdisk and some other tools.
The changes are not permanently written when you create the partition.
You first review the configuration with:
p
If everything is correct, write the changes with:
w
If you realize that something is wrong and want to exit without writing:
q
This makes the following workflow useful:
Create
↓
Review
↓
Write
Practical fdisk Example
For a new 1 TB disk at /dev/sdb:
$ sudo fdisk /dev/sdb
Command (m for help): g
Command (m for help): n
Partition number: 1
First sector: [Enter]
Last sector: [Enter]
Command (m for help): t
Partition type: 30
Command (m for help): p
Command (m for help): w
Then verify:
lsblk
You should see:
NAME SIZE TYPE
sdb 931G disk
└─sdb1 931G part
The partition is now ready for LVM.
Comparing parted and fdisk
Both tools are capable of performing common partitioning tasks.
| Feature | parted |
fdisk |
|---|---|---|
| GPT | Yes | Yes |
| MBR | Yes | Yes |
| Interactive | Yes | Yes |
| Human-readable boundaries | Very convenient | Sector-oriented |
| Percentage-based sizes | Yes | No |
| Partition type management | Yes | Yes |
| Common on Linux | Yes | Yes |
| Easy to learn interactively | Yes | Yes |
| Useful for scripting | Yes | Yes |
Which One Should You Use?
There is no universal winner.
Both tools are good, and learning both is valuable for Linux administration.
For interactive work, fdisk is an excellent tool to know because it is widely available and its workflow is straightforward once the commands are familiar.
parted is particularly convenient when working with GPT disks and when you want to specify partition boundaries using percentages or explicit units.
For example:
mkpart primary 0% 50%
is very convenient when describing a partition layout.
A practical approach is therefore:
fdisk
→ learn the traditional interactive Linux partitioning workflow
parted
→ learn flexible partition boundaries and modern disk layouts
You do not need to choose only one.
As a Linux administrator, being comfortable with both is more useful than treating one as universally better.
A Note About Automation
Interactive tools are excellent for learning and for manual administration.
For automation, however, you should normally avoid building scripts that depend on interactive input.
In infrastructure environments, tools such as Ansible can manage partitioning and storage declaratively.
For example, instead of manually repeating:
fdisk
n
t
w
across several servers, an automation tool can describe the desired final state.
This becomes especially useful when managing multiple machines.
The manual commands in this chapter are still important because understanding what the automation is doing is essential.
Verifying the Final Layout
After creating a partition, use several commands to verify the result.
Start with:
lsblk
For detailed partition information:
sudo fdisk -l /dev/sdb
For GPT-specific information:
sudo parted /dev/sdb print
These commands answer slightly different questions.
lsblk
→ What block devices and partitions exist?
fdisk -l
→ What is the detailed partition table?
parted print
→ What does the partition layout look like?
From Partitioning to LVM
At the end of this chapter, we have:
/dev/sdb
└── /dev/sdb1
The partition has been marked for LVM.
However, LVM itself has not been created yet.
The next step is:
sudo pvcreate /dev/sdb1
This initializes the partition as an LVM Physical Volume (PV).
The complete storage stack will then become:
Disk
│
▼
Partition
│
▼
Physical Volume
│
▼
Volume Group
│
▼
Logical Volume
│
▼
Filesystem
│
▼
Mount Point
The next chapter explains this LVM layer in detail.
Key Takeaways
Remember these core concepts:
- A disk is a physical storage device.
- A partition is a logical section of a disk.
- GPT is the modern partition table format normally preferred for new systems.
fdiskandpartedare partitioning tools.- A partition marked as
Linux LVMis prepared for LVM but is not LVM by itself. - Always verify the correct device before modifying it.
pinfdiskprints the current configuration.winfdiskwrites changes.qinfdiskexits without writing changes.partedcan conveniently express partition boundaries using percentages.- Automation should be preferred for repeatable infrastructure tasks.