Linux Commands

Linux cfdisk Command Examples

In Linux systems, the cfdisk is the curses-based command-line tool used to manage hard drive partitions including creating, deleting, and modifying. It provides an effective and user-friendly text-based graphical interface with basic partitioning functionalities. It displays all disks and partitions along with relevant information.

In this guide, I am going to cover cfdisk command and how to use it to create and delete partitions in Linux.

cfdisk Linux Command Examples
1. Resize the Partition
2. Change Partition Type
3. Create a New Partition
Conclusion

cfdisk Linux Command Examples

Run the cfdisk command with the /dev/sda as an argument in the terminal:

sudo cfdisk /dev/sda

You will receive the following output in the terminal:

In my Linux system, we have three partitions that can be edited.

Let’s perform some of the functions for better understanding.

1. Resize the Partition

Choose the disk; resize it by clicking on the Resize option using the arrow buttons and hit Enter button:

Allocate the size according to need or choice and press the Enter button to save it:

As you can see, the disk size has been updated and it also mentions the free space:

2. Change Partition Type

You can also change the partition type by selecting the Type and press Enter:

Once you select the Type option; this will display the partitions types list in front of you; choose any of them:

3. Create a New Partition

We have reduced the size of disk 3 in Step 1, and this creates free space in the system. Now, we can create a new partition as well max of size 3.5G.

Move to Free Space and click on the New option:

Set the size of the new disk and hit Enter:

The new partition of 3.0G is successfully created:

After the partition size allocation, you can set the type of created partition; let’s suppose I am assigning it Linux Swap type:

Move to the Write option to write the partition to make changes:

A prompt will appear to confirm if you’re sure to write the partition table, type yes and Press Enter button:

Now we have four disk partitions in the Linux system:

Conclusion

The cfdisk command is a text-based graphical interface used to handle disk partitions. With the help of this, you can create, edit, and delete any partition easily as it is a simple and effective tool. Throughout this guide, we have learned how we can manage disk partitions by resizing them and changing their type. We have also created a new disk; allocated a size and write it in a partition table.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.