How to Create Partitions in Ubuntu Linux using fdisk

How to Create Partitions in Ubuntu Linux using fdisk. In this post, we will introduce FDISK, its advantages then show you how to create partitions in Ubuntu.

Disk partitioning is the process of dividing a hard drive into multiple sections called partitions. These sections are called primary partitions and they are formatted with a file system before they can be used to store data. With FDISK, a front end utility, you configure the computers’ fixed disk drives.

So, shall we start with How to Create Partitions in Ubuntu Linux using fdisk.

What is FDISK?

First of all, FDISK is a disk partitioning utility for DOS, Microsoft Windows, and Linux. Hence, FDISK creates up to four primary partitions on a storage volume. It is a command line utility used in PCs for the creation of extended partitions, logical drives, and logical partitions.

Most modern personal computers come with the disc already partitioned and loaded with the operating system and sometimes other applications. Truly speaking, FDISK is basically used to prepare and partition a fresh hard drive.

Originally, FDISK was designed to be used on floppy disks. However, with the introduction of hard drives and other storage devices, the FDISK limitation are no longer considered to be a reliable measure for disk space.

Subsequently, FDISK utility is very useful for system administrators to manage and view disk partitions on a Linux system. Be aware that FDISK is a dangerous tool and should be used with extreme caution. Only root or users with sudo privileges can manipulate the partition tables.

Advantages of FDISK

Surely, FDISK utility allows partitions to be created and managed on the hard disk drive. Also, it works on other devices, like compact flash memory cards and USB flash drives, as long as those other devices support PC style master boot records (MBRs) and partitions. Commands of FDISK allow up to four new primary partitions, and a number of logical (extended) partitions, depending on the size of the hard disk in your system.

Use the FDISK commands to display, resize, delete, copy, modify, scale, or move partitions, all using a text based interface. FDISK is the most widely used command for checking the partitions on a disk, but will not report Linux partition sizes. Well, it is a simple command line utility that offers the ability to partition the drive in Windows.

In like manner, FDISK helps you to partition the drive, in order to separately install the operating system onto a single disk, while the rest of the required things are placed onto other drives. The DiskPart tool is a great successor that takes over from FDISK for serving Windows users in the area of disk partitioning and creating utilization of the drive space on Windows 10 and also on the latest version of Windows 11.

The FDISK commands are quite helpful when it comes to creating space for new partitions, organizing the space for new drives, reorganizing the old disk, and copying or moving data over new drives.

Though, FDISK utility is a valuable tool to recognize partitions, create new partitions, and configure a drive as desired. But it has certain limitations like applications cannot be moved between partitions without first being uninstalled and then reinstalled.

We have come to the main part of this article How to Create Partitions in Ubuntu Linux using fdisk.

How to Create Partitions in Ubuntu Linux using FDISK

In this section, we will show you how to create partitions in Ubuntu Linux using the FDISK utility.

Step 1 - List Partitions

Before creating partitions on a hard disk, it is a good idea to list available space and partitions on the hard disk. So you can easily identify the storage device and create a partition on it.

You can use the fdisk command with l option to list all available partitions on the disk.

				
					fdisk -l
				
			

You should see a number of partitions, type of the partitions, partition size, and a few more information on the following screen:

If you want to see partitions of a specific disk then run the following command:

				
					fdisk -l /dev/sdc
				
			

Step 2 - Select a Storage Disk

Next, you will need to select the storage disk on which you want to create partitions. In this case, we will use the /dev/sdb as a storage disk.

Run the following command to select a storage disk:

				
					fdisk /dev/sdb
				
			

You should see the following screen.

Step 3 - Define Partition Scheme

You will also need to choose which partition scheme you want to use on disk. By default, the FDISK command uses a DOS partition scheme for the new partition. You can also define the MBR and GPT partition scheme on the hard disk.

First, type m and press the Enter key to see all available commands and help information as shown below:

Type g and press the Enter key to create a GPT partition scheme. You should see the following screen:

Then, type w and press the Enter key to write the changes on the disk.

Step 4 - Create a New Partition

To create a new partition, follow the below steps:

  • Type n and press the Enter key to create a new partition.
  • Select the partition number.
  • Choose the first sector and last sector of the hard disk
  • Define the size of the partition. Define the size in KB, MB, GB, TB, and PB. Type +3GB to set the size of the partition to 3GB. Once the partition is created, you see the following screen.

Step 5 - Save Changes on Disk

Next, type p and press the Enter key to display the new partition table:

Then, type w and press the Enter key to write changes on the hard disk. You should see the following screen.

You can also type q and press the Enter key to exit from the fdisk menu. Next, you will need to verify whether the partition is created or not. You can verify it with the following command:

				
					lsblk -p /dev/sdb
				
			

You should see your newly created partition on the following screen:

Step 6 - Format the Partition

After creating a partition, you will need to format it before using it. You can format it with the following command:

				
					mkfs -t ext4 /dev/sdb1
				
			

Once the partition is formatted, you should see the following screen:

Step 7 - Mount the Partition

Next, you will need to create a mount point and mount your partition in order to use it. First, create a mount point directory with the following command:

				
					mkdir /data
				
			

Now, please mount the partition using the following command:

				
					mount /dev/sdb1 /data
				
			

You can now verify the mounted partition using the following command:

				
					df -h
				
			

See your mounted partition on the following screen:

Your partition will be unmounted automatically after the system reboot.

Step 8 - Mount the Partition Permanently

If you want to mount the partition automatically when your Linux system starts up. Then, you will need to define your partition in the /etc/fstab file.

Edit the /etc/fstab file using the following command:

				
					nano /etc/fstab
				
			

Add the following line:

				
					/dev/sdb1 /data ext4 defaults 0 0
				
			

Save and close the file then run the following command to apply the changes:

				
					mount -a
				
			

How to Remove Partitions in Ubuntu Linux using FDISK

Additionally, FDISK utility also allows you to remove an unwanted partition easily via the command line interface. First, select the hard disk using the following command:

				
					fdisk /dev/sdb
				
			

You should see the following output:

				
					Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
				
			

Type d and press the Enter key. You will be asked to give the partition number you want to delete. Then, type 1 and press the Enter key to delete the first partition.

				
					Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): w
				
			

Then, type w and press the Enter key to write the changes on the disk.

Thank you for reading How to Create Partitions in Ubuntu Linux using fdisk. We will conclude this article blog. 

How to Create Partitions in Ubuntu Linux using fdisk Conclusion

In this post, we explained about FDISK utility and show you how to create a partition using the FDISK tool. I hope you can now easily use this utility to create and manage partitions.

Finally, FDISK is a utility included with all versions of MS DOS, Windows, and Linux that helps format (prepare) a hard disk for data storage, and logically partition a disk by indicating and naming major parts of the disk for various uses.

Please take a look at more Ubuntu content by navigating to our blog over here. 

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

3.2 5 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x