How to Manage Disk Partitions on Linux
Learn to create, resize, and format Linux disk partitions using fdisk and parted, covering GPT, ext4/xfs/btrfs filesystems, fstab, and safe resizing procedures.
Before you start
- ▸Root or sudo access on the target system
- ▸A spare disk or unallocated space (do not practice on your system disk without a backup)
- ▸Basic familiarity with the Linux terminal and block device naming
Disk partitioning is one of those skills every serious Linux user needs. Whether you're adding a second drive, repurposing old hardware, or carving up a fresh NVMe for a new install, knowing how to partition correctly—and safely—saves hours of pain later. This guide covers the full workflow: inspecting disks, creating and resizing partitions with fdisk and parted, formatting with modern filesystems, and mounting persistently via /etc/fstab.
Warning: Partition operations on the wrong device destroy data instantly and irreversibly. Double-check every device path before running any write command.
Identify Your Disks
Before touching anything, get a clear picture of the current layout. lsblk is the fastest way:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,LABEL
Output will vary, but you'll see devices like sda, nvme0n1, or vda with their partitions indented beneath them. For low-level detail including partition table type and disk identifiers:
sudo fdisk -l
NVMe drives follow a different naming convention: the disk is /dev/nvme0n1 and its partitions are /dev/nvme0n1p1, /dev/nvme0n1p2, and so on. SATA/SCSI disks use /dev/sda, /dev/sdb, etc.
Choosing a Partition Table Type
New disks need a partition table before they can hold partitions. Use GPT for any disk larger than 2 TB, any disk that will boot on a UEFI system, or essentially any modern use. The older MBR (DOS) table is only necessary for legacy BIOS boot compatibility on very old hardware.
Partitioning with fdisk
fdisk is interactive and ships on every distro. It writes nothing until you explicitly confirm, making it safer to explore. It handles both MBR and GPT tables (GPT support was added around util-linux 2.23; all current distros have it).
Launch fdisk on the target disk
sudo fdisk /dev/sdb
You'll drop into an interactive prompt. Key commands: p prints the current layout, g creates a new GPT table, n adds a new partition, d deletes one, t changes the partition type, w writes changes and exits, q quits without saving.
Create a new GPT table and partition
# Inside fdisk:
# g — create GPT table (destroys existing data)
# n — new partition
# 1 — partition number
# (press Enter to accept default first sector)
# +50G — size; or press Enter to use remaining space
# w — write and exit
After writing, the kernel may not immediately see the new table. Force a re-read:
sudo partprobe /dev/sdb
Partitioning with parted (Scripted / Large Disks)
parted supports disks beyond 2 TB natively, accepts non-interactive (scripted) commands, and is the tool of choice when you need to automate provisioning. gdisk is another GPT-focused option, but parted is more universally available.
Non-interactive example: format and partition a fresh disk
sudo parted /dev/sdb --script mklabel gpt
sudo parted /dev/sdb --script mkpart primary ext4 1MiB 100%
The 1MiB start point ensures proper alignment on SSDs and NVMe drives. Never start a partition at sector 0 or at 0B with parted on modern hardware.
Inspect the result
sudo parted /dev/sdb print
Creating Filesystems
A partition is just raw space until you put a filesystem on it. Pick based on your use case:
- ext4 — rock-solid default for most data partitions and boot volumes.
- xfs — excellent for large files and high-throughput workloads; default on RHEL/Fedora.
- btrfs — built-in snapshots and checksums; useful for desktops and Fedora/openSUSE workstations.
- vfat/FAT32 — required for EFI System Partitions (ESP).
# ext4
sudo mkfs.ext4 -L mydisk /dev/sdb1
# xfs
sudo mkfs.xfs -L mydisk /dev/sdb1
# btrfs
sudo mkfs.btrfs -L mydisk /dev/sdb1
# FAT32 (for ESP)
sudo mkfs.vfat -F32 /dev/sdb1
The -L flag sets a human-readable label, which you can use in fstab instead of a UUID.
Mounting and Persistent fstab Entries
Get the UUID
Always use UUID (or PARTUUID for GPT) in /etc/fstab—device names like /dev/sdb1 can change after a reboot if you add or remove drives.
sudo blkid /dev/sdb1
Create a mount point and mount
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
Add to /etc/fstab for persistence
# Add a line like this to /etc/fstab (replace UUID with your own):
# UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890 /mnt/data ext4 defaults,noatime 0 2
The last two fields are dump (set to 0) and fsck pass order (1 for root, 2 for other, 0 to skip). Test the entry before rebooting:
sudo mount -a
If that produces no errors, your fstab entry is valid.
Resizing Partitions and Filesystems
Resizing is a two-step process: resize the partition first, then the filesystem. Always back up before resizing. Growing is generally safe; shrinking carries real risk of data loss if done in the wrong order.
Growing a partition and filesystem (ext4 example)
If you've extended the underlying disk (common in VMs), use parted to expand the partition to fill available space:
# Unmount first (or use --no-fsck for online resize if supported)
sudo umount /mnt/data
# Resize partition to use all remaining space
sudo parted /dev/sdb resizepart 1 100%
# Re-read partition table
sudo partprobe /dev/sdb
# Resize the ext4 filesystem to fill the partition
sudo resize2fs /dev/sdb1
XFS can only grow, never shrink, and supports online resize: sudo xfs_growfs /mnt/data (mountpoint, not device).
Shrinking a partition (ext4 only)
Shrink the filesystem first, then the partition. Reversing this order corrupts data.
sudo umount /mnt/data
sudo e2fsck -f /dev/sdb1
sudo resize2fs /dev/sdb1 20G # shrink filesystem to 20G
sudo parted /dev/sdb resizepart 1 21G # shrink partition slightly larger
Leave a small buffer (a few hundred MiB) between the filesystem size and the partition end.
Verification
lsblk -f
df -hT /mnt/data
lsblk -f shows filesystem type, label, UUID, and mountpoint at a glance. df -hT confirms the available space and filesystem type as seen by the OS.
Troubleshooting
"Device or resource busy" on umount
Something is using the mountpoint. Find and kill the process:
sudo fuser -mv /mnt/data
sudo lsof +D /mnt/data
Partition not visible after creation
sudo partprobe /dev/sdb
# or
sudo udevadm trigger --subsystem-match=block
fstab error prevents boot
If a bad fstab entry stops the system from booting, systemd drops you to an emergency shell. Mount root read-write and fix the file:
mount -o remount,rw /
nano /etc/fstab
Distro-specific package notes
parted and fdisk (part of util-linux) are installed by default everywhere. If resize2fs is missing, install the relevant package:
# Debian/Ubuntu
sudo apt install e2fsprogs
# Fedora/RHEL
sudo dnf install e2fsprogs
# Arch
sudo pacman -S e2fsprogsFrequently asked questions
- Can I partition a disk that is already mounted and in use?
- You can create new partitions on unused space of a mounted disk with parted, but you must unmount any partition before resizing or formatting it. The root filesystem can only be resized from a live environment or rescue mode.
- What is the difference between fdisk and parted?
- Both can manage GPT and MBR tables on modern systems. fdisk is interactive and beginner-friendly; parted supports non-interactive scripted use, handles disks over 2 TB more cleanly, and exposes alignment options more explicitly.
- Why should I use UUID in fstab instead of the device path like /dev/sdb1?
- Device names are assigned at boot based on detection order and can change if you add, remove, or reorder drives. UUIDs are tied to the filesystem itself and remain stable regardless of which port or slot a drive occupies.
- Can I resize an XFS filesystem to make it smaller?
- No. XFS does not support shrinking—it can only grow. If you need a smaller XFS volume, you must back up the data, recreate the partition and filesystem at the desired size, and restore.
- Is it safe to partition an NVMe drive the same way as a SATA drive?
- Yes, the same tools and concepts apply. The only difference is naming: NVMe devices appear as /dev/nvme0n1 and partitions as /dev/nvme0n1p1. The 1 MiB alignment recommendation applies equally to NVMe.
Related guides
Back Up Linux with Borg or restic
Set up encrypted, deduplicated backups with BorgBackup or restic: local and remote repos, retention pruning, restoring files, and systemd timer scheduling.
How to Check Disk Health with SMART
Learn to use smartctl to read SMART attributes, run drive self-tests, and identify early warning signs of HDD and SSD failure before data loss occurs.
Debug systemd Units that Won't Start
Learn a repeatable workflow to debug systemd services that won't start: status output, journalctl, systemd-analyze verify, and safe override.conf patches.
Linux Server Disaster Recovery Checklist
A practical Linux server disaster recovery checklist: what to back up, RTO/RPO planning, immutable off-site copies, automated restore drills, and verification.