To create a disk partition in Linux CentOS 7 you just need to format the disk in the system. In brief, disk Partitioning is the process of dividing a disk into one or more regions, the so-called partitions. Therefore if a partition is created, the disk must store the information about its location and size. This information is stored in the partition table which is usually located in the first sector of a disk and so on. We need to create a partition because you can’t start writing files to an empty disk. The disk must contain at least one partition having a file system. You can build a  partition that can have all the spaces of your disk, or divide the space into 20 different partitions for ease. In any case, the disk must contain at least one partition.

Why Disk Partition Is Needed

  • To upgrade Hard Disk (to include a new Hard Disk to the system)
  • Dual Booting (Multiple Operating Systems on the same machine)
  • Efficient disk management
  • Ensure backup and security
  • Work with different File Systems using the same system

Listing Disk In Linux CentOS 7

Before moving further, let’s list the connected disk to the system first. This will help you choose the disk on which you want to create a partition. Run the following command in the terminal having root access to list all the existing disks.

# fdisk -l     ##fdisk is a linux tool that is used to configure disk partition table

List partiton Table

The given output shows the partition table of all the disks connected to the system. The Disk 1 /dev/sda contains the sda1 partition having Linux boot pieces of information. The later sda2 partition contains the LVM information for root and swap. Disks 1 and 2 are the disk that currently does not have any partitions, hence the output shows only disk information.

Selecting The Disk For Partitioning

In this case, we are going to select Disk 2 to create a partition. Run the given command in the terminal to select the disk. For the system, the disk is named /dev/sdb.

# fdisk /dev/sdb

Selecting The Disk

The output shows that the disk is selected and waiting for a command. It also shows that currently, the disk does not have any partition table as there are no partitions. It also shows that any changes made to the disk partition will stay in memory till you write/save them.

Creating A Disk Partition

Create A Disk Partition

To create a new partition type in n in the command line. The output asks us to select the partition type. In this example, we are going to create a primary portion for /dev/sdb. In this example, we are going to select the default partition type primary, as it can be used to boot multiple operating systems. While the extended partition is not bootable like the primary.

Creating A Primary partition

Enter p to select the partition type as primary, next select the partition number as 1 or you can leave it blank, and the system will name it accordingly, after that, there is the First Sector which means the starting track of the partition you can select any range from 2048-41943039, we are selecting the default value 2048 by leaving the input blank. At last enter the Last Sector which means the endpoint of partition memory allocation of the disk. You can select any numbers as per the disk size. Enter that size in the given format +size(K, M, G). For example, if you want to size the partition for 15 Gb then the input command will be +15G. Enter the command and press enter. This will create partition 1 having a size of 15GB.

Save The Changes To Partition Table

In order to write the changes to disk enter the command w and press Enter. We can see that the partition table is altered and ioctl control device is called to re-read the partition table and sync it to the existing disk.

Saving Changes to Partition Table

Conclusion

Type in the fdisk -l command again to see the updated partition table. The output will show that there is a new partition for /dev/sdb disk. The newly created partition is named /dev/sdb1. 

Checking the new partition


Buy A Dedicated Root Linux Server @ $ 79 Only

Open chat
WhatsApp Support
Hello,
How can i help you today?