How to zero out unused space on UFS filesystem?

1

I have a FreeBSD system installed in VirtualBox and i want to compact its vdi. AFAIK, before doing this i need to fill unused space with zeros so VirtualBox can shrink it.

On Windows there is sdelete utility, that does exactly this. What can be used on FreeBSD?

arrowd

Posted 2015-04-06T09:19:48.310

Reputation: 288

Answers

2

The usual method – also used by sdelete – is to fill the disk with files containing only null bytes:

dir="/" i=0

while dd if=/dev/zero of="$dir/empty.$((++i))" bs=8M count=128; do
    echo "wrote empty.$i"
done

sync

rm -f /empty.*

user1686

Posted 2015-04-06T09:19:48.310

Reputation: 283 655