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

Cloud images are not resized according to the required disk size #473

Closed
galdor opened this issue Aug 2, 2022 · 2 comments
Closed

Cloud images are not resized according to the required disk size #473

galdor opened this issue Aug 2, 2022 · 2 comments

Comments

@galdor
Copy link
Contributor

galdor commented Aug 2, 2022

In the current state (vm-bhyve 1.5), vm created from a cloud image have a disk whose size is the virtual size of the cloud image size.

For example:

vm img https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img
vm create -i ubuntu-22.04-server-cloudimg-amd64.img -s 100G

This creates a VM whose disk is 2.2GB, which is the virtual size of the Ubuntu cloud image (check with qemu-img info <vm-path>/.img/ubuntu-22.04-server-cloudimg-amd64.img), even though we expect a VM with a 100GB disk.

One way to fix this would be to use qemu-img resize. But since we probably do not want to touch the original image, would it be acceptable to modify core::write_img to:

  • Copy $_imgpath to ${img_path}.tmp.
  • Call qemu-img resize ${img_path}.tmp $_size.
  • Run qemu-img dd on the temporary image.
  • Delete the temporary image.

Of course it would mean extra disk usage during the operation. I do not think this is a huge deal, but someone may have a better idea.

I can write the patch if maintainers (who are they?) agree.

@sarcasticadmin
Copy link
Contributor

I just ran into this as well with some of my testing. I had this issue while using the default value for disk0_dev=file in my template. This does not seem to be an issue for disk0_dev=sparse-zvol or disk0_dev=zvol which still honor disk0_size.

Simplest way Ive been able to reproduce this behavior was to manually do what the vm create command does when disk0_dev=file in a template.

Starting with my raw image:

~ # ls -lah myimage.img 
-rw-r--r--  1 root  wheel   2.4G Dec 29 09:40 myimage.img

Create the disk:

~ # truncate -s 10G disk0
~ # ls -lah disk0 
-rw-r--r--  1 root  wheel    10G Dec 29 09:15 disk0

Write the image to it:

~ # qemu-img dd -O raw if=myimage.img of=./disk0 bs=1M
~ # ls -lah disk0
-rw-r--r--  1 root  wheel   2.4G Dec 29 09:39 disk0

Refs in the codebase:

~ # vm version
vm-bhyve: Bhyve virtual machine management v1.6-devel (rev. 106001)
~ # qemu-img --version
qemu-img version 7.1.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers

@mateuszkwiatkowski
Copy link
Collaborator

This is tracked in new issue: #535

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

No branches or pull requests

3 participants