I found a very nice tutorial on how to create virtual hard disks, and I am considering using these for my work in order to store reliably and portably large datasets with associated processing results.
Basically, the tutorial consist in doing this:
dd if=/dev/zero of=MyDrive.vhd bs=1M count=500
mkfs -t ext3 MyDrive.vhd
mount -t auto -o loop MyDrive.vhd /some/user/folder
which creates a virtual hard drive of 500MB formatted in ext3 and mounts it somewhere.
Now say I use that file and realise I need more than 500MB, is there a way of "dynamically" resizing the virtual disk? (By dynamically I mean other than creating a new bigger disk and copy the data over.)
Best Answer
There is better alternative than
dd
to extend a file. Thedd
command requires several parameters to run properly (to not corrupt your data). I usetruncate
instead. Despite of its name it can extend the size of a file as well:thus,
safely expands your file by 1 gigabyte. And, yes, it does sparse expansion when supported by the underlying filesystem, so the actual blocks would be allocated on demand.
When a file is expanded, don't forget to run resize2fs:
Also, the whole thing may be done online (without
umount
'ing the device) for file systems that support online resize:updates in-kernel information on a backing file,
and
resizes the mounted file system online