Overview
When running Linux virtual machines on Unraid, you may need to expand the disk space as your storage requirements grow. This guide covers the complete process of resizing virtual disks and expanding the underlying LVM (Logical Volume Manager) partitions to utilize the newly added space.
Understanding LVM Architecture
LVM provides a flexible approach to disk management in Linux by abstracting physical storage into logical components:
- Physical Volume (PV): The actual physical disk or partition
- Volume Group (VG): A pool of storage created from one or more physical volumes
- Logical Volume (LV): Virtual partitions created from the volume group's free space
- Filesystem: The layer that organizes data on the logical volume (ext4, xfs, btrfs, etc.)
The resize process involves expanding each layer from bottom to top: physical disk → partition → physical volume → logical volume → filesystem.
Prerequisites
Before beginning the resize operation:
- Backup your data - Always create a backup before modifying disk structures
- Verify VM is powered off when resizing the vdisk file in Unraid
- Check current disk layout to understand your LVM configuration
- Ensure sufficient host storage - Verify Unraid has enough free space for the expanded disk
Step 1: Resize the Virtual Disk in Unraid
First, expand the virtual disk image on your Unraid host:
Via Unraid Web UI
- Navigate to the VM tab
- Stop the virtual machine
- Click on the VM icon and select "Edit"
- Increase the vdisk size in the configuration
- Apply changes and start the VM
Via Command Line on Unraid Host
1# Locate your vdisk file (typically in /mnt/user/domains/)2cd /mnt/user/domains/your-vm-name/3
4# Check current size5ls -lh vdisk1.img6
7# Resize vdisk (example: add 50GB)8qemu-img resize vdisk1.img +50G9
10# Verify new size11qemu-img info vdisk1.imgStep 2: Expand the Partition Inside the VM
After the virtual disk is resized on the host, boot your VM and expand the partition:
Check Current Partition Layout
1# View partition table2sudo fdisk -l /dev/vda3sudo lsblk4
5# Check partition details6sudo parted /dev/vda printResize Partition Using growpart
1# Install cloud-utils if not present (includes growpart)2sudo apt-get update && sudo apt-get install -y cloud-guest-utils3
4# Grow partition 3 (adjust number based on your layout)5sudo growpart /dev/vda 36
7# Verify the change8sudo lsblkAlternative: Manual Partition Resize with parted
1# Start parted in interactive mode2sudo parted /dev/vda3
4# Print partition table5(parted) print6
7# Resize partition 3 to use all available space8(parted) resizepart 3 100%9
10# Exit parted11(parted) quitStep 3: Expand LVM Physical Volume
After the partition is resized, inform LVM about the new space:
1# Check current PV size2sudo pvdisplay3sudo pvs4
5# Resize the physical volume to use all partition space6sudo pvresize /dev/vda37
8# Verify the expanded PV9sudo pvdisplay /dev/vda310sudo pvsStep 4: Extend the Logical Volume
Now expand the logical volume to consume the newly available space in the volume group.
You need manually resize LVM partition on Unraid VM Linux.
1sudo vgdisplay2sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv3sudo lvdisplay4df -T /5# for ext46sudo resize2fs /dev/ubuntu-vg/ubuntu-lv7#8df -h /Understanding lvextend Options
1# Extend by specific size (e.g., add 20GB)2sudo lvextend -L +20G /dev/ubuntu-vg/ubuntu-lv3
4# Extend to a specific total size (e.g., make it 100GB)5sudo lvextend -L 100G /dev/ubuntu-vg/ubuntu-lv6
7# Extend by percentage of free space (e.g., use 50% of free)8sudo lvextend -l +50%FREE /dev/ubuntu-vg/ubuntu-lv9
10# Extend using all free space (recommended for single-LV setups)11sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv12
13# Verify the logical volume size14sudo lvdisplay /dev/ubuntu-vg/ubuntu-lv15sudo lvsStep 5: Resize the Filesystem
The final step is expanding the filesystem to use the newly allocated space in the logical volume. The command varies by filesystem type:
For ext4 Filesystem
1# Check filesystem before resize2sudo e2fsck -f /dev/ubuntu-vg/ubuntu-lv3
4# Resize ext4 filesystem (can be done online/mounted)5sudo resize2fs /dev/ubuntu-vg/ubuntu-lv6
7# Verify the new size8df -h /For XFS Filesystem
1# XFS must be mounted during resize2sudo xfs_growfs /3
4# Verify using df5df -h /For Btrfs Filesystem
1# Btrfs resize (must be mounted)2sudo btrfs filesystem resize max /3
4# Check filesystem usage5sudo btrfs filesystem usage /Verification and Validation
After completing all steps, thoroughly verify the changes:
Complete System Check
1# Display complete storage hierarchy2lsblk -f3
4# Check disk usage by filesystem5df -Th6
7# Verify LVM configuration8sudo vgdisplay9sudo lvdisplay10sudo pvdisplay11
12# Check filesystem integrity13sudo fsck -N /dev/ubuntu-vg/ubuntu-lv14
15# Display inode usage (important for ext4)16df -i /Create Test Data
1# Create a test file to confirm write capability2sudo dd if=/dev/zero of=/test-file bs=1M count=1003
4# Verify file creation5ls -lh /test-file6
7# Remove test file8sudo rm /test-fileTroubleshooting Common Issues
Issue: Partition table not updated after qemu-img resize
Solution: Restart the VM completely or use partprobe:
1sudo partprobe /dev/vdaIssue: LVM doesn't see new space after partition resize
Solution: Ensure kernel recognizes new partition size:
1# Reread partition table2sudo partprobe3
4# Manually notify kernel5echo 1 | sudo tee /sys/class/block/vda/device/rescan6
7# Verify change8sudo lsblkIssue: resize2fs reports filesystem already resized
Solution: Check if filesystem block count matches LV size:
1# Check LV size in bytes2sudo lvdisplay /dev/ubuntu-vg/ubuntu-lv | grep "LV Size"3
4# Check filesystem block size and count5sudo tune2fs -l /dev/ubuntu-vg/ubuntu-lv | grep -E 'Block (size|count)'6
7# If they match, no resize neededIssue: Unable to extend LV - not enough free space
Solution: Verify VG has free extents:
1# Check VG free space2sudo vgdisplay ubuntu-vg | grep "Free"3
4# If no free space, ensure previous steps completed5sudo pvresize /dev/vda36sudo pvdisplayAdvanced Scenarios
Resizing Without Downtime (Online Resize)
For production systems, minimize downtime:
1# All steps can be performed while filesystem is mounted2# Only the initial vdisk resize requires VM shutdown3
4# After expanding vdisk and restarting VM:5sudo growpart /dev/vda 36sudo pvresize /dev/vda37sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv8sudo resize2fs /dev/ubuntu-vg/ubuntu-lv # For ext49
10# Verify without unmounting11df -h /Working with Multiple Logical Volumes
If your volume group contains multiple logical volumes:
1# List all logical volumes in the VG2sudo lvs ubuntu-vg3
4# Extend specific LV with desired amount5sudo lvextend -L +30G /dev/ubuntu-vg/data-lv6sudo resize2fs /dev/ubuntu-vg/data-lv7
8# Keep some space free in VG for snapshots9sudo lvextend -l +75%FREE /dev/ubuntu-vg/root-lv10sudo resize2fs /dev/ubuntu-vg/root-lvCreating LVM Snapshots Before Resize
Create safety snapshots for critical systems:
1# Check available space in VG2sudo vgs ubuntu-vg3
4# Create snapshot (10GB for snapshot metadata/changes)5sudo lvcreate -L 10G -s -n root-snapshot /dev/ubuntu-vg/ubuntu-lv6
7# Proceed with resize operations8# If issues occur, revert:9sudo lvconvert --merge /dev/ubuntu-vg/root-snapshot10
11# After successful resize, remove snapshot12sudo lvremove /dev/ubuntu-vg/root-snapshotPerformance Considerations
Filesystem Alignment
Ensure optimal I/O performance after resize:
1# Check alignment for ext42sudo blockdev --getalignoff /dev/ubuntu-vg/ubuntu-lv3
4# For new filesystems, specify stripe size (if using RAID)5sudo mkfs.ext4 -E stride=32,stripe_width=64 /dev/ubuntu-vg/ubuntu-lvI/O Scheduler Optimization
1# Check current I/O scheduler2cat /sys/block/vda/queue/scheduler3
4# For VMs, deadline or noop are often optimal5echo deadline | sudo tee /sys/block/vda/queue/schedulerAutomation Script
For frequent resize operations, use this comprehensive script:
1#!/bin/bash2# automated-lvm-resize.sh3# Usage: ./automated-lvm-resize.sh /dev/ubuntu-vg/ubuntu-lv4
5set -euo pipefail6
7LV_PATH="${1:-/dev/ubuntu-vg/ubuntu-lv}"8DEVICE="/dev/vda"9PART_NUM="3"10
11echo "=== Starting LVM Resize Process ==="12
13# Step 1: Grow partition14echo "Growing partition ${DEVICE}${PART_NUM}..."15sudo growpart "$DEVICE" "$PART_NUM"16
17# Step 2: Resize physical volume18echo "Resizing physical volume..."19sudo pvresize "${DEVICE}${PART_NUM}"20
21# Step 3: Extend logical volume22
23echo "Extending logical volume..."24sudo lvextend -l +100%FREE "$LV_PATH"25
26# Step 4: Detect filesystem type and resize27FS_TYPE=$(sudo blkid -o value -s TYPE "$LV_PATH")28echo "Detected filesystem: $FS_TYPE"29
30case "$FS_TYPE" in31 ext4|ext3|ext2)32 echo "Resizing ext filesystem..."33 sudo resize2fs "$LV_PATH"34 ;;35 xfs)36 MOUNT_POINT=$(df -P "$LV_PATH" | tail -1 | awk '{print $6}')37 echo "Resizing XFS filesystem at $MOUNT_POINT..."38 sudo xfs_growfs "$MOUNT_POINT"39 ;;40 btrfs)41 MOUNT_POINT=$(df -P "$LV_PATH" | tail -1 | awk '{print $6}')42 echo "Resizing Btrfs filesystem at $MOUNT_POINT..."43 sudo btrfs filesystem resize max "$MOUNT_POINT"44 ;;45 *)46 echo "Unsupported filesystem type: $FS_TYPE"47 exit 148 ;;49esac50
51# Step 5: Display results52echo "=== Resize Complete ==="53echo "Filesystem usage:"54df -h "$LV_PATH"55
56echo -e "\nLVM details:"57sudo lvdisplay "$LV_PATH" | grep -E "LV Name|LV Size"