Secure wipe a disk in Linux with DD command

Here is a quick example how to secure erase a disk or a partition with the Linux DD command. In the example I am using an input file of /dev/urandom instead of /dev/random as it’s quicker to generate random data with urandom. The output file can be either the disk ‘/dev/sdb’ or a single partition on the disk ‘/dev/sdb1’ Examine the output of ‘fdisk -l’ command, i’m not responsible for any loss of data.

Identify the disk
-Below is the output of fdisk -l command
-We can see the first disk below is the system disk ‘/dev/sda’ with two partitions ‘/dev/sda1’ & ‘/dev/sda2’. One of the partitions is a Linux LVM volume. We do NOT want to wipe this one.
-The second disk in my example is a 1GB disk ‘/dev/sdb’ that I attached to the VM and created two partitions on it ‘/dev/sdb1’ & ‘/dev/sdb2’.

[root@localhost ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c128a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        5222    41430016   8e  Linux LVM

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xff9a9e51

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          60      481918+  83  Linux
/dev/sdb2              61         130      562275   83  Linux

Secure Erase the disk With DD
-This will overwrite the entire disk ‘dev/sdb’ along with the two partitions on it ‘/dev/sdb1’ and ‘/dev/sdb2’
-This command takes a little while to run. We are overwriting the disk with urandom data.

[root@localhost ~]# dd if=/dev/urandom of=/dev/sdb
dd: writing to `/dev/sdb': No space left on device
2097153+0 records in
2097152+0 records out
1073741824 bytes (1.1 GB) copied, 410.258 s, 2.6 MB/s
[root@localhost ~]#

Secure Erase a single partition
-The below command would overwrite a single partition

[root@localhost data1]# dd if=/dev/urandom of=/dev/sdb1
dd: writing to `/dev/sdb1': No space left on device
973313+0 records in
973312+0 records out
498335744 bytes (498 MB) copied, 88.8434 s, 5.6 MB/s
This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *