December 3, 2022

How To Delete A Disk Partition In Linux CentOS 7

Abhishek Thakur


A hard drive partition is a section of a data storage device. Disk partitions can be in one of several formats. From NTFS (on Windows) to ext4 (on Linux). Disk partitions start with one number and end with another number. These numbers are addresses on your hard disk. The address points to one byte and ends at another on the disk. Hence, a partition helps you organize the data on a disk. While sometimes in order to organize the data we have to delete a disk portion. In this article, we will show you how to delete a disk partition in Linux CentOS 7.

Linux Default Partition Layout

For most Linux distributions, your /  root Partition is the primary partition. While every other partition – Be it Primary or Logical, mounts to that partition. Linux further categorizes these disk partitions as followed.

  • data partition: normal Linux system data, including the root partition containing all the data to start up and run the system; and
  • swap partition: expansion of the computer’s physical memory, extra memory on the hard disk.

Checking Linux CentOS 7 Disk Partitions

Before deleting the partition let’s understand the partition style so that we don’t mess up. Type in the given command to check the disk partition style in CentOS 7.

# fdisk -l

How TO

In our case the terminal prints out the information about three disks named “sda1” and “sda2” and “sdb1”. Disk “sda1” contains the basic boot information of the OS while the other disk “sda2” contains the user data, swap, and root partitions. You can check that by using the “lsblk” command which is used to display details about block devices.

Check Partition Detail

 

Delete A Disk Partition In Linux CentOS 7

In our case, we are going to delete the partition named “sdb1” from “/dev/sdb”. Select the device for which you want to delete the partition using the given, command.

# fdisk /dev/sdb

Delete Partition

Back up your data before deleting the partition. Deleting a partition will automatically erase all data and recovery will not be possible.

Enter d to delete the partition in disk “sdb”. If there are no other partitions on the disk, the partition will be automatically selected and deleted. If the hard disk contains multiple partitions, enter the number to select the partition.

Delete Partition

Verify that the correct portion is deleted by typing in p (partition view) command. Here you can see that the partition is deleted from the disk “sdb” and does not contain any other partitions.

Delete Partition

Now, type in the w command to write and save changes made on the disk “sdb”.

Delete Partition Linux

Conclusion

These are the basic steps on how to delete a disk partition in Linux CentOS 7. If you want to learn more about working with partitions, I recommend reading the tutorial on creating partitions in Linux. If you’re running an NTFS partition, I recommend reading Mounting NTFS partitions in Linux. Which will be covered in the next sessions.


Buy Linux CentOS 7 VPS @ $ 7.99 only

Popular Blog Posts