Lately, I ran out of space on one of my Multipass virtual machine. I decided to write down here, the steps I followed to expand the VM disk size.

Consider the list of Multipass virtual machines below:

kenneth@laptop:~$ multipass list

Name                    State             IPv4             Image
altruistic-impala       Running           172.17.244.151   Ubuntu 22.04 LTS
awx                     Stopped           --               Ubuntu 22.04 LTS
database                Stopped           --               Ubuntu 22.04 LTS
haproxy                 Stopped           --               Ubuntu 22.04 LTS

The VM named altruistic-impala is the one concerned by the disk expansion. It has the following specs:

kenneth@laptop:~$ multipass info altruistic-impala

Name:           altruistic-impala
State:          Running
IPv4:           172.17.244.151
Release:        Ubuntu 22.04.3 LTS
Image hash:     870bd58b5c1e (Ubuntu 22.04 LTS)
CPU(s):         1
Load:           0.02 0.03 0.00
Disk usage:     7.6GiB out of 7.6GiB
Memory usage:   180.4MiB out of 892.2MiB
Mounts:         --

As you can see above, the VM has a 7.6GiB disk, used at 100% of its capacity.

I will expand the disk size to 32G (feel free to put with the desired size you want):

kenneth@laptop:~$ multipass stop altruistic-impala 
kenneth@laptop:~$ multipass set local.altruistic-impala.disk=32G  
kenneth@laptop:~$ multipass start altruistic-impala 

Note: Substitute altruistic-impala in all the commands of this article with the name of your target VM.

At this point, I should be done. According to Multipass documentation, the steps above are enough. The VM disk size should have been expanded, and the root partition should have been resized. But in my case, I got one surprise: the previous statement is partially true. There’s a small bit of free space required for the resize operation.

Why do I say that?

Because I found out that if your VM disk had no space left while you made the expansion, the disk size will change BUT the root partition won’t be automatically resized. Then the modifications won’t be reflected in the Operating System. So after expanding the disk, I need to manually expand the main partition and extend the filesystem from within the VM. Read along if you’re in the same situation.

You can use the lsblk command on your VM as below to verify:

kenneth@laptop:~$ multipass exec altruistic-impala -- lsblk

NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0     7:0    0  63.4M  1 loop /snap/core20/1974
loop1     7:1    0 111.9M  1 loop /snap/lxd/24322
loop2     7:2    0  53.3M  1 loop /snap/snapd/19457
sda       8:0    0    32G  0 disk
├─sda1    8:1    0   7.9G  0 part /
├─sda14   8:14   0     4M  0 part
└─sda15   8:15   0   106M  0 part /boot/efi
sr0      11:0    1    52K  0 rom

We can see that the sda disk size has successfully been increased from 8G to 32G. BUT its main partition sda1 mounted on / still showing 7.9G as size. We need to resize that partition to utilize all free available space.

Let’s access to the shell of the altruistic-impala VM:

kenneth@laptop:~$ multipass shell altruistic-impala

From that shell:

ubuntu@altruistic-impala:~$ sudo parted /dev/sda

GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart                                                
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 50331648 blocks) or continue with
the current setting? 
Fix/Ignore? Fix                                                           
Partition number? 1                                                       
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? Yes                                                               
End?  [8590MB]? 100%                                                      
(parted) quit
Information: You may need to update /etc/fstab.

We also need to resize the filesystem:

ubuntu@altruistic-impala:~$ sudo resize2fs /dev/sda1
  
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/sda1 is now 8360187 (4k) blocks long.

And now we’re done! We check it out:

ubuntu@altruistic-impala:~$ lsblk
                                         
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
fd0       2:0    1     4K  0 disk 
loop0     7:0    0  53.3M  1 loop /snap/snapd/19457
loop1     7:1    0  63.4M  1 loop /snap/core20/1974
loop2     7:2    0 111.9M  1 loop /snap/lxd/24322
sda       8:0    0    32G  0 disk 
├─sda1    8:1    0  31.9G  0 part /
├─sda14   8:14   0     4M  0 part 
└─sda15   8:15   0   106M  0 part /boot/efi
sr0      11:0    1    52K  0 rom

The /dev/sda1 partition is now used at 25% against 100% at the beginning of this write-up:

ubuntu@altruistic-impala:~$ df -h

Filesystem      Size  Used Avail Use% Mounted on
tmpfs            96M  5.7M   90M   6% /run
/dev/sda1        31G  7.6G   24G  25% /
tmpfs           476M     0  476M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/sda15      105M  6.1M   99M   6% /boot/efi
tmpfs            96M  4.0K   96M   1% /run/user/1000

It corresponds to 7.6GiB used out of 30.9GiB:

kenneth@laptop:~$ multipass info altruistic-impala

Name:           altruistic-impala
State:          Running
IPv4:           172.17.244.151
Release:        Ubuntu 22.04.3 LTS
Image hash:     870bd58b5c1e (Ubuntu 22.04 LTS)
CPU(s):         1
Load:           0.08 0.10 0.07
Disk usage:     7.6GiB out of 30.9GiB
Memory usage:   148.2MiB out of 951.9MiB
Mounts:         --

That’s all !


Thank you for reading this article all the way to the end! I hope you found the information and insights shared here to be valuable and interesting. Get in touch with me on LinkedIn

I appreciate your support and look forward to sharing more content with you in the future. Until next time!

This post also appears on Medium