Score:1

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

sh flag

as I am new Linux user I don't really know yet where's path to my disk, so therefore also I don't know how to wipe out data from it.

As I mentioned I would need something that will wipe out a hard disk, so I did a bit of googling and I found out that something like command shred will most likely suit me.

Now, I found out that this is syntax of command:

shred [OPTIONS] FILE [...]

So, I would probably run shred with these options:

shred -vfzu -n 25

Now back to my problem, I don't know what's the path of my hard drive, because I have exactly 4 sda parts in /dev/, and they are:

sda
sda1
sda2
sda5 

So, my question here is which one of these should I even shred? And how can I know it's the right one?

Bruni avatar
cn flag
sda1 is partition 1 on drive sda, sda2 partition 2 on drive sda etc.... It very much depends on what you want to shred and only you know that....
sudodus avatar
jp flag
You should **shred the whole drive (disk), 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. - `shred` can do the job, 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](https://help.ubuntu.com/community/mkusb).
str1ng avatar
sh flag
@Bruni Ahh, alright gotcha...
str1ng avatar
sh flag
@sudodus So using shred would affect HDD? Thanks for info btw
sudodus avatar
jp flag
@str1ng, Shred will overwrite the data on the drive or partition, that you tell it to shred. And you get the best result, when you overwrite the whole disk (drive in linux terminology).
Score:1
cn flag
  • 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.

str1ng avatar
sh flag
Thank you, this was super detailed and useful. Can you explain me more on how exactly does it affects HDD?
mook765 avatar
cn flag
We are writing to files here, but this files are not regular files like text files, this are files representing block-devices such as your HDD or the partitions on it. `/dev/sda` represents the diskspace from the first to the last sector. The others represent the partitons, disk-space from sector x to sector y as defined in the partition table (which resides in `/dev/sda`). So when you shred a partition, you only shred the content of the partition, but nothing changes in the partition table which is stored in the first sectors of `/dev/sda`.
str1ng avatar
sh flag
Ahhh, okay gotcha.
Score:1
jp flag

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.
str1ng avatar
sh flag
This was really in-depth! Thank you for your explanation!
Score:0
cn flag
  • sda is the entire disk
  • sda1 is the first partion of that disk and so on.
  • sdb is the second disk
  • sdb1 is the first partition of the second disk and so on.

To wipe the entire disk with all partiontions, use the entire disk - sda. To wipe a specific partition, specify the partiotion - for instance sda2.

Disk device names can differ on different systems.

Shred is an excellent tool but be warned, it is really easy for an unexperienced user to wipe the wrong partition or disk. If so you loose your data permanently.

BTW, 25 passes will take a long time to complete. I'd change that to 1 or two if it's not Top Secret information we are talking about.

str1ng avatar
sh flag
Ohh alright, so if I want to delete everything I should just specify /dev/sda ... Well, in case I do use shred, I will certainly want to delete everything, I might change it to 5 passes with option to overwrite it with 0's ... Thanks!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.