I have a VirtualBox dynamic image of Xubuntu 20.04 of maximum size 70 GB. The current size of the image is 9 GB.
When I try to convert it to a .img file with the commandVBoxManage clonehd 'xubuntu.vdi' xubuntu.img --format RAW
the image size keeps growing far beyond 9 GB, and it would probably go on until 70 GB (I stopped the process when it crossed 20 GB).
How to turn it into an image of size 9 GB, so that later on I can write to a 16 GB USB drive as a portable install?
The host OS is Kubuntu 20.04.
01 Answer
You have to compact the VDI disk file first by using command below:
VBoxManage modifymedium xubuntu.vdi --compactSee 8.22 VBoxManage modifymedium of for details.
Then convert it to RAW using command below:
qemu-img convert xubuntu.vdi -O raw xubuntu.rawIf the resulting RAW file is still big, then you have to shrink it more by using Gparted (move, resize partitions here) using commands below:
sudo losetup -P /dev/loop137 xubuntu.raw
gparted /dev/loop137After shrinking the partition with GParted, you can unmount the image.
sudo losetup -d /dev/loop137You can check the actual partitions inside RAW image by running fdisk -l xubuntu.raw.
Then you can shrink the RAW image to fit its partitions:
qemu-img resize --shrink xubuntu.raw 9216MThen finally test the image in VM
kvm -m 2048 -drive file=xubuntu.raw,format=rawand then write it to USB drive using GNOME Disks or Etcher or dd or ddrescue (I prefer it over plain dd, as it shows progress, time estimate and speeds).
Then, open Gparted, and extend the partition in the USB drive to the maximum possible size. Otherwise, the root partition would be stuck at (let's say) 9 GB, even if the size of the USB drive is (let's say) 32 GB, and you won't be able to install new programs despite having free space on the drive.
Note: if USB drive shows missing UUID error (as the UUID may change), then you can boot with the fallback mode in the Advanced option in the GRUB menu.
5