Dear visitor, in case we do not cover a topic you are looking for, then feel free to ask in our freshly created forum for IT-professionals for a solution. We hope our visitors can help you out with your questions. Have a good one. ~ Tom.

How to remove all partitions / data on a disk

To remove / delete all data on your disk drive, you can use one of the following methods below. Have a look a gparted in case you need a live DVD to boot from to perform the steps.

Old good dd command

Use the following dd command to remove data from /dev/hdX:

# dd if=/dev/zero of=/dev/hdX bs=512 count=1

OR for sata disk, use the following syntax:

# dd if=/dev/zero of=/dev/sdX bs=512 count=1

In this example, empty sata disk /dev/sdb, enter (you must be login as the root user):

# fdisk /dev/sdb
# dd if=/dev/zero of=/dev/sdb bs=512 count=1
# fdisk -l /dev/sdb

Securely wipe hard disk with shred

You can use the shred command to securely remove everything so that no one recover any data:

# shred -n 5 -vz /dev/sdb

The scrub command

You can use a disk scrubbing program such as scrub. It overwrites hard disks, files, and other devices with repeating patterns intended to make recovering data from these devices more difficult. Type the following command to securely wipe out /dev/sdb:

# scrub -p dod /dev/sdb

Remove paritions with fdisk

fdisk can be used to display or manipulate a disk partition table. To remove all partitions perform the following steps.

First, get a listing of your current partition scheme, type the following command:

# fdisk -l.
Disk /dev/hda: 20.0 GB, 20060651520 bytes
255 heads, 63 sectors/track, 2438 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1        1024     8225248+   b  W95 FAT32
/dev/hda2   *        1025        2438    11357955    c  W95 FAT32 (LBA)

Disk /dev/hdb: 80.0 GB, 80060424192 bytes
255 heads, 63 sectors/track, 9733 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1   *           1        2432    19535008+  83  Linux
/dev/hdb2            2433        2554      979965   82  Linux swap / Solaris
/dev/hdb3            2555        6202    29302560   83  Linux
/dev/hdb4            6203        9733    28362757+   5  Extended
/dev/hdb5            6203        9733    28362726   83  Linux

From the output above, there are two disk listed:

– /dev/hda – 20 GB
– /dev/hdb – 80 GB

Let us assume that we want to remove a partition /dev/hdb3 from /dev/hdb disk. Type the following command:

# fdisk /dev/hdb
The number of cylinders for this disk is set to 9733.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):

Now type p command to list partition:

Command (m for help): p
Disk /dev/hdb: 80.0 GB, 80060424192 bytes
255 heads, 63 sectors/track, 9733 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdb1   *           1        2432    19535008+  83  Linux
/dev/hdb2            2433        2554      979965   82  Linux swap / Solaris
/dev/hdb3            2555        6202    29302560   83  Linux
/dev/hdb4            6203        9733    28362757+   5  Extended
/dev/hdb5            6203        9733    28362726   83  Linux

Now let us say you want to delete /dev/hdb3 (3rd partition). Type the d command to delete a partition:

Command (m for help): d

It will prompt you for the partition number. Type 3: (repeat the step for every partition)

Partition number (1-4): 3

Verify that partition deleted:

Command (m for help): p

Now save the changes and exit to shell prompt. Type the w command:

Command (m for help): w

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.