Disk Partitioning and Filesystems on Linux

Khimananda Oli 8 min read Virtualization
Disk Partitioning and Filesystems on Linux

By Khimananda Oli | Last reviewed: August 2026

Disk partitioning and filesystems on Linux form the foundation of every reliable server, yet misconfigurations here cause more data loss and downtime than almost any other layer. Whether you are provisioning a new VPS in Kathmandu or managing a high-throughput database cluster globally, understanding how blocks map to files is non-negotiable. This guide skips the theory and focuses on the exact commands, safety checks, and architectural decisions I use daily as a DevOps engineer to keep storage resilient and performant.

How do you safely perform disk partitioning and filesystems on Linux?

Safe storage management begins before you type a single format command. In production environments, I never touch a disk without first confirming its identity and current state. A common mistake is assuming device names like /dev/sdb are persistent; they can change after reboots or kernel updates. Always identify drives by ID or path using lsblk -f or ls -l /dev/disk/by-id/. For a deeper dive into preparing a fresh server securely, see my guide on initial Ubuntu server setup.

Physical Disk (/dev/sda)GPT PartitionLVM PV / VGLogical VolumeFilesystem (ext4/xfs)
Storage stack layers for disk partitioning and filesystems on Linux: physical disk → GPT → LVM → filesystem

Create GPT partitions with parted

For any modern system, use GPT instead of MBR. GPT supports disks larger than 2 TiB, includes redundant headers, and allows unlimited partitions. The parted tool handles this cleanly:

# Create GPT label
sudo parted /dev/sdb mklabel gpt

# Create primary partition spanning entire disk (aligned)
sudo parted -a opt /dev/sdb mkpart primary 0% 100%

# Verify alignment and layout
sudo parted /dev/sdb print

The -a opt flag ensures optimal I/O alignment based on the disk's topology. Misaligned partitions on SSDs or RAID arrays degrade performance significantly. Always run print afterward to confirm boundaries match expected values.

Abstract with LVM for operational flexibility

I rarely format a raw partition directly in production. Logical Volume Manager (LVM) adds an abstraction layer that enables online resizing, snapshots, and multi-disk aggregation without unmounting. If you later need to extend storage for databases or logs, LVM makes this trivial. For persistent storage patterns in containerized environments, see Kubernetes persistent volumes and storage.

# Initialize physical volume
sudo pvcreate /dev/sdb1

# Create volume group
sudo vgcreate datavg /dev/sdb1

# Create logical volume (use 80% initially to leave room for snapshots/growth)
sudo lvcreate -L 100G -n datalv datavg

# Verify
sudo pvs && sudo vgs && sudo lvs

Leaving free space in the volume group is critical. Snapshots require unallocated extents; running out of VG space during a backup operation can corrupt the snapshot and stall your pipeline.

Which filesystem should you choose: ext4 vs XFS vs Btrfs?

Choosing the right filesystem depends entirely on workload characteristics. There is no universal best option. In my experience across dozens of production systems, ext4 remains the default for good reason, but XFS dominates specific niches. Btrfs has matured but still carries risks for certain enterprise use cases.

Featureext4XFSBtrfs
Max file size16 TiB8 EiB16 EiB
Online growYesYesYes
Online shrinkYesNoYes (experimental)
SnapshotsNo (needs LVM)No (needs LVM)Native
Data checksummingMetadata onlyMetadata onlyFull data + metadata
Best workloadGeneral purpose, boot, small filesLarge files, parallel I/O, mediaNAS, self-healing storage
Recovery maturityExcellentExcellentGood but complex

For web servers, application containers, and boot volumes, ext4 is the safest choice. It shrinks online, recovers predictably, and every Linux admin knows it. For media servers, video processing, or large sequential writes, XFS performs better under concurrency. Never choose XFS if you anticipate needing to shrink the volume later — it cannot be reduced in size. Btrfs offers compelling features like transparent compression and bit-rot detection, but I reserve it for personal NAS or non-critical archival storage until its RAID5/6 implementation stabilizes further.

How do you format and mount filesystems correctly?

Formatting and mounting seem basic, but production-grade setups require attention to options that affect durability and performance. Default mount options are rarely optimal for servers.

mkfs.ext4 / mkfs.xfsmkdir && mountVerify with df/findmntAdd to /etc/fstabCritical fstab options:• defaults,noatime,nodiratime (reduce metadata writes)• errors=remount-ro (prevent write corruption on failure)• Use UUID= instead of /dev/sdX paths• Always test with 'mount -a' before reboot⚠ Never skip mount -a validation — typo = unbootable system
Safe workflow for disk partitioning and filesystems on Linux: format, mount, verify, persist with validated fstab entry

Format with appropriate options

# ext4 with lazy initialization disabled (production-ready immediately)
sudo mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/datavg/datalv

# XFS with reflink enabled (for future dedup/snapshots)
sudo mkfs.xfs -m reflink=1 /dev/datavg/datalv

Lazy initialization speeds up creation but defers inode table zeroing to background I/O, causing unpredictable latency spikes during early writes. Disable it for production volumes. For XFS, enabling reflink at format time is free and unlocks copy-on-write features later.

Persist mounts safely via fstab

Always use UUIDs rather than device paths. Device enumeration order changes; UUIDs do not. After editing /etc/fstab, always run sudo mount -a to validate syntax before rebooting. A malformed fstab entry will drop your server into emergency mode, requiring console access to fix.

# Get UUID
UUID=$(sudo blkid -s UUID -o value /dev/datavg/datalv)

# Example fstab line (ext4)
echo "UUID=$UUID /data ext4 defaults,noatime,errors=remount-ro 0 2" | sudo tee -a /etc/fstab

# Validate without reboot
sudo mount -a && df -hT /data

The noatime option eliminates read-triggered metadata writes, reducing SSD wear and improving throughput for read-heavy workloads. Modern applications rarely need access timestamps; if yours does, use relatime instead.

How do you resize partitions and filesystems without downtime?

Storage requirements grow. Planning for online resizing from day one prevents painful migrations later. This is where LVM pays dividends over raw partitions.

Extend LVM and filesystem online

# Extend logical volume by 50G
sudo lvextend -L +50G /dev/datavg/datalv

# Resize filesystem to fill LV
# ext4:
sudo resize2fs /dev/datavg/datalv
# XFS:
sudo xfs_growfs /data

Note the asymmetry: resize2fs takes the device path, while xfs_growfs takes the mount point. Mixing these up is a frequent source of confusion. Both operations are safe online for growing. Shrinking requires unmounting for XFS (not supported) and careful ordering for ext4 (shrink filesystem first, then LV).

Shrink ext4 safely (offline only)

# Unmount first
sudo umount /data

# Check filesystem integrity
sudo e2fsck -f /dev/datavg/datalv

# Shrink filesystem to 80G
sudo resize2fs /dev/datavg/datalv 80G

# Shrink LV to match
sudo lvreduce -L 80G /dev/datavg/datalv

Never shrink an LVM volume before shrinking the filesystem inside it. Doing so truncates the filesystem metadata and causes irreversible corruption. Always reduce the filesystem first, then the container. For monitoring disk usage trends to anticipate resizing needs, refer to Linux server monitoring with Netdata.

ONLINE GROW (Safe)1. lvextend -L +50G /dev/vg/lv2. resize2fs OR xfs_growfs3. df -hT (verify)✓ No downtime required✓ Supported: ext4 + XFSOFFLINE SHRINK (Risky)1. umount /data2. e2fsck -f /dev/vg/lv3. resize2fs THEN lvreduce✗ Requires downtime✗ XFS cannot shrink
Online grow vs offline shrink comparison for disk partitioning and filesystems on Linux — order of operations matters critically

What are common pitfalls and recovery strategies?

Even experienced engineers make mistakes at the storage layer. Knowing failure modes and recovery paths separates competent admins from those who lose data.

  • Accidental format on wrong device: Always double-check with lsblk before mkfs. Keep backups of partition tables with sfdisk -d /dev/sda > sda-backup.sfdisk before modifications. Restore with sfdisk /dev/sda < sda-backup.sfdisk.
  • LVM metadata corruption: LVM stores metadata copies on each PV. If corrupted, restore from /etc/lvm/archive/ using vgcfgrestore -f archive_file vgname. Regularly back up this directory off-server.
  • Filesystem full despite free space: ext4 reserves 5% for root by default. On large data volumes, reduce this with tune2fs -m 1 /dev/datavg/datalv. Also check inode exhaustion with df -i; millions of small files can exhaust inodes before blocks.
  • Mount failures after kernel update: Some filesystem modules (like btrfs or xfs) may not load automatically. Add required modules to /etc/modules-load.d/storage.conf to ensure availability at boot.

For teams managing databases on Linux storage, proper partitioning and filesystem tuning directly impacts query performance and replication stability. My guides on MySQL performance tuning and PostgreSQL administration essentials cover storage-specific optimizations in depth.

Practical Next Steps for Production Storage

Disk partitioning and filesystems on Linux demand respect for fundamentals over convenience. Start every deployment with GPT and LVM unless you have a specific reason not to. Choose ext4 for versatility, XFS for scale, and validate every fstab change with mount -a. Document your storage topology in infrastructure-as-code so recovery doesn't depend on tribal knowledge. If your team needs help designing audit-ready, compliant storage architectures or migrating legacy systems safely, reach out to discuss your infrastructure.

Frequently Asked Questions

GPT supports drives larger than 2TB and allows up to 128 partitions by default, while MBR limits you to four primary partitions and 2TB. Modern UEFI systems require GPT for booting. Always choose GPT for new Linux installations unless maintaining legacy BIOS hardware compatibility.

Ext4 remains the standard for most workloads due to maturity and stability. XFS is preferred for large file storage or high-throughput databases. Btrfs offers snapshots but requires more RAM. For 2026 deployments, ext4 is safe; choose XFS only if handling multi-terabyte files or parallel I/O.

Use resize2fs after extending the underlying partition with growpart or fdisk. The filesystem must be unmounted or remounted read-only for shrinking. Online expansion works on mounted ext4 volumes. Always backup before resizing. Run e2fsck first to ensure metadata consistency before modifying geometry.

Yes, via the ntfs3 kernel driver included since Linux 5.15. It provides read-write access faster than older FUSE-based ntfs-3g. Mount with type ntfs3 for best performance. Avoid using NTFS for native Linux system partitions; reserve it only for dual-boot data sharing or external drive compatibility.

Run lsblk -f to display devices, partitions, mount points, and filesystem labels in one view. Alternatively, blkid shows UUIDs and types. Both are part of util-linux and available on all modern distributions. These tools query sysfs directly and reflect real-time kernel state accurately.

No, in-place conversion was removed from btrfs-progs years ago due to reliability issues. You must create a new btrfs volume and copy data over. Use btrfs send/receive or rsync for migration. Always verify checksums after transfer and test bootability before decommissioning the original ext4 partition.

Filesystems reserve blocks for root and metadata overhead. Ext4 reserves 5% by default; reduce with tune2fs -m. Additionally, df excludes unallocated space within LVM or thin-provisioned volumes. Check actual usage with du and compare against lsblk raw sizes to identify discrepancies from reserved blocks or snapshot allocations.

Yes, OpenZFS 2.3+ is stable and widely used in enterprise storage. It requires explicit installation as it is not GPL-compatible with the kernel. ZFS excels at data integrity, compression, and snapshots but demands ECC RAM. Use it for NAS or database backends, not minimal containers or low-memory VPS instances.

Use shred -vzn 1 /dev/sdXn for single-pass overwrite on HDDs. For SSDs, issue ATA Secure Erase via hdparm or use blkdiscard followed by fstrim. Never rely on rm or format alone. Verify wipe completion with hexdump. Physical destruction remains necessary for classified data compliance requirements.

Inode exhaustion is the usual cause. Check with df -i. Small files consume inodes regardless of block usage. Ext4 has fixed inode counts set at mkfs time. Solutions include deleting unnecessary files, migrating to a filesystem with dynamic inodes like XFS, or recreating the partition with higher inode density.

Standard partitions suffice for simple single-disk VMs where resizing is rare. LVM adds flexibility for snapshots, live resizing, and spanning multiple disks but introduces slight overhead. Most cloud providers recommend plain partitions for boot volumes. Use LVM only when managing multiple data volumes or requiring point-in-time recovery capabilities.

Use xfs_info or btrfs scrub for online checks on those filesystems. Ext4 cannot be fully checked while mounted; remount read-only or schedule downtime. Monitor dmesg for I/O errors as early warning signs. Enable smartd for hardware-level health. Regular offline e2fsck during maintenance windows prevents silent corruption accumulation.

Align partitions to 1MiB boundaries, which satisfies all modern SSD erase block sizes. Parted defaults to this since version 3.0. Misalignment causes write amplification and reduced lifespan. Verify with cat /sys/block/sda/queue/optimal_io_size. Cloud block storage also benefits from proper alignment to avoid performance penalties on virtualized storage layers.

Yes, use LUKS2 on specific partitions via cryptsetup luksFormat. This protects sensitive data independently of other volumes. Key management integrates with systemd-cryptsetup for automatic unlocking at boot. Performance impact is minimal on AES-NI hardware. Combine with separate unencrypted boot partition for GRUB compatibility and easier recovery procedures.

Locate backup superblocks with dumpe2fs | grep -i superblock. Attempt repair using e2fsck -b /dev/sdXn. If that fails, mount read-only with sb= option to extract data. Tools like testdisk can scan for lost partitions. Always image the drive first with ddrescue before attempting any recovery operations.