Expand NetBSD root partition
I already wrote how to expand LVM partition on NetBSD, however expanding root partition is not as easy as none root partition.
I've got schema prepared for small machines like firewalls and vpn terminators, which has only one 10GB disk, and whole filesystem is on one partition, and mount point is just / , so disklabel looks like this:
For those not familiar with FFS or UFS file systems used in *BSD. First you need to create slice for BSD on disk, then inside slice you can set partitions, becasue of this partition c and d are reserved on BSD systems, and partitions for users start with "a", then "b", and then "e" and so on. So above disklabel shows:
Disklabel is using sectors of disks instead of bytes, so 10GB is 20971520 sectors.
Disk size in template can't be changed during creation of VM, so only option is to create 10GB machine, then shutdown (or not even start) it, and alter disk size. Lets do it in Xen Orchestra.
And it worked on turned off machine
Machine booted without any problem, but disklabel didn't change, however looking at dmesg showed new size in sectors which is basically previous size doubled.
Lets use this new size with disklabel. We can edit disklabel with disklabel -e xbd0 in vi.
I altered total sectors, partition c and d to new sizes:
Now we need to do some math. We need to expand only root partition, without touching swap partition. Disklabel position of partitions are controlled by two variables size which is how big is partition, and offset which repesents when it starts. So first partition start at 0 sector (offset 0), and have size of 18874368 sectors), then swap start at sector when partition a ends (offset 18874368), and have size of 2097152 sectors. If we add one size to another we got total sectors of original disk size. So using built in calculator (bc) we can now count correct values.
Substract from total sectors size of swap:
Then, if ne offset for swap is calculated and its size didn't change it means that all sectors down to 0 will be new size of partition a: as well. We can now update disklabel accordingly:
Fear not if you mess something up when counting, disklabel will warn you that is too big, or overlap with another one partition.
Not much surprise - no effect at all yet, still original 10GB layout:
It is time to grow partition with resize_ffs. Remember to always use raw device when doing so, hence rxbd0a instead of xbd0a. I didn't run fsck and said yes, because it changes nothing to problem that will occur next.
Resize completed, but new size is still unusable, on this stage I decided maybe it will show up after reboot, so I did, aaand .... its gone:
This looks bad. This was clean shutdown, but fsck said that we need to fsck anyway. However fsck now is complaining about super blocks, and is not checking filesystem, because ... it is clean.
Fortunatelly there is option -f (force), you can add -y as well which automatically confirms every question:
# fsck_ffs -f -y /dev/rxbd0a
Lets try to grow filesystem once again in single user mode just after fscking, then reboot to check if system boots properly and has new size
To my surprise after that system booted without any problem, and df showed new correct size:
Now I only have to shut down this machine and create another template from it with new disk size.