zero out unused space in FreeBSD

Hi,

I have FB FreeBSD system running as a VM in XenServer. Exporting this VM as xva results in a big file. I was informed zeroing the filesystems before exporting can reduce the xva file size. However the command to zero in the file system causes error.

Code:
 cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

/boot: write failed, filesystem is full
cat: stdout: No space left on device

Code:
AN# df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ad0s1e    8.0G    1.2G    6.2G    17%    /
devfs          1.0K    1.0K      0B   100%    /dev
/dev/ad0s1a    193M    438K    178M     0%    /boot
/dev/ad0s1d    8.0G    1.1G    6.2G    16%    /abcd
/dev/ad0s1f     15G     80M     13G     1%    /var
/dev/ad0s1g    2.8G    7.0K    2.6G     0%    /tmp

The df output seems to be fine:


Any tips on how to resolve this?

Thanks,
Arvind
 
bv_arvind said:
...
/boot: write failed, filesystem is full
cat: stdout: No space left on device

This error message is a desired part of the zeroing procedure. Let's break your command in two parts:

[CMD="1. #"]cat /dev/zero > zero.fill; sync; sleep 1; sync;[/CMD]
This asks the system to create a file named zero.fill and to infinitely write to it using /dev/zero as the source. Well it can't be infinitely, because writing will reach the point, once the "filesystem is full". And hence the write error which is therefore desired.

[CMD="2. #"]rm -f zero.fill[/CMD]
The second part of the command asks the system to delete the just created file, releasing all space that it occupied, and all the left space now contains zeros only.

bv_arvind said:
... The df output seems to be fine:

Of course, because the file has been deleted, it is simply gone.

bv_arvind said:
Any tips on how to resolve this ?

Simply ignore the error message.
 
As far as I know filesystems can't be zeroed. You'd have to zero the device/partition using# dd if=/dev/zero of=/dev/[i]something[/i](possibly adding bs=1m or something thereabout) and then create the filesystem.

In any case, the "no space left on device" error is perfectly normal because you're filling the device with zeroes until it's full, which at some point it will be indeed.
 
fonz said:
As far as I know filesystems can't be zeroed. You'd have to zero the device/partition using# dd if=/dev/zero of=/dev/[i]something[/i](possibly adding bs=1m or something thereabout) and then create the filesystem.

Well, or write into a file. The idea is the same, although with dd(1) you can give it a larger buffer size to speed it up.

% dd if=/dev/zero of=/empty.file bs=1m
 
Back
Top