Linux partition manager – fdisk command

 Linux partition manager (fdisk command) introduction

Linux has a very useful tool 'fdisk command'. It is a  Linux partition manager. With Linux fdisk command you will be able to create partitions, you will be able to know the partition, you will be able to delete a partition and many more tasks associated with Linux partition you will be able to perform.
In this article you will learn about how fdisk works as Linux partition manager.

Before I proceed further I want to warn you that please be cautious while using Linux fdisk command once you delete your partitions by mistake  you may also loose the data forever.

1. Fdisk partition display

To list disk in linux use the command "fdisk -l" It will display the disk partition. 
Note: The display may be different in some other flavours of Linux. It is also possible that you may have more than two partitions in your computer.

[root@techsakh ~]# fdisk -l

 

Linux partition manager
Linux partition manager

2. Fdisk partition display of specific disk

If you  have more than one disk in your computer. For example:  /dev/sda, /dev/sdb . In that case you would like to know the partition of the particular disk. Use the command  "fdisk -l  /dev/sda" or "fdisk -l  /dev/sdb" to see the list of disk in Linux.

[root@techsakh ~]# fdisk -l /dev/sda

 

Linux partition manager
Linux partition manager

3. Fdisk help

There are various commands that you can use  with fdisk for Linux partition management.  Use the command "fdisk /dev/sda" and type :"m" for help to display the list of commands. See the example below.  

[root@techsakh ~]# fdisk /dev/sda

 

Linux partition manager
Linux partition manager fdisk help option

 

4. Fdisk create partition

To create a new partition use the command "fdisk /dev/sda", then press "n" to display the options for creating a new partition.  

[root@techsakh ~]# fdisk /dev/sda
fdisk command for partition
Linux partition manager fdisk to create partition

 

You will have two options, you can either select primary partition or extended. You need to press p for primary partition and e for extended partition.  

5. fdisk primary vs extended linux partition

You can create upto four Primary partitions in your HDD. However you can create additional sub-partitions inside these Primary partitions and this is called Extended partitions. The Extended partition is also called Logical partition. One thing you must know that your OS must be kept only in Primary partition in Linux., because when your computer starts it looks into the Primary partition to load the OS into the memory.  

6 Write partition table

Write partition table by  choosing p for primary partition or e for extended partition. Now select the partition number, you can select the partition number you want.Now comes selecting Linux partition size . Give the size of the First sector and the Last sector according to the requirement. What ever the size you allot here will become the permanent size of your new partition. To make the changes permanently press "w". It will write the size on your HDD permanently. Be very careful while pressing w, any new changes will cause the loss of data from your computer, make sure you have taken backups of you important data.  

fdisk command for partition
fdisk command for partition

7. Fdisk remove partition in Linux

If you don't want any partition, you can simply remove it with the "d" command. Enter into the partition by "fdisk /dev/sda" command and delete the partition with "d". You can select the partition number you want to delete. Your changes will not be permanent until you press the "w" button.  

[root@techsakh ~]# fdisk /dev/sda

 

fdisk command for partition
fdisk command for partition

8. Fdisk partition type your Linux OS support.

There are many partition types that your Linux system support. You can list them with the help of fdisk option "l"  See the image below.  

fdisk command for partition
Linux partition manager

9. Fdisk set boot flag

The bootable flag tells the master boot record which partition to boot. You can set boot flag in Linux to only one partition. To change the boot flag to another partition  use fdisk /dev/sda  then press  "a". Select any partition number you want. The image below is given as an example.  

fdisk command for partition
Linux partition manager fdisk to set boot flag

 

10. Make partition table (GPT)

GPT stands for GUID Partition Table. It stores the partitioning information on the drive. MBR(Master Boot Record) also does the same thing i.e. stores the partitioning information. But MBR has many limitations, it supports upto four primary partitioning and it can't handle more than 2 TB of space. GPT is very robust and modern and it is replacing MBR. Press "g" after "fdisk /dev/sda" command to create GPT partition table.  

Linux partition manager
Linux partition manager fdisk command

11. Verify the partition table

 With "v" command you can verify the remaining and unallocated space of the partition table.  

Linux partition manager
Linux partition manager

12. Get into extra(Expert) functionality

Extra functionality is for experts only. So you should not use this until you know what you are doing. Inside fdisk /dev/sda press "x" for expert functionality, then "m" to see the list of expert functionality.

Linux partition manager
Linux partition manager

 

  • "f" option is for fixing partition order. If the partition is not arranged in order use "f" for arranging in order again.
  • "e" is for listing extended partition if present.
  • If you have made any changes by mistake then press "q" to exit without saving.
  • The option "c" for changing the number of cylinders and "s" for changing the number of sectors and tracks are rarely used. It is mostly used by researcher or in any tech laboratory. If you need  more details about it go to this link.

 

13.Best Recommended partition for your Linux System

The following are the best partition rule that you can apply while formatting you Linux OS.

 swap -----  At least 250 MB
/boot -----  2 times amount of RAM
/     -----  Minimum 5 GB for better performance
/home -----  More than 10 GB is good

This is it with the article Linux partition manager - fdisk command

Download Our Free eBook now

Linux and UNIX Shell scripting ebook

Be the first to comment

Leave a Reply

Your email address will not be published.


*


shares