What is the different between sdelete -c and -z?
I've learned from this article to use sdelete as a step to shrink VDI file:
sdelete -c c:
But what does the -c
('Clean free space' as described by its help text) mean? Doesn't it write free space with zero? And what about -z
(Zero free space)? What is the different between sdelete -c and -z?
Edit
I tried the step in the article mentioned before, but failed to reduce the size of the .vid
file. Then I followed this superuser post, and changed the option -c
to -z
, and succeeded.
So it seems -z
writes zeros to free space, and -c
writes something else (random bits possibly).
I think this is a common mistake. Maybe the -z option was not available in earlier versions. SDelete 1.61 says
-z Zero free space (good for virtual disk optimization)
Note that doing so will first expand your hard disk to the full size. Only in the shrinking process by VMWare it will become smaller again.
A quick test on my machine:
-z took 1:01 minutes
-c took 2:11 minutes
Which indicates that -z only writes simple zeros whereas -c is the military standard wiping DoD 5220.22-M as written on the SDelete website.
Current documentation (and program version 2.01):
-
-c
: Clean free space. Specify an option amount of space to leave free for use by a running system. -
-z
: Zero free space (good for virtual disk optimization).
But in older versions it was reversed:
-
-c
: Zero free space (good for virtual disk optimization). -
-z
: Clean free space.
But what do they do?
Clean creates the largest file it can, and fills it with random data, and then fills it with zeros. This is what most people think of as wiping, and it's overkill.
The downside is that if you are using a virtual disk, or inside a virtual machine, or running it on a storage space: the underlying storage system will be forced to allocate resources to hold you random data, and then hold zero. Hopefully then the underlying storage system will realize that all that space that was just allocated to your drive can be reclaimed because all those sectors simply contain zeros.
-z Zero: Simply writes zeros to all sectors. This is the option you want, for many reasons:
- wiping with random data is overkill (reading data is not practically possible; i.e. one bit at a time though a microscope is not feasable)
- some SSDs can detect that you are writing zero to a sector, and can use that to mark the sector as free (similar to a TRIM)
- most virtual storage systems (VMWare, Hyper-V, Windows Virtual Disks, Storage Spaces) realize that you are writing an entire sector of zeros, and take the opportunity to reclaim space in the underlying storage file
- SSDs won't know that your ultimate goal is essentially a glorified TRIM, and (like the virtual disks) be forced to fill sectors that already contained zeros, with non-zeros, only to have you fill it with zeros again. That's terrible for your SSDs.
Source: Mounted a virtual hard disk, and watched the I/O operations that sdelete took in both modes.
tl;dr: Use -z Zero. It's faster, better, safer.