6

I need to safely format my hardrive. I booted from a usb key and I am planning to run the following command on the whole hard drive:

sudo shred -v -n3 -z /dev/the-partition

My question is: how do I identify all the partitions that there are in order to totally wipe out the hard drive?

Here's the output of lsblk

NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0     7:0    0   1.8G  1 loop /rofs
loop1     7:1    0    91M  1 loop /snap/core/6350
loop2     7:2    0  34.6M  1 loop /snap/gtk-common-themes/818
loop3     7:3    0 140.7M  1 loop /snap/gnome-3-26-1604/74
loop4     7:4    0   2.3M  1 loop /snap/gnome-calculator/260
loop5     7:5    0    13M  1 loop /snap/gnome-characters/139
loop6     7:6    0  14.5M  1 loop /snap/gnome-logs/45
loop7     7:7    0   3.7M  1 loop /snap/gnome-system-monitor/57
sda       8:0    1   7.5G  0 disk /cdrom
├─sda1    8:1    1   1.9G  0 part 
└─sda2    8:2    1   2.4M  0 part 
nvme0n1 259:0    0 238.5G  0 disk 

and here's is df -h

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           786M  1.7M  785M   1% /run
/dev/sda        1.9G  1.9G     0 100% /cdrom
/dev/loop0      1.8G  1.8G     0 100% /rofs
/cow            3.9G  331M  3.6G   9% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           3.9G     0  3.9G   0% /tmp
tmpfs           786M   44K  786M   1% /run/user/999
/dev/loop1       91M   91M     0 100% /snap/core/6350
/dev/loop2       35M   35M     0 100% /snap/gtk-common-themes/818
/dev/loop3      141M  141M     0 100% /snap/gnome-3-26-1604/74
/dev/loop4      2.3M  2.3M     0 100% /snap/gnome-calculator/260
/dev/loop5       13M   13M     0 100% /snap/gnome-characters/139
/dev/loop6       15M   15M     0 100% /snap/gnome-logs/45
/dev/loop7      3.8M  3.8M     0 100% /snap/gnome-system-monitor/57
nourdine
  • 225
  • 9
    Do you really need to shred each partition (/dev/sda1, /dev/sda2, /dev/sda3, etc.) separately? If you have one disk drive you can just shred the whole drive (/dev/sda) – FedKad May 13 '19 at 10:30
  • 11
    Before using shred on an NVME or SSD drive read this: https://superuser.com/questions/1336292/is-using-shred-to-wipe-linux-ssds-safe – FedKad May 13 '19 at 11:54
  • I tried hdparm -I /dev/ nvme0n1 (to check if shred is supported by the SSHD) but it says: HDIO_DRIVE(identify) failed: Inappropriate ioctl for device. Any idea why it says ttah? – nourdine May 13 '19 at 12:56
  • 2
    Is it because of the space character between /dev/ and nvme0n1? – FedKad May 13 '19 at 15:09
  • 1
    You should not "shred" an SSD, SSHD or NVME SSD. This will only add a large amount of wear to the drive, and usually does not erase all the data on it. Use secure erase on such devices instead. This actually erases all the blocks and/or destroys the drive's internal encryption key, rendering all the data irretrievable without wearing out the flash. – Michael Hampton May 14 '19 at 02:09
  • @FedonKadifeli no it's not. How weird! Any other way I can find out if shred is supported? – nourdine May 14 '19 at 08:44
  • @MichaelHampton how do you perform the "secure erase"? – nourdine May 14 '19 at 08:54
  • @MichaelHampton by doing sudo shred -v -n3 -z /dev/the-partition. But I need to find out if that operation is indeed supported by my SSD and I am having troubles doing that (see above comments) – nourdine May 14 '19 at 11:42
  • No, shred does not do secure erase at all. This will not erase all data on a SSD and will cause excessive wear. – Michael Hampton May 14 '19 at 18:40

5 Answers5

17

Why not shred then entire device (important! choose the right device to shred!):

shred /dev/nvme0n1

... rather than

shred /dev/nvme0n1p1
Eric Mintz
  • 2,516
  • 12
  • 24
  • 3
    I have the impression /dev/sda is the USB from which OP booted. But OP want to shred dev/nvme0n1. – mook765 May 13 '19 at 10:48
  • 3
    I should have clarified: I was using /dev/sda as an example device. The point is, whichever device you need to shred, shred the entire device rather than partition at a time (I just edited my suggestion above to reflect that). So in your case, schred /dev/nvme0n1 – Eric Mintz May 13 '19 at 10:58
  • 2
    @EricMintz Please update your answer, either to indicate /dev/sda is an example, or (preferably) to use /dev/nvme0n1. It's best for every reader if the answer actually matches the question ;) – marcelm May 13 '19 at 17:12
7

I like lsblk, it show device name and partition inside it, as well the mounted partition.

:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465,8G  0 disk 
├─sda1   8:1    0   100M  0 part 
├─sda2   8:2    0   122G  0 part 
├─sda3   8:3    0     1K  0 part 
├─sda5   8:5    0   7,6G  0 part [SWAP]
├─sda6   8:6    0  69,9G  0 part /
└─sda7   8:7    0 266,2G  0 part /home
sr0     11:0    1  1024M  0 rom

sudo fdisk -l gives more detail, but it requires superuser access.

~$ sudo fdisk -l
Disk /dev/sda: 465,8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xe0ec1799

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048    206847    204800   100M  7 HPFS/NTFS/exFAT
/dev/sda2          206848 255999999 255793152   122G  7 HPFS/NTFS/exFAT
/dev/sda3       256002046 976771071 720769026 343,7G  5 Extended
/dev/sda5       256002048 272001023  15998976   7,6G 82 Linux swap / Solaris
/dev/sda6       272003072 418486271 146483200  69,9G 83 Linux
/dev/sda7       418488320 976771071 558282752 266,2G 83 Linux

I always uses lsblk to detect the drive, then register /dev/zero to wipe the disk.

Liso
  • 15,377
  • 3
  • 51
  • 80
  • ok I ran lsblk and it gave me the followings: loop0, loop1, loop2, sda, sda1, sda2, nvme0n1. Which ones shall I shred? Thanks – nourdine May 13 '19 at 10:01
  • @nourdine What do you want to achieve ? To delete your main hard disk or delete external hard disk ? Also adding lsblk output to your main post probably help ! – Liso May 13 '19 at 10:29
  • main hard disk. There is no external. – nourdine May 13 '19 at 10:30
  • Only /dev/sda*'s. – FedKad May 13 '19 at 10:31
  • 2
    @nourdine Shred only /dev/sda to wipe entire hard disk. Anyway nvme0n1 indicate that your uses ssd, again please edit your post and add output of lsblk. – Liso May 13 '19 at 10:32
  • @FedonKadifeli what is nvme0n1 then? It is by far the biggerst partition – nourdine May 13 '19 at 10:33
  • @Jim /dev/sda/ is only 7.5 GB – nourdine May 13 '19 at 10:34
  • @Jim please see amended question – nourdine May 13 '19 at 10:40
  • 1
    /dev/sda seems to be your CDROM device (and the media in the CDROM drive seems to have 2 partitions). You need to shred your disk drive which seems to be /dev/nvme0n1 . Please paste the output from df -h command. – FedKad May 13 '19 at 10:45
  • @FedonKadifeli that makes sense ... that is approximately the size of the usb key from where I am running ubuntu live. Will paste df -h in a minute – nourdine May 13 '19 at 10:48
  • df -h output added – nourdine May 13 '19 at 10:54
  • df does not show your nvme0n1 disk as mounted; which is OK, since you have booted from a removable device. As root you can use mkdir /old_disk; mount /dev/nvme0n1 /old_disk to have a last look (df, ls /old_disk, etc.) at your data on your disk. Also, if you have booted to a desktop environment, the Disks utility (gnome-disks) might have been more useful in a GUI environment. – FedKad May 13 '19 at 11:31
  • @FedonKadifeli why should I give a last look to my data? I am backed up everything already in an external hard drive. Am I missing something? – nourdine May 13 '19 at 12:46
  • 2
    Just as a last check to verify that you are erasing the correct data. (Only for paranoids! ) – FedKad May 13 '19 at 12:48
2

To get a more meaningful report from lsblk without the noise from dozens of loop devices use:

$ lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT,SIZE,MODEL | egrep -v "^loop"

NAME         FSTYPE LABEL            MOUNTPOINT   SIZE MODEL
nvme0n1                                           477G Samsung SSD 960 PRO 512GB               
├─nvme0n1p9  swap                    [SWAP]       7.9G 
├─nvme0n1p7  ext4   Old_Ubuntu_16.04 /mnt/old    23.1G 
├─nvme0n1p5  ntfs                                 859M 
├─nvme0n1p3                                        16M 
├─nvme0n1p1  ntfs                                 450M 
├─nvme0n1p8  ntfs   Shared_WSL+Linux /mnt/e         9G 
├─nvme0n1p10 ext4   Ubuntu_18.04     /mnt/clone  27.2G 
├─nvme0n1p6  ext4   New_Ubuntu_16.04 /           45.1G 
├─nvme0n1p4  ntfs   NVMe_Win10       /mnt/c     363.2G 
└─nvme0n1p2  vfat                    /boot/efi     99M 
sr0                                              1024M DVD+/-RW DW316  
sda                                             931.5G HGST HTS721010A9
├─sda4       ntfs   WINRETOOLS                    450M 
├─sda2                                            128M 
├─sda5       ntfs   Image                        11.4G 
├─sda3       ntfs   HGST_Win10       /mnt/d       919G 
└─sda1       vfat   ESP                           500M 
0

If you want to completely wipe everything:

  1. Do not use shred, it's primarily meant for files, not disks.
  2. Just wipe the whole disk /dev/nvme0n1, instead of each partition individually.
  3. Download this DBAN fork and use it to securely wipe your drives.
ThunderBird
  • 1,955
DaPeda
  • 1
0

Addendum: When using the "use the whole disk device" method, check if there is a HPA set up (with hdparm -N, please read the manual for the version at hand, getting hdparm command lines wrong can mess up things BAD), and remove it in that case.