Virtual Disks in Linux

creating a VHD volume of size 1GB image

sudo dd if=/dev/zero of=VHD.img bs=1M count=1200
sudo mkfs -t ext4 /media/VHD.img
sudo mkdir /mnt/VHD/
sudo mount -t auto -o loop /media/VHD.img /mnt/VHD/

source

or xfat:

sudo mkfs.exfat /media/VHD.img

or hfs+

sudo mkfs.hfsplus /media/VHD.img

or Fat32

sudo mkfs.vfat /media/VHD.img

resizing a volume (increasing) for ext4

Append 500MB to the end

sudo dd if=/dev/zero bs=1M count=500 >> VHD.img

Then resize (after unmounting)

sudo resize2fs VHD.img

resizing a volume (reducing) for ext4

  • Resize the Filesystem Inside the Image

resize2fs VHD.img 800M

  • Shrink the Disk Image File

sudo truncate -s 800M VHD.img

You can't resize an exfat file system so you will need to recreate the exFAT filesystem in the rezied image (requiring moving the files out of the image and putting back again