UFS GPT corrupt on guest drive after resize inside Virtualbox

These are the steps taken to reproduce the error (host is Windows 10):
  1. Open Oracle Virtualbox and create a new virtual machine, FreeBSD 64 bits. Choose to add virtual drive later.
  2. Download prebuilt image disk "FreeBSD-13.0-RELEASE-amd64.vhd".
  3. Attach the disk to the virtual machine.
  4. Start the guest FreeBSD and do configuration (update, create user, etc.)
  5. Power off the virtual machine
  6. On Virtualbox, go to File --> Virtual Media Manager... --> select "FreeBSD-13.0-RELEASE-amd64.vhd" --> change size to bigger value. I did it twice, first to 10GB and later to 16GB --> Apply
  7. Start again the virtual machine, and check that GPT partition is corrupt. It detects the proper size of the whole drive, but not the free space.

mUnNeNT.png


sNcqAM1.png


How can I fix this? And how to do it properly next time?
 
Looks like your adap4 is located somewhere in the middle of the free space. It's not adjacent to adap3 (2.097.152 vs 2.163.866) and at the end of adap4 there is another chunk of unused space (18.807.647 to 20.971.509). I think I would remove adap4 and then try to re-create it using the whole free space left.
 
I've noticed that if I resize the vhd right after downloading it, gpart detects the new size properly and it's added to root partition. However if I resize the vhd after having used the virtual machine it's when gives GPT error. Maybe the vhd comes uninitialized and takes as much free space as possible before first use?

Probably for Virtualbox it's a better idea to convert the drive format:
& 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' clonehd FreeBSD-13.0-RELEASE-amd64.vhd FreeBSD-13.0-RELEASE-amd64.vdi --format vdi
 
I've noticed that if I resize the vhd right after downloading it, gpart detects the new size properly and it's added to root partition. However if I resize the vhd after having used the virtual machine it's when gives GPT error. Maybe the vhd comes uninitialized and takes as much free space as possible before first use?
The VM images have sysutils/firstboot-growfs installed.
 
Ideally boot in single user mode and use gpart after any growth of the disk.

Also:

 
Those "firstboot" scripts are triggered by the existence of a /firstboot file. So a touch /firstboot and a reboot would trigger the firstboot-growfs script again.
 
Those "firstboot" scripts are triggered by the existence of a /firstboot file. So a touch /firstboot and a reboot would trigger the firstboot-growfs script again.
Thank you very much. Does /firstboot do anything else than firstboot-growfs?
 
Back
Top