Using fdisk to manage Partitions

Introduction

One of the most time-consuming tasks while using Linux is managing partitions. If you are unfamiliar with the operating System, you could initially find the procedure complicated.

But it’s crucial to understand how to handle partitions on your computer since disk partitioning is necessary for many processes, including installing an operating system and file organization.

Here is a tutorial on creating, resizing, and removing partitions on Linux using the Fdisk program.

What is fdisk?

Fdisk is a text-based command-line tool for Linux that allows you to inspect and manage hard disk partitions. You can use the disk space to install operating systems, back up your data, and manage your files by using it to support a variety of partition tables and create, delete, and alter disk partitions.

How to Install fdisk on Linux?

Since Fdisk is a common partitioning tool, it comes pre-installed on the majority of Linux distributions out there. Open the terminal and type the following command to see if your System has fdisk:

which fdisk

If it provides a path, fdisk is installed on your System. If it doesn’t, you’ll have to install it manually.

On systems based on Debian:

sudo apt install fdisk

On CentOS:

sudo yum install fdisk

How to Use fdisk on Linux

After installing fdisk, refer to the sections below to learn how to use it to carry out various disk management tasks on your computer.

Listing All Disk Partitions

Let’s start by listing all of the partitions on your System. Using the -l parameter with the command, we may accomplish this.

Type the following command into the terminal window, then hit Enter:

sudo fdisk -l

Entering and Using Command Mode

It would help if you now switched into command mode to do any disk operations after listing the available partitions on your System.
Choose the device on which you wish to perform the necessary operations, then type the following command:

sudo fdisk /dev/sda

Ensure that the device name of your choosing is substituted for /dev/sda in the command above.
Once in command mode, you can do various actions using letters. If this is your first time using fdisk, type M to receive a list of all the supported commands.

Viewing the Partition Table

Before adding, formatting, or removing partitions on your drive, one of the fundamental partition management procedures you should carry out is viewing the partition table.

You may then choose how you want to manage the partitions on your disk using the information you receive about the logical disks or partitions on your hard drive.

Linux users should type p in command mode and press Enter to examine the partition table. Remember that this command can determine the current state of the partition table even after deleting, creating, or formatting a partition.

Deleting a Partition in fdisk

You can use the D command in the command mode to remove a partition after examining the partition table to make room for it or to prepare your disk to expand another partition.

Enter D and press Enter in the terminal to complete this. Fdisk will now prompt you to select the partition you wish to erase. Locate the number next to the partition you want to erase by scrolling up to the P command output.

Creating a Partition

Follow the instructions below to create a new partition once you’ve made some space on your drive.

Let us begin by starting the process of creating a partition. In order to do this, enter N. Following that, fdisk will prompt you to choose the type of partition you want to create. Choices for include:

p: primary (1-4)
l: logical (5 or over)

Enter the proper letter corresponding to the partition type above according to your needs, then press Enter.

The sector where you wish the partition to begin must then be specified. Press Enter to stick with the default setting.

Similarly, it would help if you also defined the disk’s final sector. Press Enter to let the partition operate using the disk space that is still available, which is the default setting. Alternatively, you can add a (+) symbol before the number and hit Enter to utilize a specific value.

Writing Partition Changes to the System using Fdisk

Until now, none of the partition management tasks we’ve completed have been applied to or saved on the file system; instead, fdisk has only carried them out.

Following this, you have two choices. You have two options: exit fdisk without storing the modifications or write your changes to the disk to apply them. If you accidentally make a mistake with a partitioning operation in fdisk, the latter option may be useful.

Enter W and press Enter to save your modifications to the disk. Alternately, enter Q to leave fdisk and reverse your changes.

Conclusion

With the aid of this manual, you ought to be able to manage disk partitions in Linux easily and afterward make better use of the storage, whether it’s for setting up a new operating system, dual-booting with another operating system, or enhancing file management.

However, cfdisk is a simpler option to fdisk that you should look at if you’re just starting with Linux. It is simply a graphical program that simplifies Linux partition management through an intuitive user interface.

Leave a Reply

Your email address will not be published.