Partitioning your disks is one of the most frustrating tasks that you will come across while installing Linux. Sophisticated command line tools make it tricky for beginners to get started with partition management.
What you need is a partitioning management tool specially developed for beginners. Here’s when Cfdisk comes to the rescue. For those who want to manage partitions on their computer in a better way, Cfdisk is the best choice.
Here’s how to create new partitions in Linux with Cfdisk, along with resizing, changing, and deleting partitions.
What Is Cfdisk
Cfdisk is a command line, text-based graphical tool that allows you to create, delete, and modify disk partitions on your system. Unlike other command line tools, Cfdisk provides an interactive way of managing partitions for beginners.
The Cfdisk package comes preinstalled on most of the well known Linux distributions. You can install Cfdisk manually if you do not find it on your system by default.
To install the package on Debian-based systems:
sudo apt-get install cfdisk
sudo dnf install cfdisk
sudo yum install cfdisk
On Arch-based distributions:
sudo pacman -S cfdisk
To launch Cfdisk in your terminal, type sudo cfdisk, and press Enter. The default user interface of the utility looks something like this.
Cfdisk also displays information associated with the storage device at the top of the screen. The following details are provided:
- Name of the disk
- Disk label
- Size in bytes and GB
- Number of sectors
If you have multiple storage devices on your system, you can specify which device you want to modify using the following syntax:
If /dev/sda is your system’s hard disk drive (HDD), then typing in cfdisk /dev/sda will allow you to manage partitions on your HDD only. Similarly, you can type in cfdisk /dev/sdb to partition external storage devices connected to your system.
Creating Linux Partitions With Cfdisk
To create new disk partitions with Cfdisk, you need to have free space on your storage. In the image below, note that we have 3GB of free space available to use.
For the demonstration, we will create a new partition by using the New option from the menu. You can traverse through the menus using the Right and Left arrow keys. To choose a partition from the table, use the Up and Down cursor keys.
To create a partition:
- Select the Free Space partition from the list
- Highlight the New option
- Tap Enter to confirm the action
- On a new unpartitioned disk, select Primary when prompted for the partition type
- Tap Enter to confirm
Now you will have to specify the size of the new partition. Since we have 3GB of space left in the storage, we will create a partition that’s 3GB in size. You can enter any number you want (1GB, 2GB, etc).
Finally, select Write from the menu and hit Enter. Type in yes to confirm your choice.
Changing the Linux Filesystem Type
When you create a new partition on your storage, the default partition type would be set to Linux Filesystem. However, if you are going to use the partition for something else, such as Linux swap or EFI, you can change the type with Cfdisk easily.
To change the filesystem type, select the newly created partition from the table. Choose the Type option from the menu and press Enter.
Cfdisk provides you with 108 different partition types to choose from. You can choose the filesystem type that suits your needs.
Again, after changing the partition type, you need to write the changes to the disk. Select Write from the menu and press Enter. Type yes to finalize the process.
Deleting Linux Partitions
Deleting partitions is the easiest job that you can do with Cfdisk. Simply choose the partition from the table, select Delete from the menu, and hit Enter.
Now you need to write the changes to the disk by selecting Write from the menu.
Resizing Old Partitions on Linux
Cfdisk allows you to change the size of your partitions within seconds.
First, select the partition that you want to resize and choose the Resize option from the menu. Next, specify the new size that you want to allocate to the partition. For this demonstration, we will resize the newly created partition to 2GB.
Once again, you will have to Write the changes to the disk.
Additional Cfdisk Commands
Although Cfdisk is the perfect choice for beginners who do not want to play around with text commands, you can still manage your partitions using the command line with Cfdisk.
For those who have decent experience working with other terminal-based partition management tools like Fdisk, here are some additional commands that you can use with Cfdisk.
- -h, –help: Display help related to Cfdisk usage.
- -L, –color: Colorize the output displayed on the screen.
- -V, –version: Display version details about Cfdisk.
- -z, –zero: This allows you to create a new partition table from scratch. The previous partition table is not read by the application.
- b: Toggle the bootable flag on or off for the selected partition.
- d: Delete the highlighted partition.
- h: Display the help screen while using Cfdisk.
- n: Create a new partition from the selected free space.
- q: Quit the program without writing data to the table.
- s: Fix the partition order.
- t: Change the type of the selected partition.
- u: Dump the disk layout to an output file.
- W: Write the data to the table.
- x: Toggle the display of additional information related to the selected partition.
Partition Management With Cfdisk
Knowing how to create and manage your disk partitions is important if you are running Linux on your computer. Even during Linux installation, users have to partition their storage in order to allocate memory to the system. Dual-booting a Linux distribution with no knowledge of drive partitioning comes with a huge risk factor.
Although many Linux distributions allow you to partition your hard drive graphically, some of them don’t. To easily counter such situations, getting comfortable with at least one command line partition management tool is a must for anyone.
Want to run multiple OSes on one machine? Here’s how to decide if a virtual machine or dual-booting is right for you.
About The Author