How to Securely Wipe Your Disk and What Happens After You Zero Your Disk using dd on Linux?


I decide to terminate one of my VPS server (QuickHostUK) and don’t want any data be leaked even they are not so critical important. You may first backup all your important data before you try one of the following method to delete your server.

Quick but Less secure

The known method:

# rm -fr /

if run using root (or sudo) will remove all the files in the hard disk(s). Please note that, this command will delete all the files/folders from the / (root), meaning that if you have several hard disks mounted at different places, e.g. /mnt/usb, /mnt/c etc the files will be deleted as well.

However, when files are removed, the content are not wiped but only the meta data removed from the file system e.g. /ext4. If you take such disk to harddisk data recovery center, you might have pretty good chances of recovering most of the files. The disk recovery software will read the sectors by sectors anyway.

Here is a in-browser Javascript Linux Emulator where you can safely execute the “rm -fr /” if you are curious and don’t you have to worry that your files will be deleted, because it is just an emulator in the browser.

How to Securely Wipe Your Disk?

If your data is so so important and you don’t want absolutely anyone (using any powerful tool) to recover them later, you can use the Linux command dd. The easiest command to wipe the disk is:

1
dd if=/dev/zero of=/dev/sdX
dd if=/dev/zero of=/dev/sdX

where X could be a, b, c depending on your harddisk. You can use the command df -h or fdisk -l to double check which hard disk you like to wipe out.

the if=/dev/zero specifies the input is from the Linux zero device, which means that if will wipe out the of device by all zeros. You can also use:

1
dd if=/dev/urandom of=/dev/sdX
dd if=/dev/urandom of=/dev/sdX

to wipe your disk with random characters. The dd command also takes optional bs and count parameter, which specifies the block size and the count, for example:

1
dd if=/dev/urandom of=/dev/sdX bs=4092 count=1024
dd if=/dev/urandom of=/dev/sdX bs=4092 count=1024

What Happens After You Zero Your Disk using dd on Linux?

First thing: don’t try this command just because you are curious. It will actually wipe out all your data. The Linux OS will not warn you (it will just assume that this is what you want).

what-happens-if-you-zero-disk-using-dd How to Securely Wipe Your Disk and What Happens After You Zero Your Disk using dd on Linux? BASH Shell harddisk linux

what-happens-if-you-zero-disk-using-dd

As you see in the above screenshot of running dd under root user. When the command is entered, the hard disk is spinning wiping out each sector. I didn’t wait till end, and press Ctrl + C to abort, but it seems too late. By default the block size is 512 Bytes, and the number of records written is 1875353, which amounts to 950MB space wiped to zero.

And it seems pretty much that it damages the Linux OS very bad, which will report any command as “Segmentation fault”. You can’t connect to it, obviously.

cannot-connect-after-disk-wiped How to Securely Wipe Your Disk and What Happens After You Zero Your Disk using dd on Linux? BASH Shell harddisk linux

cannot-connect-after-disk-wiped

Feature Comments

Firstly, I don’t understand why you would erase the partition you are currently working on. Seems to me like there is no guarantee the job will actually finish when you attempt to erase a disk in that way, but it might.

We don’t know though. The author didn’t let dd finish and quit the process after a short while, so not all data is actually wiped, but then goes to “show” that some commands don’t work any more. If that’s all you wanted to achieve, “rm -rf /” would’ve sufficed. Not being able to issue some commands does not mean the data isn’t there any more and can never be read again. You might even be able to get a lot of it back just by rebuilding the partition table.

However, the command itself “dd” may not finish and end up with ‘segmentation fault’ as well. In this case, not all data are wiped.

Update: here is an example output if you are patient enough to wait for dd to finish.

1
2
3
4
dd if=/dev/zero of=/dev/root
dd: writing '/dev/root': No space left on device
125513+0 records in
125512+0 records out
dd if=/dev/zero of=/dev/root
dd: writing '/dev/root': No space left on device
125513+0 records in
125512+0 records out

This experience has also been re-blogged in Chinese.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
938 words
Last Post: Review of WiseUp "Smart" Eyewear Sunglass Camera (USB Chargeable 1080p Video Spy Camera)
Next Post: A Glimpse on Microsoft Research Cambridge

The Permanent URL is: How to Securely Wipe Your Disk and What Happens After You Zero Your Disk using dd on Linux?

Leave a Reply