fdisk command in Linux with options

Hi Friends! today we will learn about fdisk command in Linux with options, it is mainly used for the creation and manipulation of the Partitions.

This fdisk command understands the partition tables like GPT, MBR, Sun, SGI, and BSD.

So, we can manage our disk partitions like create, update and delete. The block Devices can be divided into one or more logical disks known as Partitions.

Q. How we can list the partition in the disk using fdisk.

Command:
# fdisk -l

So, the “fdisk -l” command will list the partition tables, but from where did this command get the data?

The file is /proc/partitions which contains the data of all the partition tables with there blocks

Q. How we can list the partition of a particular Disk.

Command:
# fdisk -l /dev/sdb

So, we have used the argument “/dev/sdb” and we will get only the partition table of the device /dev/sdb. Also, there is only one partition “/dev/sdb1” in /dev/sdb.

Q. How we can see a Colourful output.

So, if we have to see the colored output of fdisk command, then we have to use -L option or we can use –color option.

There are three options auto, never and always. The main part is that it is by default set to auto.

Command:
# fdisk -l -L=never

While using the -L=never this will disable the colors and show us the output in black and white.

Command:
# fdisk -l --color=always

When we will use –color=always it will set some colour, in my case, it shows a yellow colour, this colour depends on the terminal you are using.

Q. How to get the output of a specific column using fdisk command in Linux.

So, we will look into the available outputs that we have for the fdisk command.

GPT Partitions: the available output columns are Device, Start, End, Sectors, Size, Type, Type-UUID, Attrs, Name, and UUID.

DOS Partitions: the available output columns are Device, Start, End, Sectors, Cylinders, Size, Type, Id, Attrs, Boot, End-C/H/S, and Start-C/H/S.

BSD Partitions: the available output columns are Slice, Start, End, Sectors, Cylinders, Size, Type, Bsize, Cpg, and Size.

sgi Partitions: the available output columns are Device, Start, End, Sectors, Cylinders, Size, Type, Id, and Attrs.

sun Partitions: the available output columns are Device, Start, End, Sectors, Cylinders, Size, Type, Id, Flags.

So, now we will see this with the GPT partition and will take some specific options.

So, from the above output, we just want to see Device, UUID, Size and the type.

Q. How to get the size of disk and from its partitions.

Just keep note that we will get the size in bytes.

# fdisk -s /dev/sda
Output:
976762584

Command fdisk -s /dev/sda will get the size of the whole disk, but friends how to get the size of partitions?

# fdisk -s /dev/sda1 
Output:
341996544

Q. How to get the disk details by its disk label type.

So, we have used -t option with the argument as gpt.

Q. How to get the output by it’s units with fdisk command.

So, by default the output we can see while using fdisk command in Linux, it has the unit as sectors.

Command:
# fdisk -l -u=sectors

But if we want to see the output in cylinders then we will use the following command

Command:
# fdisk -l -u=cylinders

Q. How to Create a new Partition in Linux using fdisk command.

A cheat sheet of fdisk command in Linux.
Q. How we can list the partition in the disk using fdisk.

Syntax:
#fdisk -[option]

Command:
#fdisk -l
Q. How we can list the partition of a particular Disk.

Syntax:
#fdisk -[option] [disk_partion]

Command:
#fdisk -l  /dev/sdb
Q. How we can see a Colourful output.

Syntax:
#fdisk -[option]=[never/always/auto]

Command:
# fdisk -l -L=never
# fdisk -l --color=always
Q. How to get the output of a specific column using fdisk command in Linux.

Syntax:
#fdisk -[option] -o [cloumn_name]

Command:
# fdisk -l -o Device,UUID,Size,type
Q. How to get the size of disk and from its partitions.

Syntax:
#fdisk -[option] [disk/disk_partition]

Command:
# fdisk -s /dev/sda
# fdisk -s /dev/sda1
Q. How to get the disk details by its disk label type.

Syntax:
#fdisk -[option] [disk_label]

Command:
# fdisk -l -t gpt
Q. How to get the output by it's units with fdisk command.

Syntax:
#fdisk -[option]=[units]

Command:
# fdisk -l -u=sectors
# fdisk -l -u=cylinders

[wp_quiz id=”1963″]

Give your valuable time