Search code examples
linuxbashmount

Discarding a Linux virtual drive


From what I understand the process of creating a virtual drive in Linux goes like this

fallocate -l size /path/to/file.img;
dd if=/dev/zero of=/path/tofile.img bs=1M count=N;
mkfs -t ext3 /path/to/file.img;
mkdir /path/to/mounted;
mount -t auto -o loop /path/to/file.img /math/to/mounted;

Once I am finished with the drive I issue

umount /path/to/mounted;

All well and good. However, I have not yet quite understood how to deallocate the disk space allocated by the fallocate command. I'd be most obliged to anyone who might be able to tell me what to do.


Solution

  • You can omit the dd call in your example since fallocate is doing the work. To deallocate the disk space simply remove the .img file as you would do with any other file:

    rm /path/to/file.img