How to create a new primary partition on a blank disk in linux?

To create a new primary partition on a blank disk in Linux, you can use the fdisk or parted command-line tools. Here, I will provide instructions for using both tools.

Using fdisk tool:

1. Open a terminal of the system which you want to create a new primary partition.

2. Identify the disk you want to create the primary partition on. You can use the lsblk or fdisk -l command to list available disks and their partitions. Let’s assume the disk you want to use is /dev/sdX, where X is the letter assigned to your disk (e.g., /dev/sda, /dev/sdb, etc.).

From the below output of lsblk command, you can see that the sda disk is new and not assigned to any mount points.

To confirm further if the `sda` disk is allocated to any other filesystems, use below command.

fdisk -l

From the above figure, you can see that the sda disk is not partioned and allocated to any other filesystems as highlighted in Red. And for sdb, there are two partition allocated.

3. Run fdisk on the chosen disk:

sudo fdisk /dev/sdX

Here, /dev/sda is the new 2Gb disk.

4. In the fdisk interactive menu, do the following:

a. Type n to create a new partition.

b. Choose the default option to create a primary partition by pressing Enter.

c. Choose the partition number (e.g., 1) and press Enter.

d. Specify the starting and ending sectors for the partition. If you want to use the entire disk for this partition, you can typically press Enter to accept the default values.

e. Type w to write the changes to the disk and exit fdisk.

Using parted tool:

1. Open a terminal.

2. Identify the disk you want to create the primary partition on, just as in the previous instructions (e.g., /dev/sdX).

3. Run parted on the chosen disk:

sudo parted /dev/sdX

4. In the `parted` interactive mode, follow these steps:

a. Type mklabel gpt to create a GPT partition table (if the disk doesn’t already have one).

b. Type mkpart primary ext4 to create a new primary partition with the “ext4” file system. You can change “ext4” to your desired file system type.

c. Specify the start and end points for the partition. To use the entire disk, you can simply type 0% for the start and 100% for the end.

d. Type quit to exit parted after creating the partition.

5. Format the newly created partition with your desired file system using the appropriate mkfs command.

For example, to format it as ext4:

sudo mkfs.ext4 /dev/sdX1

Here, /dev/sda1 as named from /dev/sda disk.

Now you’ve created and formatted a primary partition on the blank disk in Linux. You can mount it and use it as needed.

6. To verify the newly created partition called /dev/sda1, use the below command.

df -h

Note:

Be extremely cautious when working with disk partitions, especially on a blank disk, as you can potentially lose data if you make mistakes. Double-check the disk you are working with and make sure it’s the correct one.