[svlug] Need a shell/bash loop over each partition and execute dd && rm

Daevid Vincent daevid at daevid.com
Mon Aug 1 20:05:00 PDT 2011


I use VirtualBox quite a lot, but one of the drawbacks of Linux guest VMs is
that there is no built in way to shrink the .vdi disks. they just
continually grow.
 
However, you can manually shrink them by doing this:
 
sudo dd if=/dev/zero of=./zerofile && sudo rm ./zerofile
 
then execute:
VBoxManage modifyhd %USERPROFILE%\.VirtualBox\HardDisks\myVBVM.vdi -compact
 
The process is more tedious if you're using FreeBSD or other Unix flavors
that have multiple partitions.
 
Can someone give me a little bash-fu that will loop over every partition,
execute that dd and rm command?
 
I'm pretty sure it will involve "df" and sed/awk, but maybe there's a better
way to find all the partitions on ANY unix variant? We mix FreeBSD, Debian,
Ubuntu VMs here for various purposes.
 
Thanks in advance,
 
d.
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.svlug.org/archives/svlug/attachments/20110801/ca38e4dc/attachment.htm


More information about the svlug mailing list