views:

68

answers:

5

I have some partitions on /dev/sda. I want to remove them all of them programatically. One way is to list all partitions and then delete them one by one. Another way is to just execute

dd if=/dev/zero of=/dev/sda

The first option failed when I got some problem with my partition table due to which the listing of the current partitions was not giving any output thereby I was unable to delete any current partition.

The second method is taking too long. Is there any "quick way" to just set the whole hard disk (/dev/sda) as unpartitioned from a shell script?

A: 

mkfs/dev/sda

Be aware that not everything likes to have a whole disk like this.

Ignacio Vazquez-Abrams
A: 

If parted is on your system, you could interact with that and issue commands to delete partitions—and list them too for that matter.

wallyk
+4  A: 

dd if=/dev/zero of=/dev/sda bs=1k count=100

Try that. Should kill the partition table in no time.

Xorlev
Thanks thats what I needed. bs is Bus size, i guess. What does count do?
baltusaj
bs is block size in bytes, so it's writing 100k to the beginning of the device.
Xorlev
A: 

Instead of removing the existing partitions, consider just creating the new ones. Unless you want to ensure that your machine won't boot off the hard drive (for example, to force a netboot on the next startup) in which case the "dd" recipe is fine.

You don't need 100k, 512 bytes will be sufficient.

MarkR
A: 

A more elegant way to do this is to use sfdisk with empty input:

echo | /sbin/sfdisk /dev/sda
caf