Command Linux

How to Use fdisk Command to Create Partition in Linux

The fdisk command utility is useful for viewing and editing hard disk or SSD partitions on Linux and its distributions, such as Ubuntu. It is one of the most powerful tools to manage disk partitions on Linux. Other tools are also available to perform disk partition on Linux, but fdisk is one of the most commonly used ones.

fdisk is a menu-driven command-line utility, and hence new users find this tool confusing and difficult to use. fdisk is not an easy tool to use and should be used with caution. You need to have root access or sudo privileges to make changes to storage partitions.

So, today in this article, I will give you a tutorial on how to create a partition in Linux using the fdisk command.

You can carry out the following operations using the fdisk command.

  • Create New Partition
  • Manage Space
  • Reorganize space on old drives.
  • Move data to a new disk

How to list partitions?

Before making any changes to the drive, you first look at the basic structure of the drive and its partitions. To view all the partitions on the drive, run the following command in the Linux terminal.

$ sudo fdisk -l

Partitions are displayed by their device name, such as dev/sda, dev/sdc, etc., as you can see in the above screenshot.

If you wish to view partition on the specific disk, you have to use ‘-l’ followed by the device name as shown in the command below.

$ sudo fdisk -l /dev/sda3

This command will show the output as shown in the screenshot below.

Creating Partition:

To create a partition on a specific drive, you have to run the fdisk command with the device name, as shown in the command below.

$ sudo fdisk /dev/loop1

Once you’re on the device where you want to create a partition, type M and press enter.

You will see the list as shown below screenshot. This is the list of single-letter commands you can use to take specific action using fdisk.

To create a partition, you have to use the N command. Both logical and primary partitions can be created where I denote logical partition and P denotes primary partition.

By default, the first free sector on the disk is chosen to create a new partition. Just like that, you also have to specify the last sector of the partition. You can also specify the size of the partition according to your requirement.

Deleting Partition:

To delete the specific partition, you have to use the D command. Use the P command to make sure which partition you want to delete.

When you fire the D command, it will ask for the partition number you want to delete. Just type that partition number and hit the enter button. This will delete the selected partition.

So, this is how you can use the fdisk command to create and delete the partition on Linux. fdisk is a very useful command-line tool when used efficiently and correctly. Make sure you have the back of the partitions where you are going to use the fdisk command. Good day!

Related Articles

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Back to top button