Saturday, March 6, 2021
Home Pc and Mobiles How to Create, Resize and Delete Linux Partitions With Cfdisk

How to Create, Resize and Delete Linux Partitions With Cfdisk

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

On Fedora:

sudo dnf install cfdisk

On CentOS:

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 partition manager

Cfdisk also displays information associated with the storage device at the top of the screen. The following details are provided:

  1. Name of the disk
  2. Disk label
  3. Size in bytes and GB
  4. Number of sectors
  5. Identifier

If you have multiple storage devices on your system, you can specify which device you want to modify using the following syntax:

cfdisk [device]

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.

partition table

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.

create new partition cfdisk

To create a partition:

  1. Select the Free Space partition from the list
  2. Highlight the New option
  3. Tap Enter to confirm the action
  4. On a new unpartitioned disk, select Primary when prompted for the partition type
  5. 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).

partition size

Finally, select Write from the menu and hit Enter. Type in yes to confirm your choice.

Related: The Pros and Cons of Partitioning a Hard Drive

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.

change partition type

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.

writing data to table cfdisk

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.

delete old partitions

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.

resizing disk partitions cfdisk

Once again, you will have to Write the changes to the disk.

resizing partitions in linux

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.

Dual Boot vs Virtual Machine
Dual Boot vs. Virtual Machine: Which One Is Right for You?

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

Source link

Leave a Reply

Most Popular

Recent Comments

%d bloggers like this: