Skip to content

How to fill a disk with random data for encryption preparation

September 30, 2012

UPDATE [2013-05-04]: this post has been outdated by How to fill a disk with random data for encryption preparation – reloaded

If you want to encrypt a disk then first step is to fill the space with (pseudo) random data.
Why? Because that’s a mean to hide where your data is and where is not. In other words, if you don’t have the (de|en)cryption key you cannot say whether in that disk there are random, meaningless information. or your, meaningful information; and where they are!
A way to do that is to run dd if=/dev/urandom of=/dev/<your disk device>; you could use random instead of urandom but be aware that random is very^n (n big) slow.
Even if urandon is faster than random it is still to much slow. A quite recent notebook with core i7 can fill a 2 tb usb 2.0 disk in 6 days.
And: what if you have to stop the command? Next time you launch it starts from scratch!!!
A faster and “resumeable” solution is:
1) format the disk (ext2 is fine… no journal is needed)
2) mount it (let’s say in /mnt/mynewdisk)
3) dd if=/dev/urandom of=$(tmpfile -d /mnt/mynewdisk)
If you stopped and now you have only to resume then you can skip 1) and execute 2) and 3) only.

I don’t whether there is some security tricks with filling that disk creating files in a file system.
Can anyone tell?
Here the code


#!/bin/sh

while [ ! -f /tmp/endflag ] ; do {

dd if=/dev/urandom of=$(tempfile -d /media/mynewdisk) &

ddpid=$!;

echo "Working $ddpid ($(date +%Y%m%d-%H%M%S))..." ;

sleep 13m;

kill -USR1 $ddpid;

kill $ddpid;

echo "Work done ($(date +%Y%m%d-%H%M%S)), now sleeping 1m" ;

sleep 1m;

} done | tee /tmp/fill.out

# now let fill each inode

for f in /media/mynewdisk/file*; do

echo $f ;

dd if=/dev/urandom oflag=append conv=notrunc of=$f bs=1;

done

From → Technology

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: