Linux Remove All Partitions / Data And Create Empty Disk

To remove all partitions and data from a disk and create an empty disk in Linux, you can use the fdisk utility, which is a standard disk partitioning tool available on most Linux distributions. Here are the steps to follow:

WARNING: These steps will permanently delete all data on the disk. Please ensure that you have backed up any important data before proceeding.

  1. Open a terminal window on your Linux machine.
  2. Type the following command to list all disks attached to your system:
sudo fdisk -l
  1. Identify the disk that you want to erase. Be careful to identify the correct disk, as all data on the selected disk will be permanently deleted.
  2. Type the following command to start the fdisk utility for the selected disk:
sudo fdisk /dev/<disk_name>

Replace <disk_name> with the name of the disk that you want to erase, such as /dev/sda.

  1. Once you are in the fdisk utility, type the following command to display the partition table for the disk:
p

This will list all existing partitions on the disk.

  1. Type the following command to delete each partition on the disk:
d <partition_number>

Replace <partition_number> with the number of the partition that you want to delete, as listed in the partition table.

  1. Repeat step 6 for each partition on the disk.
  2. Once all partitions have been deleted, type the following command to write the changes to the partition table:
w

This will permanently delete all data on the disk.

  1. Type the following command to create a new empty partition table on the disk:
sudo fdisk /dev/<disk_name>
  1. Once you are in the fdisk utility, type the following command to create a new empty partition table:
o

This will create a new empty partition table on the disk.

  1. Type the following command to write the changes to the partition table:
w

This will create an empty disk with no partitions or data.

You can now use the mkfs command to create a new file system on the disk if needed.

Leave a Comment