Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: A command to resize a vm #62

Closed
hatched opened this issue Jan 24, 2018 · 73 comments · Fixed by #2353
Closed

Feature request: A command to resize a vm #62

hatched opened this issue Jan 24, 2018 · 73 comments · Fixed by #2353
Milestone

Comments

@hatched
Copy link

hatched commented Jan 24, 2018

I have an existing VM that's run out of space, it would be really nice if I could resize it. Or even better would be a VM with a dynamic size on disk.

@Saviq
Copy link
Collaborator

Saviq commented Jan 24, 2018

The problem with resizing is the filesystem needs to grow, which needs to happen within the instance.

We're increasing the default size from the cloud-image 2.1GB default to 5GB - fortunately that doesn't mean it takes 5GB of your space, as that is allocated dynamically.

We'll allow changing the default size, but I'm not sure yet we'll support resizing. Maybe we should be even more aggressive with the default, since it doesn't bear a cost to start with.

@townsend2010
Copy link
Contributor

I'll just add that we already have the '--disk' option in launch for specifying the size of the virtual disk when launching a new instance.

But yeah, increasing the virtual disk size after launch will still either require a user to resize the partition inside the VM or multipass would need some magic to do it automatically, but we would need to take great care in such a case.

Saviq added a commit that referenced this issue Feb 11, 2019
#62: windows/console: Use select() on session socket for read detection r=townsend2010 a=Saviq
@Saviq
Copy link
Collaborator

Saviq commented Feb 21, 2019

We'll close this on the basis that repartitioning and growing the filesystem is beyond the scope of Multipass. We'll increase the size of the default disk, though.

@okneloper
Copy link

okneloper commented Oct 23, 2020

Guys, this is a HUGE issue! If resizing the disk is not an option the user should be made aware before the VM is even created, not after he has run out of space.... this is so frustrating! After spending all this time to configure the VM I run out of disk space and find out the only option is ditch the whole thing...

The disk space should be made a required setting and there should be a warning that one will have to start over if he runs out of disk space.

@townsend2010
Copy link
Contributor

@okneloper,

I'm not sure which host OS you are using, but I have found that it is possible to resize an instance's virtual disk via qemu-img and on next boot, cloud-init will automatically grow the partition. If you are not sure where the instance's virtual disk resides, please let us know which host OS you are using and we can help you out.

@okneloper
Copy link

okneloper commented Oct 23, 2020

@townsend2010 thanks, I am on windows using Hyper-V and was about to try the Resize-VHD solution from #29, but if you recommend qemu-img I'll go with that.

@townsend2010
Copy link
Contributor

Hi @okneloper,

Sure, Resize-VHD is the way to do it on Windows. You can also use Hyper-V Manager, right click on the instance you are interested in, select Settings..., then select the Hard Drive under IDE Controller 0. From there, you can see the path to the virtual disk. You can also click Edit under the Virtual hard disk and that will bring up the Edit Virtual Hard Disk Wizard. Click Next from here and you will be presented with several different options. Choose Expand -> Next and then fill out whatever size you want to make the disk. Click Next, review the change, and then click Finish.

Then start the instance via Multipass and when you log in, the partition will be fully expanded. Hope this helps!

@okneloper
Copy link

okneloper commented Oct 23, 2020

Thanks. I've tried qemu-img before you posted the above, and it said the disk format doesn't support resizing.

Using Hyper-V GUI seems to have done the trick! I'll continue using the VM and report if there are any issues.

@Saviq Saviq removed the question label Oct 28, 2020
@Saviq Saviq reopened this Oct 28, 2020
@Saviq
Copy link
Collaborator

Saviq commented Oct 28, 2020

I'll actually reopen this, as resizing the block device seems to be enough for at least a good subset of the images we allow running.

@erny
Copy link

erny commented Nov 5, 2020

On OS X (High Sierra) I tried to resize image with qemu-img (5.1.0) without luck. qemu-img info seems to give the right info, but qemu-img check returns a lot of errors, and trying to fix them and then resize, gives an unusable image.

I found this gist, so I tried with /Applications/Docker.app/Contents/MacOS/qcow-tool because I have Docker Desktop installed too:

    /Applications/Docker.app/Contents/MacOS/qcow-tool resize --size=$(( 15 * 1024**3 )) ubuntu-20.04-server-cloudimg-amd64.img

and that seemed to work, df -h returns the new disk size (without any file system resizing).

@winkeesail
Copy link

I need this feature very badly because I run into a situation that my VM is using up the initial space after I have spent so much time setting up a dev environment in the VM and to ditch the whole thing is a big pain.

@Saviq
Copy link
Collaborator

Saviq commented Nov 16, 2020

@winkeesail you commented on two issues, both of which had explanations on how to achieve this in the comments…

@winkeesail
Copy link

winkeesail commented Nov 17, 2020

@winkeesail you commented on two issues, both of which had explanations on how to achieve this in the comments…

Are you saying that I should use qcow-tool resize to do the trick? I tested on primary, after I do resize, the image becomes 2.3 G on host machine, but when I shell into the the VM instance, it still shows it has 4.7G.

@winkeesail
Copy link

winkeesail commented Nov 17, 2020

these tricks make little sense to me, because qcow-tool resize does not affect the image size.

@Saviq
Copy link
Collaborator

Saviq commented Nov 17, 2020

these tricks make little sense to me, because qcow-tool resize does not affect the image size.

You mean the image file size? It won't. The image files will only grow with use.

@winkeesail
Copy link

these tricks make little sense to me, because qcow-tool resize does not affect the image size.

You mean the image file size? It won't. The image files will only grow with use.

Unfortunately, this is not the case on my machine. I use qcow-tool resize --size=$((1024*1024*1280) ubuntu-20.04-server-cloudimg-amd64.img to increase my image from 10G to 12G. After I execute the command, the image size does not change at all, and I login into the VM instance, trying to do things, and it still keeping warning me that No space left on device. Clearly, the VM size has not changed.

@Saviq
Copy link
Collaborator

Saviq commented Nov 18, 2020

Unfortunately, this is not the case on my machine. I use qcow-tool resize --size=$((1024*1024*1280) ubuntu-20.04-server-cloudimg-amd64.img to increase my image from 10G to 12G. After I execute the command, the image size does not change at all, and I login into the VM instance, trying to do things, and it still keeping warning me that No space left on device. Clearly, the VM size has not changed.

I'm assuming the missing ) is a typo here on GitHub. However, the size you gave above was 1280MB, not 12GB (which would be $(( 12 * 1024 * 1024 * 1024 )):

$ multipass launch                        
Launched: suited-emu                                                            
$ multipass info suited-emu | grep Disk
Disk usage:     1.2G out of 4.7G
$ multipass stop suited-emu
Stopping suited-emu -
$ sudo /Applications/Docker.app/Contents/MacOS/qcow-tool resize --size=$(( 12 * 1024 * 1024 * 1024 )) "/var/root/Library/Application Support/multipassd/vault/instances/suited-emu/ubuntu-20.04-server-cloudimg-amd64.img"
qcow-tool: [INFO] Resized file to 22880 clusters (2928640 sectors)
qcow-tool: [INFO] image has 0 free sectors and 22876 used sectors
$ multipass start suited-emu
$ multipass info suited-emu | grep Disk
Disk usage:     1.2G out of 11.5G

@winkeesail
Copy link

Thanks, this is helpful, I typed the wrong size. Fortunately, a smaller size has no harm to my image.

@xinster
Copy link

xinster commented Dec 30, 2020

I ran into the virtual disk size issue today. the default size is up to 5GB but my project requires more. it stopped during the compile : No space left on device (os error 28). How can I resize the VM disk or how can I set up a larger disk size during the installation?

@countingpine
Copy link

Right now, the question of resizing the base disk seems to have an answer of "it depends...", and involves finding the location of the disk image, knowing which tool to use, and how to use it. And I (myself) am not clear if the correct tool can even be assumed to be present at the moment, or if I have to go away and install something else.

But at least once the base disk is resized, growing the partition inside it is at least a procedure that should work the same independently of the host platform.

I think it would be great if multipass were able to do the most complicated/platform dependent step for me, and let me worry about growing partitions/filesystems in the guest.

@Saviq
Copy link
Collaborator

Saviq commented Dec 31, 2020

@countingpine that's exactly what this feature request is about, and we will make it happen, for sure.

@nana-marinbio
Copy link

sudo cp /var/root/Library/Application\ Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img /var/root/Library/Application\ Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img.orig

@townsend2010
sorry, obviously i could not ctrl-c, it should be sudo cp.
I checked the copy with tree and it is there.

I tried the check -r:
qemu-img: Unknown option value for -r (expecting 'leaks' or 'all'): /var/root/Library/Application Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img Try 'qemu-img --help' for more information

I asked help and for check I got:
check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename

@townsend2010
Copy link
Contributor

Sorry, I forgot the all for the -r option. So it should be:
sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img check -r all /var/root/Library/Application\ Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img

@nana-marinbio
Copy link

Sorry, I forgot the all for the -r option. So it should be: sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img check -r all /var/root/Library/Application\ Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img

@townsend2010

check -r
The following inconsistencies were found and repaired: 0 leaked clusters 79011 corruptions Double checking the fixed image now... No errors were found on the image. 78998/81920 = 96.43% allocated, 2.15% fragmented, 0.00% compressed clusters Image end offset: 5178392576

resize
Image resized.

I started image and used shell:

System information disabled due to load higher than 1.0

How can I check size?

@townsend2010
Copy link
Contributor

You can do df -BG / while shelled into the instance or do:
$ multipass exec ubuntu18 -- df -BG /

You should hopefully see under the 1G-blocks header the new size of the virtual disk.

@townsend2010
Copy link
Contributor

@nana-marinbio,

Also, if this did indeed work, you can delete that copy of the image you made in order to save disk space on your Mac.

@nana-marinbio
Copy link

You can do df -BG / while shelled into the instance or do: $ multipass exec ubuntu18 -- df -BG /

You should hopefully see under the 1G-blocks header the new size of the virtual disk.

@townsend2010

iMac-de-Ana:bin AnaPaula$ multipass info ubuntu18

**Disk usage: 4.4G out of 38.6G**

IT WORKED, tks for your patience,
sending a bear hug!

@townsend2010
Copy link
Contributor

@nana-marinbio,

Hooray!!!! 🎉

@Saviq Saviq mentioned this issue Apr 11, 2022
8 tasks
@Saviq
Copy link
Collaborator

Saviq commented Apr 11, 2022

Anyone stumbling here, you can now try the implementation in action in #2353, with snaps under edge/pr2353 channel and Windows and macOS packages.

@linhmtran168
Copy link

qemu-img resize complained the image was corrupt.

qemu-img check -r all found some errors and claimed to have repaired them.

nevertheless, the VM will not start.

Instance stopped while starting

the logs show

[2022-02-15T07:24:03.116] [info] [primary] mirage_block_open: block_config = file:///var/root/Library/Application Support/multipassd/vault/instances/primary/ubuntu-20.04-server-cloudimg-amd64.img?sync=os&buffered=1 and qcow_config = discard=true;compact_after_unmaps=262144;keep_erased=262144;runtime_asserts=false and stats_config = None
[2022-02-15T07:24:03.117] [error] [primary] hyperkit: [ERROR] Mirage block device raised exception: (Failure "Read a header_length of 112 but we computed 104")
[2022-02-15T07:24:03.117] [error] [primary] Mirage-block error: Block device is disconnected
[2022-02-15T07:24:03.117] [error] [primary] Could not open mirage-block device: Invalid argument
[2022-02-15T07:24:03.117] [error] [primary] Could not open backing file: Invalid argument
[2022-02-15T07:24:03.118] [info] [primary] process state changed to NotRunning
[2022-02-15T07:24:03.118] [info] [primary] process finished with exit code 1

I had the same problem as @jstanley0 and thanks to @lucasnetau's comment, I was able to create a new image from the old image and booted the instance successfully again:

$ sudo su
$ cd /var/root/Library/Application\ Support/multipassd/vault/instances/docker-vm/
$ /Library/Application\ Support/com.canonical.multipass/bin/qemu-img-hyperkit convert -p -O qcow2 -o lazy_refcounts=on ubuntu-20.04-server-cloudimg-amd64.img new_image.img
$ mv ubuntu-20.04-server-cloudimg-amd64.img backup.img
$ mv new_image.img ubuntu-20.04-server-cloudimg-amd64.img

@furkan-guvenc
Copy link

sudo apt --fix-broken install

Not worked, also path is wrong in the script:
sudo qemu-img resize ubuntu-20.04-server-cloudimg-arm64.img +20G
need to be:
sudo qemu-img resize /var/root/a/ubuntu-20.04-server-cloudimg-arm64.img +20G

@Kalaikkovan
Copy link

@nana-marinbio,

Ok, you've used the wrong qemu-img for use with HyperKit VM's. Please try the following:

sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img-hyperkit resize /var/root/Library/Application\ Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img 40G

Thanks!

This is perfect , worked for me. Thanks @nana-marinbio @townsend2010

@rewgs
Copy link

rewgs commented Jun 19, 2022

@nana-marinbio,
Ok, you've used the wrong qemu-img for use with HyperKit VM's. Please try the following:
sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img-hyperkit resize /var/root/Library/Application\ Support/multipassd/vault/instances/ubuntu18/ubuntu-18.04-server-cloudimg-amd64.img 40G
Thanks!

This is perfect , worked for me. Thanks @nana-marinbio @townsend2010

I had to amend this slightly, to
sudo /Library/Application\ Support/com.canonical.multipass/bin/qemu-img resize /var/root/Library/Application\ Support/multipassd/qemu/vault/instances/ubuntu/ubuntu-20.04-server-cloudimg-arm64.img 32G

qemu-img-hyperkit resize was not a valid command, but qemu-img resize did it.

(Of course everything after /instances/ubuntu/ is up to you, though).

@daviewales
Copy link

Hi @okneloper,

Sure, Resize-VHD is the way to do it on Windows. You can also use Hyper-V Manager, right click on the instance you are interested in, select Settings..., then select the Hard Drive under IDE Controller 0. From there, you can see the path to the virtual disk. You can also click Edit under the Virtual hard disk and that will bring up the Edit Virtual Hard Disk Wizard. Click Next from here and you will be presented with several different options. Choose Expand -> Next and then fill out whatever size you want to make the disk. Click Next, review the change, and then click Finish.

Then start the instance via Multipass and when you log in, the partition will be fully expanded. Hope this helps!

I tried both this method and the Resize-VHD method, but I'm not getting any additional space. I tried this command:

Resize-VHD -Path C:\ProgramData\Multipass\data\vault\instances\primary\ubuntu-20.04-server-cloudimg-amd64.vhdx -SizeBytes 10GB

But still getting: Disk usage: 4.7G out of 4.7G from multipass info. And similar from df -h.

@androidseb
Copy link

This is not a solution to resizing the disk, but a workaround that I found worked for me to solve the problem of running out of disk space: just extract the folders containing too much data into your physical computer and mount them into the VM.

For example let's say you have a folder taking too much space in your VM's home under /home/ubuntu/.gradle.

Do this from inside the VM:

cd /home/ubuntu
mv .gradle .gradle.old

Then do this from your physical computer:

# Replace "multipass_vm_storage" with whatever folder you decided to store your VM files in
cd ~/multipass_vm_storage
mkdir .gradle
# Replace "primary" with whatever name your VM has
# You can list VMs with the `multipass list` command
multipass mount .gradle primary:/home/ubuntu/.gradle

Then do this from your VM:

cd /home/ubuntu
# Moving all files from the VM-hosted folder to the mounted physical-computer-hosted folder
mv .gradle.old/* .gradle/
# Optionally delete the old empty gradle folder
rm -rf .gradle

I hope this helps!

@townsend2010 townsend2010 added this to the v1.10.0 milestone Jul 29, 2022
@sbs2001
Copy link

sbs2001 commented Nov 11, 2022

I think this was added in recent release of multipass. I'm able to do:

multipass stop primary
multipass set local.primary.disk=30G
multipass start primary

Much cleaner.

@weisdd
Copy link

weisdd commented Nov 15, 2022

@theonewolf
Copy link

@townsend2010 I fond the qemu-img-hyperkit tool thanks to your comment and successfully resized my VM!

Then I saw you guys have added this as a feature and there is nice documentation which @weisdd linked.

Honestly, this is one of the nicest cross-platform VM management tools I've seen! Really smooth on Mac, and I love that I can go to other OS and have a uniform(ish) experience.

@hamdisha
Copy link

I think this was added in recent release of multipass. I'm able to do:

multipass stop primary
multipass set local.primary.disk=30G
multipass start primary

Much cleaner.

thanks, worked for me on Windows 💯

@itsazzad
Copy link

itsazzad commented Mar 18, 2023

multipass info is showing the old size in Disk usage

@junosuarez
Copy link

multipass info is showing the old size in Disk usage

After expanding the disk, you need to expand the partition and extend the filesystem from within the vm, eg with https://manpages.ubuntu.com/manpages/xenial/en/man1/growpart.1.html

@boukandouramhamed
Copy link

If your vm disk is at 100% the changes won't take effect. Try to free some space first and rerun the commands.

I think this was added in recent release of multipass. I'm able to do:

multipass stop primary
multipass set local.primary.disk=30G
multipass start primary

Much cleaner.

@kangarooo
Copy link

I think this was added in recent release of multipass. I'm able to do:

multipass stop primary
multipass set local.primary.disk=30G
multipass start primary

Much cleaner.

In where do i write that on windows 10/11?

@ricab
Copy link
Collaborator

ricab commented Jan 2, 2024

@kangarooo On either Powershell or Command Prompt (CMD).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.