Delete partitions & MBR/GPT on disks

So far we have seen how to create MBR or GPT and partitions on any mass storage disk. If you do not know then refer my two previous posts:

In this post, we will delete partitions present on disk as well as delete MBR/GPT on disks.

Please note that the process of deleting partitions is same for both MBR/GPT.

Delete partitions on disk

In order to delete a partition with parted utility, rm command is used. Before we delete a partition make sure it *must* be un-mounted because we cannot delete a mounted a partition. Let's see it.

The rm command needs partition number. we can view partition number from print command.
  • As we saw before, run parted /dev/sdb to get into parted mode
  • Run print command to view partition number
  • Run rm <partition_number> e.g. rm 1 will delete 1st partition
  • Run print command and you no longer see partition 1 because it has been deleted now. so simple right? 
  • Run quit command to exit from parted mode
All above commands are shown below,





















We have deleted a partition present on /dev/sdb but disk still contains GPT record. If we use any disk manipulation utility such as parted, fdisk, gdisk, then the existing record will be used which we may not want in some cases.

Delete MBR/GPT on disk

To remove MBR/GPT record, we need to overwrite the area in disk which contains these records with zeros or raw data. How to do it? Open the terminal and run below command with root permission. That's it !!! 
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=1

dd command is used to write, read, copy and convert low level data. bs means block size which we have given 1 MB and count means how many times you want to do this operation for given block size. In short, this command fills out zeros in first 1MB area of disk.

After running dd command, if you check your disk status with parted utility, it will show Error: /dev/sdb: unrecognised disk label, which means we have deleted MBR/GPT record, same can be seen from below figure.















Notes:
  • I have just zeroed out first 1MB  with dd command for sanity though MBR/GPT record present in some KiB.
  • You can use "/dev/urandom" as well instead of "/dev/zero" in dd command which fills out some random data instead of zeros

Comments

Popular posts from this blog

MBR partitioning with 'parted' utility

Replace default splash screen in Yocto

Disk Partitioning: MBR vs GPT