Disk Partition Linux: How to Create and Manage Partitions
In this article
Partitioning a disk in Linux involves dividing a storage device into separate sections, each of which can be managed independently for different file systems, operating systems, or data types. This foundational system administration task enables better organization, security, and performance. Whether installing a new system or reconfiguring an existing one, understanding how to create, resize, delete, and manage disk partitions is essential for Linux users and administrators.
Background and Purpose of Disk Partitioning
Disk partitioning has been a core component of computing since early operating systems. In Linux, it allows the system to organize storage into logical units, each with its own file system and mount point. Historically, partitioning was necessary due to hardware limitations and file system constraints. Today, it serves more advanced purposes: isolating the operating system from user data, enabling multi-boot configurations, improving security through separation, and simplifying backups and recovery.
For example, a typical Linux installation might include separate partitions for / (root), /home, /boot, and swap. This separation ensures that if the root partition fills up due to log accumulation, user files in /home remain unaffected. It also allows /home to persist across OS re-installations.
How Disk Partitioning Works in Linux
Linux supports two primary partitioning schemes: MBR (Master Boot Record) and GPT (GUID Partition Table). MBR is older, supports up to four primary partitions (or three primary and one extended with logical partitions), and is limited to disks under 2 TiB. GPT is modern, supports up to 128 partitions by default on most systems, and handles disks larger than 2 TiB—making it the preferred choice for new systems.
Partitions are accessed via device files in /dev, such as /dev/sda1 or /dev/nvme0n1p2. The kernel reads the partition table to determine how the disk is divided. Once created, a partition must be formatted with a file system (e.g., ext4, XFS, Btrfs) before it can store data. It is then mounted to a directory in the file system hierarchy.
Common Partitioning Tools
Linux offers several command-line and graphical tools to manage partitions:
- fdisk: A text-based utility for managing MBR and GPT partitions. Ideal for scripting and server environments.
- gdisk: Specifically designed for GPT disks, offering similar functionality to
fdisk. - parted: Supports both MBR and GPT, allows resizing, and includes a command-line and interactive mode.
- cfdisk: A curses-based, user-friendly version of
fdiskwith a simple interface. - GParted: A graphical tool often used in live environments, providing drag-and-drop partition management.
For example, to list partitions using fdisk, run sudo fdisk -l. To start interactive partitioning on /dev/sdb, use sudo fdisk /dev/sdb.
How to Choose Partitioning Scheme and Layout
Selecting the right partitioning scheme depends on hardware and use case:
- Use GPT for disks larger than 2 TiB or on UEFI-based systems. It also provides redundancy with a backup partition table.
- Use MBR only for legacy BIOS systems with small disks.
Common partition layouts include:
- Single partition: Entire disk as
/. Simple but risky—system issues can affect all data. - Root and home:
/for system files,/homefor user data. Recommended for most users. - Full separation: Includes
/,/home,/boot,/var,/tmp, andswap. Useful for servers where log files (/var) or temporary data (/tmp) may grow unpredictably. - Swap partition vs. swap file: Traditionally, a dedicated swap partition was used for virtual memory. Modern systems often use a swap file on the root partition, which is easier to resize. However, a swap partition may offer slightly better performance and is required for hibernation in some setups.
Common Problems and How to Avoid Them
Partitioning errors can lead to data loss or boot failures. Common issues include:
- Incorrect partition table type: Accidentally creating an MBR table on a large disk can result in unusable space. Always verify the scheme before writing changes.
- Mounting errors: Forgetting to update
/etc/fstabafter creating a new partition prevents the system from booting. Always test entries withsudo mount -abefore rebooting. - Running out of space: Fixed-size partitions can fill up. Using LVM (Logical Volume Manager) allows dynamic resizing.
- Data loss during resizing: Always back up data before modifying partition sizes, even with tools like GParted that claim to be safe.
A frequent misconception is that partitions can be freely resized without risk. While modern tools are reliable, power failures or hardware issues during resizing can corrupt data.
Alternatives to Traditional Partitioning
Linux offers advanced storage management systems that go beyond basic partitioning:
- LVM (Logical Volume Manager): Abstracts physical disks into volume groups and logical volumes. Enables resizing, snapshots, and spanning multiple disks. For example, you can grow a logical volume online without unmounting.
- RAID: Combines multiple disks for redundancy (RAID 1) or performance (RAID 0). Can be software-based (mdadm) or hardware.
- Btrfs and ZFS: Copy-on-write file systems that include built-in volume management, compression, and snapshots. Btrfs supports subvolumes, which behave like partitions but are more flexible.
- Encryption with LUKS: Full-disk or partition-level encryption. Often applied to
/and/homefor security.
These technologies can be combined—e.g., LVM on LUKS, or Btrfs on a single partition—to achieve robust, scalable storage.
Frequently Asked Questions
How do I view current partitions in Linux?
To list all disk partitions, use lsblk for a clean tree view or sudo fdisk -l for detailed partition table information. Both commands show device names, sizes, and mount points if available.
Can I resize a partition without losing data?
Yes, using tools like parted or GParted, you can resize ext2/3/4 and XFS partitions (with caution). Always back up data first. Note that resizing the partition hosting the root file system typically requires booting from a live USB.
What is the difference between primary and logical partitions?
In MBR, you can have up to four primary partitions. To create more, one primary must be an extended partition, which can contain multiple logical partitions. GPT does not use this distinction, eliminating the limitation.
Do I need a /boot partition?
On BIOS systems with MBR, a small /boot partition (500 MB) is often used. On UEFI systems, an EFI System Partition (ESP), usually 100–550 MB and formatted as FAT32, is required. It holds bootloaders and must not be encrypted.
Can I delete a partition safely?
Yes, if it’s not in use. Unmount it first with umount /dev/sdXN, then use fdisk or parted to delete. Ensure no critical data is stored there and that /etc/fstab doesn’t reference it.
Is it better to use partitions or directories?
Partitions provide isolation at the block level, useful for security and performance. Directories are simpler and sufficient for basic organization. Use partitions when you need separate file systems, mount options, or resilience against disk full errors.