# VM File sizing



## Phishfry (Jan 24, 2019)

I am new to VM's so I wonder what is the best strategy for VM file sizing.
For example I am building a Poudiere VM and I truncated my VM for 80GB.
What if I need more later?
Can I DD my VM image into another larger image and grow the filesystem on the VM side?
So I can probably grow a VM but shrinking is not feasible?
Can't DD to a smaller target image because DD is block layer including empty space.
Not much worry. I don't need shrinking. I could see the need to grow.


----------



## SirDice (Jan 24, 2019)

As you've seen in the other threads I'm using sysutils/vm-bhyve. My templates all use ZVOL devices for the disk images. Those are easily expanded by using `zfs set volsize=100GB mypool/DATA/somedisk0` for example. Shrinking is not really feasible indeed, because you simply don't know if that last bit of disk is used or not.

Some VMs use ZFS and setting autoexpand is usually enough, for other situations you would need to resize the partition using gpart(8) and perhaps growfs(8) if you use UFS. For UFS images sysutils/firstboot-growfs can be useful. Those firstboot-* scripts can easily be triggered again after the actual first boot simply by `touch /firstboot`.


----------



## Phishfry (Jan 24, 2019)

aragats covered the dd commands here:
https://forums.freebsd.org/threads/increase-size-of-bhyve-vm.63274/


----------



## SirDice (Jan 24, 2019)

One thing I can give as a tip when creating partitions on the VM, a default 'automatic' partitioning uses freebsd-boot, freebsd-ufs (or freebsd-zfs) and freebsd-swap, in that order. To make resizing easier it's better to use freebsd-boot, freebsd-swap and then freebsd-ufs or freebsd-zfs as last partition. Expansion is easier because the swap partition won't get in the way.


----------



## Phishfry (Jan 24, 2019)

Looking at this post by aragats I can pass a whole disk. That sounds interesting to try.
https://forums.freebsd.org/threads/...nted-at-full-physical-disk.60679/#post-349158


----------



## Phishfry (Jun 4, 2019)

Alrighty I had a need to increase images as I am now making FreeBSD images with a custom release makefile.
Problem is I have my custom build down to 200MB but when I open the image in a VM it is out of space.
Here is what I did:
Resize VM image on host:
`dd if=/dev/zero bs=1M count=400 >> /vm/freebsd1.img`
So this adds 400 Megabytes of zeros at the end of my image file thus enlarging it.

Then inside the VM
`gpart resize -i 2 ada0`
`gpart resize -i 1 ada0s2`
`growfs -y /dev/ufs/FreeBSD`

What is really strange to me is that this image uses UEFI but uses a slice disk arrangment.
From inside the VM:
`sysctl machdep.bootmethod`
machdep.bootmethod: UEFI


----------



## aragats (Jun 5, 2019)

IMHO, It's easier and faster to use truncate(1) instead of `dd`.


Phishfry said:


> What is really strange to me is that this image uses UEFI but uses a slice disk arrangment.


UEFI does support MBR disks.


----------



## Phishfry (Jun 5, 2019)

My `growfs` line would not work with the raw device node name. I had to use the label.
That took quite a while to figure out.
I am working off a release image so it had a label assigned. I am neutering the release/Makefile a little at a time.


----------

