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

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,536
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,677
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,963
  • 13
  • 22
  • 31
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.