Intro:
I decided to write this after I could not find any documentation on internet how to easily add space to a FreeBSD 10 guest that had zfs on root install. This should show you how to do it easily and quickly. It is important as we may need to add more space from our LVM to our FreeBSD guest at some point, and we need to know exactly how to do that.
Pre-requisites:
I assume you have a Centos host running KVM guests, as well as gdisk installed.
First thing we want to do is extend size of our guest
lvextend -L +10G /dev/vps/sunsaturn (add 10G to sunsaturn) gdisk /dev/vps/sunsaturn (we let gdisk fix partition table or we will not be able to add new space)
Command (? for help): w
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): Y
Have moved second header and partition table to correct location.”
Just save and exit to fix our partition tables.
Now let us run gdisk again to add the new space, since we have following:
gdisk -l /dev/vps/sunsaturn Number Start (sector) End (sector) Size Code Name 1 34 1057 512.0 KiB A501 gptboot0 2 1058 8389665 4.0 GiB A502 swap0 3 8389666 335544286 156.0 GiB A504 zfs0 virt-filesystems --long --parts --blkdevs -h -a /dev/vps/sunsaturn Name Type MBR Size Parent /dev/sda1 partition - 512K /dev/sda /dev/sda2 partition - 4.0G /dev/sda /dev/sda3 partition - 156G /dev/sda /dev/sda device - 160G -
Our last partition can easily be expanded just deleting last partition and add it back with the new space.
gdisk /dev/vps/sunsaturn (now delete last partition(3) and add it back, set code and name back to A504 and zfs0) partprobe /dev/vps/sunsaturn (if for any reason you cannot see the space just run:) gdisk /dev/vps/sunsaturn (then hit "w") partprobe /dev/vps/sunsaturn (now you should be able to do above)
Alright we have expanded our LVM, now we need to restart the guest and enable new space within the guest.
virsh shutdown sunsaturn (actually wait till it is shutdown, till "virsh list" shows it gone) virsh start sunsaturn
IN THE GUEST:
zpool status (find out device and put it below) zpool online -e zroot vtbd0p3 (zfs will now grab the additional space)
That’s it, now you know how to add space on the fly to any FreeBSD guest with zfs on root, on the fly.
Dan.
Update: a few months after writing this I came across this article which does a good representation.