I'm planning on selling a USB external hard drive that currently contains an old Ubuntu installation with stored passwords and banking information.
How can I securely erase the drive before selling it?
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/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
N 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.
shredonline or by typing
man shredin the terminal.
Just 'zero' it using the
System > Administration > Disk Utility
sudo dd if=/dev/zero of=/dev/sdX bs=1M
This will overwrite the whole disk with zeros and is considerably faster than generating gigabytes of random data. Like all the other tools this won't take care of blocks that were mapped out for whatever reason (write errors, reserved, etc.), but it's highly unlikely your buyer will have the tools and the knowledge to recover anything from those blocks.
PS: Before you Bruce Schneier fanboys downvote me: I want proof that it's possible to recover data from a non-ancient rotational hard drive that has been overwritten with zeros. Don't even think about commenting otherwise! :P
Have a look at this definitive question on Security Stack Exchange
This discusses various secure deletion options, along with physical destruction and wiping so you can decide which option may be your best bet.
Remember though that the current recovery status for different storage is as follows:
I generally use a destructive read-write test using
badblocks -w. The two major advantages are
Note that if the report indicates a problem, I'd no longer sell the disk as it is likely to fail soon.
Usage example (if your disk is
sudo badblocks -wsv /dev/sdd
sv for progress bar + verbose)
That'll fill the entire drive with almost completely random data.Then you can set all bits back to 0 with dd.
Actually, dd should be able to randomize all of the information.
You said that you have stored banking information on your harddisk.So i would suggest you to run any one of the following command from a live cd (where hdX is your harddrive).
dd if=/dev/zero of=/dev/hdX
dd if=/dev/random of=/dev/hdX
dd if=/dev/urandom of=/dev/hdX
For your information:
See the following links,
you can use wipe
sudo apt-get install wipe
You can use that software or use the following command:
shred -vfz -n ? (drive)
Were the "?" is, put the number of times you wan to shred the drive, then for were "(drive)" is, put the drive that you want to shred. Once your done, do whatever you want with it. I think that this method is more effective since you can control what is done to your drive and have immediate results.
Darik's Boot and Nuke (commonly known as DBAN) [...] is designed to securely erase a hard disk until data is permanently removed and no longer recoverable, which is achieved by overwriting the data with random numbers generated by Mersenne twister or ISAAC (a PRNG). The Gutmann method, Quick Erase, DoD Short (3 passes), and DOD 5220.22-M (7 passes) are also included as options to handle Data remanence.
DBAN can be booted from a floppy disk, CD, DVD, or USB flash drive and it is based on Linux. It supports PATA (IDE), SCSI and SATA hard drives. DBAN can be configured to automatically wipe every hard disk that it sees on a system, making it very useful for unattended data destruction scenarios. DBAN exists for Intel x86 and PowerPC systems.
DBAN, like other methods of data erasure, is suitable for use prior to computer recycling for personal or commercial situations, such as donating or selling a computer. In the case of malware infection, DBAN can be used before returning a disk to production.
One more advantage of shred over dd in this scenario: I have a faulty disk that I need to return to the vendor for an exchange.
dd halts at the first bad block, and fails to clobber the rest (unless I painfully use skip=... to jump ahead each time it stops).
shred ignores write errors and happily continues in this case.
Those recommending to use shred are giving bad advice. Shred's own man page says it's effectively useless on journaled filesystems, which Ubuntu is almost guaranteed to be using if you don't change its filesystem defaults (ext3 and ext4 are journaled. As is resierfs and Reiser4 as well as many MANY other common Linux filesystems.).
Not to mention shred is completely useless for completely blanking or randomizing a disk, as it only works on individual files or sets of files (On the filesystem level, not a raw data level.). If you want to securely wipe a disk, you gotta use dd on the drive's main device node (For example: /dev/sdc instead of /dev/sdc1) while nothing is mounted on it.
It WILL take a while, but unlike shred it will completely and IRREVERSIBLY wipe a hard disk from MBR to final sector. Also, BIG WARNING on dd, make sure you are using it on the correct device or you'll at least PARTIALLY wipe the wrong disk. This could be disastrous if you accidentally use dd on a system drive, which will not only make it unbootable, but may irreversibly corrupt any given partition on the drive. This has given it the nickname "disk destroyer."
Shred is NOT a reliable tool for securely wiping a drive. If you're selling or giving your computer away the CORRECT way to empty the drive is to zero or randomize it with dd and never, ever use shred, as filesystem journals will effectively restore shredded files with no effort at all.
Easiest way to do that is use :
sudo shred -fv /dev/xxx
where xxx is device, to ensure what device you have, type :
sudo fdisk -l
The device are indicated after disk word and to the colon char :, like this :
Disk /dev/sde: 500.1 GB etc...
Don't mount file systems of your disk you want wipe etc. Shred will do what you want in part of time. -z option is for last run with 0 to hide wipe and is not necessary to wipe data.
Best way is to use dd like wrote previous users:
sudo dd if=/dev/urandom of=/dev/xxx bs=1M
use urandom device as it is more modern and better way to obtain random pattern.
Other tools at this moment can be older and by less people develop. Shred is in core application of Linux.
Best is to use the secure erase function of ATA drives. Secure erase erases the drive at firmware level. Can't get more secure.
First check if secure erase is supported:
sudo hdparm -I /dev/sdX | grep -i security
(replace sdX with sda/sdb/sdc, whatever your disk is).
If you see no output, just use dd:
sudo dd if=/dev/zero of=/dev/sdX bs=1M
If you see output, check if the device is not frozen:
sudo hdparm -I /dev/sdX | grep -i frozen
If not frozen, set password to "Eins":
sudo hdparm --user-master u --security-set-pass Eins /dev/sdX
Optional: you might want to know how how long this will take:
sudo hdparm -I /dev/sdX | awk '/for SECURITY ERASE UNIT/'
Then execute the erase:
sudo hdparm --user-master u --security-erase Eins /dev/sdX
Then wait. Apparently for a 1TB disk this might take 3 hours or more.
There's a nice script which automated these steps.
If the dd cmd is not working, you can use the redirection method to wipe out the data.
cat /dev/urandom > /dev/sd**a** # depends on your hdd location
alternatively you can use cp (copy cmd) to overwrite the previous data.
cp /dev/urandom /dev/sd**a** # depends on your hdd location