Linux Partition Resize

Comprehensive guides for resizing partitions with LVM, ext4, XFS, Btrfs, and more.

WARNING: Always backup your data before resizing partitions! Incorrect operations can result in permanent data loss.

LVM (Logical Volume Manager)

Extend LVM Logical Volume

1. Check available space: vgdisplay

2. Extend logical volume: lvextend -L +10G /dev/vg_name/lv_name

3. Resize filesystem: resize2fs /dev/vg_name/lv_name (ext4) or xfs_growfs /mount/point (XFS)

4. Verify: df -h

lvextend -L +10G /dev/vg_name/lv_name && resize2fs /dev/vg_name/lv_name

Extend LVM Physical Volume

1. Extend partition using fdisk/parted

2. Resize physical volume: pvresize /dev/sda2

3. Verify: pvdisplay

4. Extend logical volume as above

pvresize /dev/sda2

Shrink LVM Logical Volume (ext4 only)

1. BACKUP DATA FIRST!

2. Unmount: umount /mount/point

3. Check filesystem: e2fsck -f /dev/vg_name/lv_name

4. Resize filesystem: resize2fs /dev/vg_name/lv_name 50G

5. Reduce LV: lvreduce -L 50G /dev/vg_name/lv_name

6. Remount: mount /dev/vg_name/lv_name /mount/point

e2fsck -f /dev/vg_name/lv_name && resize2fs /dev/vg_name/lv_name 50G && lvreduce -L 50G /dev/vg_name/lv_name

Add New Disk to Volume Group

1. Create physical volume: pvcreate /dev/sdb

2. Extend volume group: vgextend vg_name /dev/sdb

3. Verify: vgdisplay

4. Extend logical volumes as needed

pvcreate /dev/sdb && vgextend vg_name /dev/sdb

ext4 / ext3 Filesystems

Extend ext4 Partition

1. Extend partition using fdisk/parted/growpart

2. Check filesystem: e2fsck -f /dev/sda1

3. Resize filesystem: resize2fs /dev/sda1

4. Verify: df -h

e2fsck -f /dev/sda1 && resize2fs /dev/sda1

Shrink ext4 Partition

1. BACKUP DATA FIRST!

2. Unmount: umount /mount/point

3. Check filesystem: e2fsck -f /dev/sda1

4. Resize filesystem: resize2fs /dev/sda1 50G

5. Shrink partition using fdisk/parted

6. Remount: mount /dev/sda1 /mount/point

umount /mount/point && e2fsck -f /dev/sda1 && resize2fs /dev/sda1 50G

Online ext4 Resize (mounted)

1. Extend partition first

2. Resize filesystem online: resize2fs /dev/sda1

3. Verify: df -h

resize2fs /dev/sda1

XFS Filesystem

Extend XFS Partition

1. Extend partition using fdisk/parted/growpart

2. Grow filesystem: xfs_growfs /mount/point

3. Verify: df -h

xfs_growfs /mount/point

XFS Filesystem Info

1. Check XFS info: xfs_info /mount/point

2. Check space usage: xfs_db -r -c "freesp" /dev/sda1

xfs_info /mount/point

Important Note: XFS Shrinking

XFS does NOT support shrinking!

To reduce XFS size: backup data, recreate smaller partition, restore data

# XFS cannot be shrunk - only grown

Btrfs Filesystem

Extend Btrfs Partition

1. Extend partition using fdisk/parted

2. Resize filesystem: btrfs filesystem resize max /mount/point

3. Or specific size: btrfs filesystem resize +10G /mount/point

4. Verify: btrfs filesystem show

btrfs filesystem resize max /mount/point

Shrink Btrfs Partition

1. Check usage: btrfs filesystem usage /mount/point

2. Shrink filesystem: btrfs filesystem resize -10G /mount/point

3. Or to specific size: btrfs filesystem resize 50G /mount/point

4. Shrink partition using fdisk/parted

btrfs filesystem resize -10G /mount/point

Add Device to Btrfs

1. Add device: btrfs device add /dev/sdb /mount/point

2. Balance data: btrfs balance start /mount/point

3. Verify: btrfs filesystem show

btrfs device add /dev/sdb /mount/point && btrfs balance start /mount/point

ZFS Filesystem

Extend ZFS Pool

1. Add new disk: zpool add tank /dev/sdb

2. Or replace disk: zpool replace tank /dev/sda /dev/sdb

3. Check status: zpool status

4. ZFS automatically uses new space

zpool add tank /dev/sdb

Expand ZFS Pool (after disk resize)

1. Online expand: zpool online -e tank /dev/sda

2. Check status: zpool list

3. Verify: zfs list

zpool online -e tank /dev/sda

ZFS Dataset Quota

1. Set quota: zfs set quota=100G tank/dataset

2. Set reservation: zfs set reservation=50G tank/dataset

3. Remove quota: zfs set quota=none tank/dataset

4. Check: zfs get quota,reservation tank/dataset

zfs set quota=100G tank/dataset

NTFS Filesystem (Linux)

Resize NTFS (ntfsresize)

1. Install ntfs-3g: apt install ntfs-3g

2. Unmount: umount /mount/point

3. Check: ntfsfix /dev/sda1

4. Resize: ntfsresize -s 50G /dev/sda1

5. Adjust partition with fdisk/parted

6. Remount partition

ntfsfix /dev/sda1 && ntfsresize -s 50G /dev/sda1

NTFS Information

1. Show info: ntfsresize -i /dev/sda1

2. Show size: ntfsresize -m /dev/sda1

ntfsresize -i /dev/sda1

Partition Tools

fdisk - Partition Editor

1. List partitions: fdisk -l

2. Edit partition: fdisk /dev/sda

3. Commands: d (delete), n (new), p (print), w (write)

4. Reload partition table: partprobe /dev/sda

fdisk /dev/sda

parted - Advanced Partition Tool

1. Interactive mode: parted /dev/sda

2. Resize partition: resizepart 1 100GB

3. Or: parted /dev/sda resizepart 1 100GB

4. Print layout: print

parted /dev/sda resizepart 1 100GB

growpart - Cloud-Init Tool

1. Install: apt install cloud-guest-utils

2. Grow partition: growpart /dev/sda 1

3. Then resize filesystem as needed

4. Useful for cloud VMs after disk expansion

growpart /dev/sda 1

cfdisk - User-Friendly Partition Tool

1. Launch: cfdisk /dev/sda

2. Navigate with arrow keys

3. Select partition and choose Resize

4. Write changes and quit

cfdisk /dev/sda

Important Safety Guidelines

Before Resizing - CRITICAL STEPS

1. BACKUP ALL DATA - resizing can cause data loss!

2. Check filesystem: e2fsck -f (ext4) or xfs_repair (XFS)

3. Verify free space for shrinking operations

4. Unmount filesystem when required

5. Test in non-production first if possible

# ALWAYS BACKUP FIRST!

Common Issues & Solutions

1. "Device is busy" - use lsof or fuser to find processes

2. "Bad magic number" - filesystem corrupted, run fsck

3. "No space" when shrinking - defragment first

4. Changes not visible - run partprobe or reboot

5. LVM not detecting - run pvscan && vgscan

lsof /mount/point && fuser -m /mount/point

Verification Commands

1. Check disk space: df -h

2. Check block devices: lsblk

3. Partition info: parted -l

4. LVM info: pvs && vgs && lvs

5. Filesystem info: tune2fs -l /dev/sda1 (ext4)

df -h && lsblk && pvs && vgs && lvs