Top Tags

Resize disk on existing Unraid VM Linux

How to resize disk on existing Unraid VM Linux

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:

  1. Backup your data - Always create a backup before modifying disk structures
  2. Verify VM is powered off when resizing the vdisk file in Unraid
  3. Check current disk layout to understand your LVM configuration
  4. 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

  1. Navigate to the VM tab
  2. Stop the virtual machine
  3. Click on the VM icon and select "Edit"
  4. Increase the vdisk size in the configuration
  5. Apply changes and start the VM

Via Command Line on Unraid Host

bash
1# Locate your vdisk file (typically in /mnt/user/domains/)
2cd /mnt/user/domains/your-vm-name/
3
4# Check current size
5ls -lh vdisk1.img
6
7# Resize vdisk (example: add 50GB)
8qemu-img resize vdisk1.img +50G
9
10# Verify new size
11qemu-img info vdisk1.img

Step 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

bash
1# View partition table
2sudo fdisk -l /dev/vda
3sudo lsblk
4
5# Check partition details
6sudo parted /dev/vda print

Resize Partition Using growpart

bash
1# Install cloud-utils if not present (includes growpart)
2sudo apt-get update && sudo apt-get install -y cloud-guest-utils
3
4# Grow partition 3 (adjust number based on your layout)
5sudo growpart /dev/vda 3
6
7# Verify the change
8sudo lsblk

Alternative: Manual Partition Resize with parted

bash
1# Start parted in interactive mode
2sudo parted /dev/vda
3
4# Print partition table
5(parted) print
6
7# Resize partition 3 to use all available space
8(parted) resizepart 3 100%
9
10# Exit parted
11(parted) quit

Step 3: Expand LVM Physical Volume

After the partition is resized, inform LVM about the new space:

bash
1# Check current PV size
2sudo pvdisplay
3sudo pvs
4
5# Resize the physical volume to use all partition space
6sudo pvresize /dev/vda3
7
8# Verify the expanded PV
9sudo pvdisplay /dev/vda3
10sudo pvs

Step 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.

bash
1sudo vgdisplay
2sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
3sudo lvdisplay
4df -T /
5# for ext4
6sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
7#
8df -h /

Understanding lvextend Options

bash
1# Extend by specific size (e.g., add 20GB)
2sudo lvextend -L +20G /dev/ubuntu-vg/ubuntu-lv
3
4# Extend to a specific total size (e.g., make it 100GB)
5sudo lvextend -L 100G /dev/ubuntu-vg/ubuntu-lv
6
7# Extend by percentage of free space (e.g., use 50% of free)
8sudo lvextend -l +50%FREE /dev/ubuntu-vg/ubuntu-lv
9
10# Extend using all free space (recommended for single-LV setups)
11sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
12
13# Verify the logical volume size
14sudo lvdisplay /dev/ubuntu-vg/ubuntu-lv
15sudo lvs

Step 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

bash
1# Check filesystem before resize
2sudo e2fsck -f /dev/ubuntu-vg/ubuntu-lv
3
4# Resize ext4 filesystem (can be done online/mounted)
5sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
6
7# Verify the new size
8df -h /

For XFS Filesystem

bash
1# XFS must be mounted during resize
2sudo xfs_growfs /
3
4# Verify using df
5df -h /

For Btrfs Filesystem

bash
1# Btrfs resize (must be mounted)
2sudo btrfs filesystem resize max /
3
4# Check filesystem usage
5sudo btrfs filesystem usage /

Verification and Validation

After completing all steps, thoroughly verify the changes:

Complete System Check

bash
1# Display complete storage hierarchy
2lsblk -f
3
4# Check disk usage by filesystem
5df -Th
6
7# Verify LVM configuration
8sudo vgdisplay
9sudo lvdisplay
10sudo pvdisplay
11
12# Check filesystem integrity
13sudo fsck -N /dev/ubuntu-vg/ubuntu-lv
14
15# Display inode usage (important for ext4)
16df -i /

Create Test Data

bash
1# Create a test file to confirm write capability
2sudo dd if=/dev/zero of=/test-file bs=1M count=100
3
4# Verify file creation
5ls -lh /test-file
6
7# Remove test file
8sudo rm /test-file

Troubleshooting Common Issues

Issue: Partition table not updated after qemu-img resize

Solution: Restart the VM completely or use partprobe:

bash
1sudo partprobe /dev/vda

Issue: LVM doesn't see new space after partition resize

Solution: Ensure kernel recognizes new partition size:

bash
1# Reread partition table
2sudo partprobe
3
4# Manually notify kernel
5echo 1 | sudo tee /sys/class/block/vda/device/rescan
6
7# Verify change
8sudo lsblk

Issue: resize2fs reports filesystem already resized

Solution: Check if filesystem block count matches LV size:

bash
1# Check LV size in bytes
2sudo lvdisplay /dev/ubuntu-vg/ubuntu-lv | grep "LV Size"
3
4# Check filesystem block size and count
5sudo tune2fs -l /dev/ubuntu-vg/ubuntu-lv | grep -E 'Block (size|count)'
6
7# If they match, no resize needed

Issue: Unable to extend LV - not enough free space

Solution: Verify VG has free extents:

bash
1# Check VG free space
2sudo vgdisplay ubuntu-vg | grep "Free"
3
4# If no free space, ensure previous steps completed
5sudo pvresize /dev/vda3
6sudo pvdisplay

Advanced Scenarios

Resizing Without Downtime (Online Resize)

For production systems, minimize downtime:

bash
1# All steps can be performed while filesystem is mounted
2# Only the initial vdisk resize requires VM shutdown
3
4# After expanding vdisk and restarting VM:
5sudo growpart /dev/vda 3
6sudo pvresize /dev/vda3
7sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
8sudo resize2fs /dev/ubuntu-vg/ubuntu-lv # For ext4
9
10# Verify without unmounting
11df -h /

Working with Multiple Logical Volumes

If your volume group contains multiple logical volumes:

bash
1# List all logical volumes in the VG
2sudo lvs ubuntu-vg
3
4# Extend specific LV with desired amount
5sudo lvextend -L +30G /dev/ubuntu-vg/data-lv
6sudo resize2fs /dev/ubuntu-vg/data-lv
7
8# Keep some space free in VG for snapshots
9sudo lvextend -l +75%FREE /dev/ubuntu-vg/root-lv
10sudo resize2fs /dev/ubuntu-vg/root-lv

Creating LVM Snapshots Before Resize

Create safety snapshots for critical systems:

bash
1# Check available space in VG
2sudo vgs ubuntu-vg
3
4# Create snapshot (10GB for snapshot metadata/changes)
5sudo lvcreate -L 10G -s -n root-snapshot /dev/ubuntu-vg/ubuntu-lv
6
7# Proceed with resize operations
8# If issues occur, revert:
9sudo lvconvert --merge /dev/ubuntu-vg/root-snapshot
10
11# After successful resize, remove snapshot
12sudo lvremove /dev/ubuntu-vg/root-snapshot

Performance Considerations

Filesystem Alignment

Ensure optimal I/O performance after resize:

bash
1# Check alignment for ext4
2sudo blockdev --getalignoff /dev/ubuntu-vg/ubuntu-lv
3
4# For new filesystems, specify stripe size (if using RAID)
5sudo mkfs.ext4 -E stride=32,stripe_width=64 /dev/ubuntu-vg/ubuntu-lv

I/O Scheduler Optimization

bash
1# Check current I/O scheduler
2cat /sys/block/vda/queue/scheduler
3
4# For VMs, deadline or noop are often optimal
5echo deadline | sudo tee /sys/block/vda/queue/scheduler

Automation Script

For frequent resize operations, use this comprehensive script:

bash
1#!/bin/bash
2# automated-lvm-resize.sh
3# Usage: ./automated-lvm-resize.sh /dev/ubuntu-vg/ubuntu-lv
4
5set -euo pipefail
6
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 partition
14echo "Growing partition ${DEVICE}${PART_NUM}..."
15sudo growpart "$DEVICE" "$PART_NUM"
16
17# Step 2: Resize physical volume
18echo "Resizing physical volume..."
19sudo pvresize "${DEVICE}${PART_NUM}"
20
21# Step 3: Extend logical volume
22
23echo "Extending logical volume..."
24sudo lvextend -l +100%FREE "$LV_PATH"
25
26# Step 4: Detect filesystem type and resize
27FS_TYPE=$(sudo blkid -o value -s TYPE "$LV_PATH")
28echo "Detected filesystem: $FS_TYPE"
29
30case "$FS_TYPE" in
31 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 1
48 ;;
49esac
50
51# Step 5: Display results
52echo "=== Resize Complete ==="
53echo "Filesystem usage:"
54df -h "$LV_PATH"
55
56echo -e "\nLVM details:"
57sudo lvdisplay "$LV_PATH" | grep -E "LV Name|LV Size"

References