Disclosure: Some of the links on this site are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.

How To Increase a UTM Virtual Machine Disk Size

If you already have a functioning UTM virtual machine running on your Mac, you may be wondering how you can increase the disk size of the guest operating system.

This is usually necessary when you fill the virtual hard disk on the guest operating system. Even if your physical hard drive has plenty of space, the virtual hard disk does not automatically increase in size to fill more space on your physical drive.

The process necessary for increasing the size of the virtual drive can be broken down into two steps:

  1. Occurs on the host OS – Increase the size of the virtual drive in UTM, which is usually a file stores on the host operating system.
  2. Occurs on the guest OS – Edit the partitions in the guest operating system and expand the file system into the newly created space.

The guest operating system is not usually ‘aware’ that it is running in a virtual machine. Therefore the hard drive appears to the guest operating system as an actual physical drive.

When the virtual drive file size is increased using the tools in UTM, the guest operating system simply perceives a physical drive that has ‘magically’ increased in size.

Depending on the guest operating system, you will then need to follow a process in order to make use of the raw disk space that has been added.

This usually involves either creating a new partition in the new raw space, or expanding the existing partition into this space.

you may find yourself running out of disk space even though your physical Mac OS disk has plenty of room.

Prerequisite

You will need to have UTM installed and a functioning virtual machine with either a Windows or Linux operating system installed.

The process of increasing the disk size in UTM is the same for both operating systems so both Windows and Linux users should complete the first step.

Once the virtual disk size has been increase, the guest operating system will see the size increase but you will then need to either increase the existing partition primary to fill the space, or create a new partition.

This process needs to be completed within the guest operating system and is therefore different for Windows and Linux. Choose the appropriate step depending on your operating system:

How to Change a UTM Virtual Disk Size

You can change the size of a virtual disk in UTM using the following steps:

  1. If the virtual machine is running, first stop it by shutting down the guest operating system.
  2. Right-click the virtual machine in the left-hand sidebar of the main UTM screen and then click edit.
  3. Under the drives section in the left-hand sidebar, click the main disk. This is most likely a VirtIO drive and will have a .qcow2 file associated with it. This is the file that holds the data kept on the virtual drive.
  4. Click the Resize… button and enter the size that you would like to resize the drive to.
  5. Click the Resize button to resize the drive.
Resize a drive in UTM

How to Expand the Partition

Once you have resized the drive using UTM in the Mac OS host operating system, you will need to either extend the primary partition or create a new partition to fill the newly created space.

This process is different for Windows and Linux guest operating systems:

Expanding a Windows Partition

In order to expand your C: drive into the newly created space, complete the following steps:

  1. Boot up your Windows virtual machine and log in.
  2. Right-click the start button and click command prompt (admin).
  3. At the command prompt, type the command diskpart. This will take you to the DISKPART> prompt:
Diskpart at the command prompt
  1. Enter the command list disk to list detected disks. Note the reference number for the main disk, for example disk 0.
  2. Enter the command select disk 0, replacing the number with the number of your disk if necessary.
  3. Enter the command list partition to show all of the partitions for the disk.
  4. First, you may need to remove the recovery partition in order to allow the main partition to expand. Enter the command select partition #, replacing # with the partition number for the recovery partition.
  5. Enter the command delete partition override to remove the recovery partition.
  6. Next, enter the list volume command to list the volumes and find the volume # associated with the C drive:
Diskpart at the command prompt
  1. Enter the command select volume # replacing the # with the volume number of your C drive. In this example, volume 2.
  2. Enter the command extend in order to extend the volume to fill the newly created disk space.
  3. Open the file explorer and navigate to This PC. You should now see that the size of the C drive has increased to fill the newly created space on the virtual disk.

Expanding a Linux Partition

In order to use newly created disk space in Linux, we will need to expand the partition and file system in the newly created space. This process can differ depending on the version of Linux that you are using.

Note that this process is quite lengthy the first time that you run through it. However once you understand the principle, you will be able to repeat the process much quicker and easier.

Note that although it is not essential, I would recommend connecting to your Debian VM using SSH in the Mac terminal. This can make copying and pasting commands easier:

You can find your Debian IP address by typing hostname -I at the Debian command prompt.

Use the following command in the Mac terminal to open an SSH session to Debian:

ssh <your-user-name>@<your-debian-IP-address>

Debian Linux

  1. If you are using a GUI, open a new Terminal window.
  2. Sign in as the root user using the command su -
  3. Ensure that everything is up to date by entering the command apt-get update && apt-get upgrade -y
  4. First, check the file system that you have with the command df -h.
  5. Identify the system partition that has the root folder “/” mounted. In this example, /dev/vda2.
Diskpart at the command prompt
  1. Run the command fdisk -l to list disk information. Note the size mismatch error, which is good as it indicates that Debian recognises the increase in virtual disk size.

You can also see here that the virtual hard drive /dev/vda is showing 35G. This is the size that we have resized this disk to using UTM for this example.

The goal is to resize the main system partition /dev/vda2 to fill the newly created space on the disk. Before we do this we will first need to move the swap partition /dev/vda3 to the end of the disk.

Fdisk output
Moving the swap partition
  1. First we need to disable the swap file, enter the command swapoff -a
  2. Next, start fdisk on your primary disk with the command fdisk /dev/vda, replacing vda with your device if different.
  3. Type p to display the partition information. Make a note of the total number of disk sectors (in this example, 73400320) and total number of sectors in the swap partition (in this example /dev/vda3, which is 1998848 sectors).
Total disk sectors and total sectors in the swap partition
  1. Next, deduct the number of sectors in the swap file from the total number of sectors and make a note of the result. This will be the location that we will move the start of the swap partition to. For this example it looks like this: 73400320 – 1998848 = 71401472
  2. Now we can delete the existing swap partition. Enter d at the prompt to delete a partition.
  3. Enter the partition number for the swap file, in this example it is partition 3.
  4. Enter p at the prompt to list disk partitions again. You should now see that the swap partition has been removed.
  5. Now we can re-create the swap partition. Enter n to create a new partition.
  6. Enter the partition number the same as the previous swap partition number. In this example it is partition 3.
  7. Enter the first sector, where the partition will begin. This should be the value that you calculated in step 10, in this example 71401472.
  8. Leave the next prompt blank and press enter to choose the default value, which will be the last available sector on the disk. This will create a swap partition the same size as before, only it will be at the end of the newly enlarged disk.
  9. You may notice that the partition created is of the type linux file system. Next we need to change this type to a swap partition. To change the type, type t at the prompt.
  10. Enter the swap file partition number, in this example it is partition 3.
  11. You will be prompted to enter a partition type or alias, here type swap to change the type to a swap partition.
  12. Type p at the prompt to list the partitions. You should now see that the swap partition again, it should be of the type linux swap and checking the start and end sectors should show the partition at the end of the newly resized disk.
Newly created swap partition at the end of the disk
  1. Next, save the changes by typing w at the prompt. This will take you back to the main command prompt.
  2. Next we need to create a new swap. Enter the command mkswap /dev/vda3, changing the swap partition as necessary. In this example it is /dev/vda3. The output of this command will show you the UUID for the partition, we will need it for the next step.
  3. Edit the fstab file by entering the command nano /etc/fstab.
  4. Edit the UUID under the swap partition, replacing it with the UUID from step 23. You will find the correct UUID under the line # swap was on /dev/vda3 during installation. Press ctrl + X to save and close the file and return to the command prompt.
  5. Enter the command nano /etc/initramfs-tools/conf.d/resume to edit the resume file and replace the UUID with the UUID from step 23. Press ctrl + X to save and close the file and return to the command prompt.
  6. Update initramfs by entering the command update-initramfs -u
  7. Enable the swap file by entering the command swapon /dev/vda3 replacing with your partition as necessary.
Expanding the primary partition

Now that the swap partition has been moved to the end of the disk, we can resize the primary partition to fill all of the remaining space on the disk.

  1. Now we are ready to extend the primary partition to fill the newly created space. Start fdisk on your primary disk with the command fdisk /dev/vda, replacing vda with your device if different.
  2. Type p at the prompt to display the current partitions. The primary partition in this example is /dev/vda2 but you should replace as necessary if your system is different (see step 5 to locate the primary partition).
  3. First, we need to delete the current primary partition. Type d at the prompt to delete a partition and then enter the partition number, in this example it is partition 2.

Note that you should not lose the data on the partition when deleting it, however it would be wise to create a backup first. Changes will not be applied until the w command is executed.

  1. Next, type n at the prompt to create a new partition. We will recreate the primary partition filling the entire free space. Enter the primary partition number, in this example it is partition 2.
  2. Leave the next two prompts blank and press enter on both. This will select the default values, creating a primary partition of the maximum possible size.
  3. Important: when prompted to remove the signature, enter N so that your data is retained.
  4. Type p at the prompt to show the partition information. You should now see that the primary partition is filling all of the remaining space. The size should now also reflect that of your newly sized disk.
  5. Type w to write the changes and exit fdisk.
  6. Enter the command reboot now to reboot the system.
Resize the filesystem

The last thing we need to do is expand the Debian file system in to the newly extended primary partition.

  1. Log back into Debian and then login as root using the command su -
  2. Enter the command resize2fs /dev/vda2, replacing the partition reference as necessary.
  3. Now when you enter the command df -h you should notice that the primary root partition has been expanded into the newly created disk space. This completes the process and you can now enjoy a larger disk on your Debian operating system!
Newly expanded file system

Thanks so much for visiting my site! If this article helped you achieve your goal and you want to say thanks, you can now support my work by buying me a coffee. I promise I won't spend it on beer instead... 😏

3 thoughts on “How To Increase a UTM Virtual Machine Disk Size”

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top