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

John Sokol john.sokol at gmail.com
Mon Aug 1 20:55:52 PDT 2011


#!/bin/bash
for h in $( `df | grep -v "Available" | awk '{print $NF}'`   );do
   echo "Cleaning partition $h"
   sudo dd if=/dev/zero of=$hzerofile && sudo rm $hzerofile
done


I recommend testing this with just the echo first.  Make sure the list of
partitions looks correct.
Some df behave differently so you need to verify it first before you just
run you nasty dd command to fill up the drives.

I think writing all 0 till the disk fills and dd errors out is a bad thing
because it could cause running processes to crash.

But there is your bash foo for today.




On Mon, Aug 1, 2011 at 8:05 PM, Daevid Vincent <daevid at daevid.com> wrote:

> 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.****
>
> ** **
>
> ** **
>
> ** **
>
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.svlug.org/archives/svlug/attachments/20110801/e4fc1527/attachment.htm


More information about the svlug mailing list