How can I securely erase a hard drive?
There’s a command-line utility called shred, which overwrites data in a file or a whole device with random bits, making it nearly impossible to recover.
First of all, you need to identify the name of the device.
This might be something like /dev/sdb or /dev/hdb (but not like /dev/sdb1, that’s a partition). You can use sudo fdisk -l to list all connected storage devices, and find your external hard drive there.
N.B. Make sure it is the correct device, picking the wrong device will wipe it.
Unmount all currently mounted partitions on that device, if any. Then run the following, replacing /dev/sdX with the name of your device:
sudo shred -v /dev/sdX
This will overwrite all the blocks on the device with random data three times, the -v flag is for verbose and will print the current progress.
You can add the option -nN to only do this N times, to save time on large capacity devices. This might take a while, depending on the size of your external hard drive (I think it takes twenty minutes or so for my 4 GB flash drive).
You can also set all bits to zero after the last iteration by adding the option -z, I prefer to do this.
sudo shred -v -n1 -z /dev/sdX
After this, you would have to repartition the device. The easiest way is to install GParted and use it:
sudo apt-get install gparted
gksu gparted
Choose your device in the upper-right corner list. Then select Device -> Create partition table to create a partition table on the device.
Then add a single partition that uses all of the unallocated space on the device, choosing fat32 as the file system. Apply the changes by click the Apply button (the green checkmark) in the toolbar.
Tips
- Read the manpage for
shredonline or by typingman shredin the terminal. - Beware that some parts of your disk will not be erased – use the drive firmware “SECURE ERASE” command, such as via hdparm, to properly clean off a disk.
Improve this answerFollow
16311 silver badge33 bronze badges
answered Dec 15, 2010 at 21:06

4,30133 gold badges2222 silver badges1919 bronze badges
- 43Best practice here: disconnect all of your hard drives, plug in the external drive and then do the above off of a live CD to prevent even the possibility of fragging anything that matters. – Nick Pascucci CommentedDec 15, 2010 at 23:09
- 45Note that this answer has been deprecated by the SECURE ERASE method of requesting the drive to erase itself. This should take care of all possible data, and won’t unnecessarily tax your system. You can perform a secure erase, where the drive erases itself, using the
hdparmutility. This method tries to erase the entire drive, including bad sectors. Furthermore it is much faster than overwriting the normal way. It is also the recommended methods for SSD drives, whereshredis an extremely bad idea. – Maarten Bodewes CommentedMar 23, 2013 at 23:24 - 9@owlstead: Could you elaborate? What is SECURE ERASE, and how does one use it? It’s appreciated if you make a separate answer if you have a better one. – Mads Skjern CommentedOct 24, 2014 at 16:36
- 22The comment about using ATA Secure Erase command is misleading. There are serious problems with using SE (regarding the lack of consistent support from vendors and the lack of transparency on the process). Related: security.stackexchange.com/questions/62253 – MV. CommentedJan 26, 2015 at 2:39
- 3@Fiksdal I don’t know, it’s been five years since I wrote this answer and I don’t remember my motivations for phrasing it that way. That said, I think I meant it along the lines of “practically impossible today but plausably possible in the future with enough technological improvement”. – Freyja CommentedMar 25, 2016 at 12:21
Source: https://askubuntu.com/questions/17640/how-can-i-securely-erase-a-hard-drive.