Reputation: 1128
There a lots of descriptions out there on how to resize a Virtualbox Disk Image (VDI), and then boot a live CD to resize it's filesystem(s), reboot from the now resized disk and voila: you've extended the size of the filesystems in the VDI.
I would like to do this using the host OS, which is Linux (Ubuntu 12.04 LTS) only. The point of this is to be able to automate it and also have the process take less time. How can I do this?
Upvotes: 1
Views: 1879
Reputation: 16305
I tried various suggestions on how to do this from the net but on an embedded distro (e.g. OpenWrt) the gparted
trick from the guest side isn't going to work (though admittedly parted
might) because you just don't have all the prerequisites installed. So you have to do it from outside the guest.
What I ended up doing was going back to the image file. If you don't have the original image around you can get it from the .vdi:
VBoxManage internalcommands converttoraw file.vdi disk.img
Now you can do something like:
qemu-img resize disk.img +10G
to add 10 GiB to the disk for example. Then:
kpartx -av disk.img
kpartx
should output which loopback device it's using for the block device (e.g. loop0
, AKA /dev/loop0
). Then do this:
ls -la /dev/mapper/loop0p*
to see the devices kpartx
has inserted under the /dev
tree (e.g. /dev/dm-8
) for each partition in the disk image. You'll need to know these, to fake out gparted
which likes it's partitions called something else like /dev/loop0_part
x. So create these fake links for gparted
ln -s /dev/dm-8 /dev/loop0_part1
...
So you can finally do the resize, etc. in gparted
gparted /dev/loop0
Don't forget to clean up after the image is all how you want it:
kpartx -d disk.img
rm /dev/loop0_part1
...
and reimport disk.img
as a .vdi.
VBoxManage convertfromraw --format VDI disk.img disk.vdi
BTW, I did try the accepted answer, but gparted
just wouldn't resize.
Upvotes: 0
Reputation: 1
Simply you have to follow the following steps:
Congratulation, enjoy your free space.
This video will help you:
https://youtu.be/ikSIDI535L0
Upvotes: -1
Reputation: 1128
Looks like this can be achieved (not always with predictable/stable/reliable result) using Qemu's NBD tool(s), as is described by Jeff Waugh in http://bethesignal.org/blog/2011/01/05/how-to-mount-virtualbox-vdi-image/ which essentially goes like this:
sudo aptitude install qemu-utils
sudo modprobe nbd
VBoxManage modifyhd <vdi-file> --resize <new_size>
sudo qemu-nbd -c /dev/nbd0 <vdi-file>
sudo gparted /dev/nbd0
sudo qemu-nbd -d /dev/nbd0
Upvotes: 2