fdisk

  • fdisk stands (for “fixed disk or format disk“) is an most commonly used command-line based disk manipulation utility for a Linux/Unix systems.
  • With the help of fdisk command you can view, create, resize, delete, change, copy and move partitions on a hard drive using its own user friendly text based menu driven interface.
  • This tool is very useful in terms of creating space for new partitions, organising space for new drives, re-organising an old drives and copying or moving data to new disks.
  • It allows you to create a maximum of four new primary partition and number of logical (extended) partitions, based on size of the hard disk you have in your system.

View all Disk Partitions in Linux:

  • The following basic command list all existing disk partition on your system.
  • The ‘-l‘ argument stand for (listing all partitions) is used with fdisk command to view all available partitions on Linux. The partitions are displayed by their device’s names.
  • For example: /dev/sda, /dev/sdb or /dev/sdc.
Linux Code
[[email protected] ~]# fdisk -l
Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 4582 15727635 83 Linux
/dev/sda4 4583 77541 586043167+ 5 Extended
/dev/sda5 4583 5887 10482381 83 Linux
/dev/sda6 5888 7192 10482381 83 Linux
/dev/sda7 7193 7845 5245191 83 Linux
/dev/sda8 7846 8367 4192933+ 82 Linux swap / Solaris
/dev/sda9 8368 77541 555640123+ 8e Linux LVM

View Specific Disk Partition in Linux:

  • To view all partitions of specific hard disk use the option ‘-l‘ with device name.
  • For example, the following command will display all disk partitions of device /dev/sda.
  • If you’ve different device names, simple write device name as /dev/sdb or /dev/sdc.
Linux Code
[[email protected] ~]# fdisk -l /dev/sda
Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 4582 15727635 83 Linux
/dev/sda4 4583 77541 586043167+ 5 Extended
/dev/sda5 4583 5887 10482381 83 Linux
/dev/sda6 5888 7192 10482381 83 Linux
/dev/sda7 7193 7845 5245191 83 Linux
/dev/sda8 7846 8367 4192933+ 82 Linux swap / Solaris
/dev/sda9 8368 77541 555640123+ 8e Linux LVM

Print all Partition Table in Linux

  • To print all partition table of hard disk, you must be on command mode of specific hard disk say /dev/sda.
Linux Code
[root@tecmint ~]# fdisk /dev/sda
  • From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As we enter ‘p‘, it will print the specific /dev/sda partition table.
Linux Code
Command (m for help): p
Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 4582 15727635 83 Linux
/dev/sda4 4583 77541 586043167+ 5 Extended
/dev/sda5 4583 5887 10482381 83 Linux
/dev/sda6 5888 7192 10482381 83 Linux
/dev/sda7 7193 7845 5245191 83 Linux
/dev/sda8 7846 8367 4192933+ 82 Linux swap / Solaris
/dev/sda9 8368 77541 555640123+ 8e Linux LVM
Command (m for help):

How to Format a Partition in Linux:

  • After the new partition is created, don’t skip to format the newly created partition using ‘mkfs‘ command.
  • Type the following command in the terminal to format a partition. Here /dev/sda4 is my newly created partition.
Linux Code
[root@tecmint ~]# mkfs.ext4 /dev/sda4

How to Check Size of a Partition in Linux:

  • After formatting new partition, check the size of that partition using flag ‘s‘ (displays size in blocks) with fdisk command. This way you can check size of any specific device.
Linux Code
[root@tecmint ~]# fdisk -s /dev/sda2
5194304

 

Categorized in: