Skip to content

Resizing a disk image

Requirements:

Things that you will need

  • SSH Connection to vhost
  • virt-manager

Things of note

  • Allways create a backup of the disk image before making changes to the disk image. It is always best practive to have a backup to prevent data loss.

Instructions:

Step 1. Connect to vhost

ssh username@###.###.###.###
Connect to vhost

Step 2. Scan the disks.

df -h
Scan the disks. You're looking for the virtual machine drive, check to make sure it is at or below 79%. If it is at 80% or above, stop.

Step 3. Navigate to the directory your disks are mounted in.

cd <your_disks_directory>
Navigate to the directory your disks are mounted in.

Step 4. View disk images

ls -lah
View disk images

Step 5. View all VMs' status

sudo virsh list
View all VMs' status. Before continuing, ensure you are not interrupting the user's work.

Step 6. Shutdown the VM gracefully

sudo virsh shutdown <desired_vm>
Shutdown the VM gracefully, if possible. Wait a minute or two.

Step 7. Hard-shutdown of the VM

sudo virsh destroy <desired_vm>
Hard-shutdown of the VM, if the graceful shutdown fails.

Step 8. Resizes the disk image

sudo qemu-img resize <desired_vm> +<your_amount>G
Resizes the disk image. This could fail, see If there are snapshots for more information.


If there are snapshots

If there are snapshots you will need to remove those before resizing.

Deleting snapshots 1.

sudo virsh snapshot-list <desired_vm>
Lists all snapshots of a VM

Deleting snapshots 2.

sudo virsh snapshot-delete <desired_vm> <snapshot_name>
Deletes the desired snapshot

Re-run the command in step 8 after deleting the snapshots

Now that the disk image has been resized, we need to partion the drives inside the VM to match the new size.

Step 9. start the VM

Open virt-manager and start the VM

Step 10. Open Disk Manager

Log into the VM, click the windows icon and search for "Create and format hard disk partitions"

Step 11. Remove Windows recovery partition

If there is a recovery partition, you will need to delete it via the command line. Search for cmd.exe, right-click it, and select Run As Administrator. Run these commands:

diskpart
select disk 0
list partition
select partition <RECOVERY_PART_NUMBER>
delete partition override
exit

Step 12. Extend the Volume

Back in the graphical program, right-click the C: drive and click "extend volume."

Step 13. Setup Wizard

Follow the setup wizard.

VM has been resized


Last update: 2024-12-17