Question

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?

Was it helpful?

Solution

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

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

OTHER TIPS

mkfs/dev/sda

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

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

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.

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

echo | /sbin/sfdisk /dev/sda
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top