I had to permanently erase data from a few external hard drives before selling them. Some of them were USB, some were NAS (connected through Ethernet). I collected some observations which some people might find helpful.
In most filesystems, deleting files from the filesystem does not really delete the data. It only erases the file reference from the file allocation table, so the computer thinks the space is empty (and so the Windows File Explorer would show the drive as empty). But it is not. After you remove the files, empty the trash, and even format the hard drive, the data is still there. The data can be recovered (without much difficulty) by anyone with physical access to the disk.
To delete the data for good, you need to overwrite the entire disk space with other data. This is referred to as wiping out a hard drive, secure erasing, zeroing out the drive, or permanently deleting of data.
Permanently erasing an external USB magnetic hard drive (HDD) on Windows
- This section concerns HDD, not SDD. To securely erase an SDD, you need different techniques (out of the scope of this article)
- There are various tools that assist in wiping out a hard drive. I found that simple solutions are best: the command line format command (available as a command in the cmd shell).
- The File Explorer format tool (available from the context menu) does not do the job. It has the option Quick Format, which takes a few seconds and does not really delete the data. If you do not use Quick Format, the default Full Format will take longer, which may seem like it is erasing the data. But it does not. It only checks the drive for bad sectors. The data is still there, even after the format (more here). Therefore use the command-line format tool instead.
- The command has /p: option, which will force the overwrite the entire disk space with zero (or random) bytes
- The /p: option allows to specify the number of passes. Many people think that overwriting of the disk needs to happen several times. In fact, this is an urban legend. As explained here and here and here, just one pass is enough: /p:1
- When formatting, you also need to provide a filesystem type. Under Windows, choices are Fat32, NTFS, and exFAT. Pick exFAT. Fat32 is old and has unpleasant limits, such as the file size limit. NTFS is nice but it may not be read by other operating systems such as macOS. If this is an external drive, pick exFAT which is most portable.
- The full command you want to run: format j: /FS:exfat /v:coolname /p:1 (replacing j with the drive name, and coolname with the volume name of your choice)
- However, before doing so…
- Plan several hours, if not days. It will take long. My rule of thumb: 24 hours per 1 Terabyte, on USB 3.1 gen 1.
- Back up your computer beforehand. Why? Because using the format command is scary. Mistake one letter (say, instead of j: you typed d:) and you have accidentally deleted another volume of yours.
- Also, triple-check that the drive letter you picked is correct. The following command will help: wmic logicaldisk get deviceid, volumename, description. As an alternative, run diskmgmt.msc, to ensure you got the drive letter association right.
Once you’ve done all this, you are good to go. After running the format, wait a few hours (or days) and you will see the following:
C:\Users\Pawel>format j: /FS:exfat /v:platinet /p:1 The type of the file system is EXFAT. Enter current volume label for drive J: platinet WARNING, ALL DATA ON NON-REMOVABLE DISK DRIVE J: WILL BE LOST! Proceed with Format (Y/N)? y Formatting 596.2 GB 0 percent completed. Initializing the File Allocation Table (FAT)... Creating file system structures. Format complete. 596.2 GB total disk space. 596.2 GB are available. 262,144 bytes in each allocation unit. 2,441,864 allocation units available on disk. 32 bits in each FAT entry. Volume Serial Number is XXXXXXX
An alternative solution
If the above sounds scary, there is a technically simpler (but more time consuming) alternative with the same effect. Simply overwrite the hard drive with files. First delete your sensitive data (including purging the Trash), and then fill the hard drive with some nonsensitive / rubbish data, until there is no space left.
Then again delete all these nonsensitive files. That’s it. This method may be time consuming, but it works.
Permanently erasing a NAS (network attached storage)
NAS (network-attached storage) are those hard drives that are connected to your home internet with Ethernet cable (rather than connecting with USB). Erasing them is tricky, because each producer may provide different methods. My NAS is 4 GB Seagate Central . Here is how I securely erased it:
- you cannot format it from Windows, because it is not your computer’s drive
- the producer provides no guidelines, and no methods for secure erasing of data. The online interface to Seagate Central has “Clear all” option, which is not documented and it is not clear what this is doing. However, almost certainly it does not perform secure-erase. Shame on you, Seagate
- I did not find any guidelines on the Internet fora either
- I logged into the drive with ssh. The drive is in fact a self-contained Linux server with Linux operating system. You can ssh to it.
- The operating system does not have most of the tools you want (shred, pf, fdisk), which makes your job difficult. It only has dd, which can be used to overwrite the disk with random numbers
- I initially tried to overwrite the space with random data using dd: dd if=/dev/urandom of=/dev/mapper/vg1-lv1 bs=1M . The performance was quite shocking: 1 MBps. I calculated that with this method, cleaning my drive would take more than 1 month. Changing the block size did not make any difference
- I found that many people online complained for unsatisfactory performance of dd
- After some experiments, I found the reason why dd takes so long. It was not about the write speed, or CPU speed. It was about using urandom, which is a pseudo device. Urandom uses the device CPU to generate random numbers, and so the CPU is 100% busy.
- Solution? Overwrite the drive with zeros (from /dev/zero) rather than /dev/urandom. Speedup? 50x. I could write with speed 50 MBps.
- I also successfully adopted an improvement found in this thread, to write data to separate files on the disk, rather than directly to the disk.
- The full command I used is:
sudo dd if=/dev/zero conv=sync,noerror bs=10M | split -a 4 -d -b 1073741824 - onegig.img
Erasing the drive took about 12 hours. The expected output is:
split: onegig2.img1775: No space left on device
Afterwards, it is worth checking with df that the drive is full indeed:
admin@Seagate-433E6C:/shares/Public$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg1-lv1 2913495680 2913495616 64 100% /Data /dev/mapper/vg1-lv1 2913495680 2913495616 64 100% /shares/Public /dev/mapper/vg1-lv1 2913495680 2913495616 64 100% /Data/anonftp/Public /dev/mapper/vg1-lv1 2913495680 2913495616 64 100% /shares/admin /dev/mapper/vg1-lv1 2913495680 2913495616 64 100% /shares/admin.tm [...]
ls will show that the drive has been filled with 1-gig files, which contain zeros. The online interface will show the drive is 100% full:
Now it is a good moment to reset the device to the factory defaults, using Settings/Clear All. It will quick-format the drive, so it will appear 100% empty again. Note that quick format does not erase the data. But we already erased it.