Re: Overwriting with random data

"Carlos E.R." <[email protected]>
Newsgroups comp.os.linux.misc
Organization Tebibyte_Retro_Gaming
Message-ID <[email protected]>
On 2026-08-24 12:10, Nuno Silva wrote:
> On 2026-08-24, Carlos E.R. wrote:
> 
>> On 2026-08-24 00:28, vallor wrote:
>>> At Sun, 23 Aug 2026 13:50:30 +0200, "Carlos E.R." <[email protected]> wrote:
>>
> [snipping a lot to keep this shorter, apologies if I ended up snipping
> too much]
>>
>>>> I wrote a program that writes bytes on big partitions.
>>>>
>>>>
>>>> excerpted:
>>>>
>>>> const
>>>>         sourcefilename = './BigRandom';
>>>>         rawdest: string = '';     // example: '/dev/sda11'
>>>>
>>>>         shuflecount = 1024;
>>>>         arraysize = 1023;
>>>>         ChunkSz=1048576;
>>>> type
>>>>         tCacho= array [1..ChunkSz] of byte;
>>>>
>>>> var
>>>>       Fin, Fout: file of tCacho;
>>>>       gotresult: Word;
>>>>
>>>>       BigData : array [1..shuflecount] of tCacho;
>>>>       OutputIndex : Int64;	// counts MiB written.
>>>>
>>>>
>>>> begin
>>>>
>>>> // writes one MiB
>>>>          {$I-}write(Fout,BigData[RandomIndex]);{$I+}
>>>>          gotresult:= ioresult;
>>>>
>>>>
>>>>
>>>> The purpose of the program is to fast fill a partition or disk with
>>>> nearly true random data. It is as fast as dd could be.
>>>
>>> SHRED(1)                 User Commands                 SHRED(1)
>>>
>>> NAME
>>>          shred  -  overwrite  a  file  to  hide its contents, and
>>>          optionally delete it
>>>
>>> SYNOPSIS
>>>          shred [OPTION]... FILE...
>>>
>>> DESCRIPTION
>>>          Overwrite the specified FILE(s) repeatedly, in order  to
>>>          make  it harder for even very expensive hardware probing
>>>          to recover the data.
>>
>> Not the same thing.
> 
> IIRC shred can do the same, and on block devices too, what's the
> difference here? block sizes?


I mentioned my code because it accesses huge devices in pascal, way 
beyond 4G.

c186282 said:
   Note Lazarus/FPC *says* it supports huge seek numbers
   but DOESN'T ... limited to maybe 4gb.


Some functions work, others don't. This does not work:

const
      rawdest: string = '';     // example: '/dev/sda11'
      ChunkSz=1048576;

type
      tCacho= array [1..ChunkSz] of byte;

var
    Fin, Fout: file of tCacho;


begin

    rawdest:= ParamStr(1);
    writeln('Apparent size of ', rawdest, ' is ', filesize(Fout));


It writes '0' (I am currently erasing an 8TB disk)


Notice that I am not using a file of bytes, but a file of 1 MiB arrays. 
And I am not using seek, but writing contiguously.


Now the shred part.


Using true random data is slow, specially if the disk or partition is 
very big. Depends on how fast can the machine create new random data 
(see man random and urandom). So I do tricks to do it faster. And shred 
does it several times.

The algorithm I use is:

   Fill a 1 GiB file with true random data.
   Read that file into ram.
   repeat
      take 1 MiB of that and write it into the destination device
      advance
      Every 100 advances, replace 1 MiB of the array of random bytes
         with new random data
   until end of device


So, the data is truly random, but used repeatedly (and slowly renovated).

-- 
Cheers, Carlos.
ES🇪🇸, EU🇪🇺;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.