Re: Wiping a disk partition

From: Odhiambo Washington <odhiambo_at_gmail.com>
Date: Wed, 02 Jul 2025 08:18:55 UTC
On Mon, Jun 30, 2025 at 5:48 PM Frank Leonhardt <freebsd-doc@fjl.co.uk>
wrote:

> On 25/06/2025 15:28, Tomek CEDRO wrote:
> > On Wed, Jun 25, 2025 at 12:18 PM Odhiambo Washington <odhiambo@gmail.com>
> wrote:
> >> I have this:
> >> ```
> >> root@gw:/home/wash # df -h
> >> Filesystem     Size    Used   Avail Capacity  Mounted on
> >> /dev/ada0p2    1.8T    552G    1.1T    33%    /
> >> devfs          1.0K      0B    1.0K     0%    /dev
> >> fdescfs        1.0K      0B    1.0K     0%    /dev/fd
> >> procfs         8.0K      0B    8.0K     0%    /proc
> >> linprocfs      8.0K      0B    8.0K     0%    /compat/linux/proc
> >> linsysfs       8.0K      0B    8.0K     0%    /compat/linux/sys
> >> /dev/ada1p2    1.8T    856G    802G    52%    /disk2
> >> ```
> >>
> >> What is the fastest way to wipe all data on /dev/ada1p2?
> > The fastest way would be to overwrite partition with zeros:
> >
> > dd if=/dev/zero of=/dev/ada1p2 bs=1g status=progress
> >
> > In order to overwrite data safely so these are not easily recovered
> > you can use /dev/random in several overwrite loops, then in the last
> > iteration you can use /dev/zero to mark partition clean (or leave
> > random data for someone to wonder). Note /dev/random is much slower
> > than /dev/zero.
> >
> > You may also use badblocks utility in destructive-write test to
> > overwrite with different patterns and check disk condition at the same
> > time but this will be slowest solution :-)
> >
> > https://man.freebsd.org/cgi/man.cgi?query=badblocks
> >
> > Have fun :-)
>
> Right answer!  As a refinement you might want to umount the volume first
> to avoid stability problems.
>
> The question was how to wipe the data on a partition. Some people have
> suggested secure erasing the entire drive. You cannot issue a SCSI
> command to erase a software defined partition that SCSI doesn't know
> anything about. Deleting the files or creating a new FS doesn't wipe the
> file contents. Without additional context, overwriting the partition
> with zeros is the best answer.
>
> Except... given that the partition IS mounted it presumably has 852Gb of
> files, and the real question might have been how to delete all the files
> in the /disk2 directory rather the wiping the partition- so Tomek - why
> do you ask?
>
> Regards, Frank.
>

My question was "What is the fastest way to wipe all data on /dev/ada1p2?"
It looks like delete, wipe, and erase all have different meanings here.
I should have explained that "rm -rf" would take a long time, so I needed a
faster command.
I didn't even want a secure erase, just the deletion.
I concluded that there is no straight answer to my question.
What I ended up doing was dd if=/dev/ada1 of=/dev/ada2  bs=1g
status=progress
The 2nd disk is a replica of the 1st disk, and I use it only for creating a
backup of the first disk.

-- 
Best regards,
Odhiambo WASHINGTON,
Nairobi,KE
+254 7 3200 0004/+254 7 2274 3223
 In an Internet failure case, the #1 suspect is a constant: DNS.
"Oh, the cruft.", egrep -v '^$|^.*#' ¯\_(ツ)_/¯ :-)
[How to ask smart questions:
http://www.catb.org/~esr/faqs/smart-questions.html]