How to securely delete/wipe out a hard disk so it's hard to recover data?

Solution 1:

  • shred /dev/sda will shred the whole disk from the first to the last sector, so everything, including partition table will be erased.

  • shred /dev/sda1 will shred the first partition on the disk. This will destroy the filesystem in this partition, the partition table entry for this partition remains.

  • shred /dev/sda2 will shred the second partition on the disk. If this is an extended partition which acts as a container for sda5, then /dev/sda5 will be completely erased, but the partition table entry for /dev/sda2 remains.

  • shred /dev/sda5 will erase the contents of this partition, the partition itself will remain.

Of course, you will need root privileges, so use sudo or run as root. Very helpful might be a command like

lsblk -f

wich will give you sufficient information about your devices.

Since shredding the whole drive or a partition which is currently in use will most probably end with unwanted side effects, consider booting from USB.

Solution 2:

General

All these actions should be performed when booted from another drive for example a USB drive.

You should erase the whole drive, that is /dev/sdx, where x is the device letter, in your case a. You should be very careful, because that drive letter may change, and if you get it wrong, you might destroy valuable data.

HDD and shred

shred can erase the data on a HDD, hard disk drive, but many people claim that it is overkill to overwrite several times. It is enough to overwrite with zeros once, which you can do with other tools, and it will be faster, and cause less wear of the hardware. You can use

  • Disks alias gnome-disks or
  • mkusb.

SSD (and HDD) connected via SATA or NVME

If you have an SSD connected via SATA or NVME, you should avoid using the tools above. Instead you should use the built-in tool to remap the links between the logical memory locations and physical memory cells. This can be done via the command line tool hdparm in Ubuntu. This works like advanced encryption, where the key is thrown away and is much faster and causes much less wear compared to overwritng.

A fairly new hard disk drive (HDD) connected via SATA can also be remapped using hdparm.

  • Lock the drive with hdparm and the option --security-set-pass

  • Erase the drive with hdparm and the option --security-erase

  • Unlock the drive with hdparm and the option --security-unlock

See man hdparm for more details.

SSD (and HDD) connected via USB

Warning: Using the built-in tool via hdparm is very risky and should be avoided, when the drive is connected via USB.

USB pendrive and memory card and other drives connected via USB

You can use

  • Disks alias gnome-disks or
  • mkusb

to wipe the whole device of a USB pendrive or memory card and other drives connected via USB.

  • A HDD connected via USB can also be wiped with shred as decribed above.