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.
[pastacode lang=”bash” manual=”%5Broot%40tecmint.com%20~%5D%23%20fdisk%20-l%0ADisk%20%2Fdev%2Fsda%3A%20637.8%20GB%2C%20637802643456%20bytes%0A255%20heads%2C%2063%20sectors%2Ftrack%2C%2077541%20cylinders%0AUnits%20%3D%20cylinders%20of%2016065%20*%20512%20%3D%208225280%20bytes%0ADevice%20Boot%20%20%20%20%20%20Start%20%20%20%20%20%20%20%20%20End%20%20%20%20%20%20Blocks%20%20%20Id%20%20System%0A%2Fdev%2Fsda1%20%20%20*%20%20%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%2013%20%20%20%20%20%20104391%20%20%2083%20%20Linux%0A%2Fdev%2Fsda2%20%20%20%20%20%20%20%20%20%20%20%20%20%2014%20%20%20%20%20%20%20%202624%20%20%20%2020972857%2B%20%2083%20%20Linux%0A%2Fdev%2Fsda3%20%20%20%20%20%20%20%20%20%20%20%202625%20%20%20%20%20%20%20%204582%20%20%20%2015727635%20%20%2083%20%20Linux%0A%2Fdev%2Fsda4%20%20%20%20%20%20%20%20%20%20%20%204583%20%20%20%20%20%20%2077541%20%20%20586043167%2B%20%20%205%20%20Extended%0A%2Fdev%2Fsda5%20%20%20%20%20%20%20%20%20%20%20%204583%20%20%20%20%20%20%20%205887%20%20%20%2010482381%20%20%2083%20%20Linux%0A%2Fdev%2Fsda6%20%20%20%20%20%20%20%20%20%20%20%205888%20%20%20%20%20%20%20%207192%20%20%20%2010482381%20%20%2083%20%20Linux%0A%2Fdev%2Fsda7%20%20%20%20%20%20%20%20%20%20%20%207193%20%20%20%20%20%20%20%207845%20%20%20%20%205245191%20%20%2083%20%20Linux%0A%2Fdev%2Fsda8%20%20%20%20%20%20%20%20%20%20%20%207846%20%20%20%20%20%20%20%208367%20%20%20%20%204192933%2B%20%2082%20%20Linux%20swap%20%2F%20Solaris%0A%2Fdev%2Fsda9%20%20%20%20%20%20%20%20%20%20%20%208368%20%20%20%20%20%20%2077541%20%20%20555640123%2B%20%208e%20%20Linux%20LVM%0A” message=”Linux Code” highlight=”” provider=”manual”/]

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.
[pastacode lang=”bash” manual=”%5Broot%40tecmint.com%20~%5D%23%20fdisk%20-l%20%2Fdev%2Fsda%0ADisk%20%2Fdev%2Fsda%3A%20637.8%20GB%2C%20637802643456%20bytes%0A255%20heads%2C%2063%20sectors%2Ftrack%2C%2077541%20cylinders%0AUnits%20%3D%20cylinders%20of%2016065%20*%20512%20%3D%208225280%20bytes%0ADevice%20Boot%20%20%20%20%20%20Start%20%20%20%20%20%20%20%20%20End%20%20%20%20%20%20Blocks%20%20%20Id%20%20System%0A%2Fdev%2Fsda1%20%20%20*%20%20%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%2013%20%20%20%20%20%20104391%20%20%2083%20%20Linux%0A%2Fdev%2Fsda2%20%20%20%20%20%20%20%20%20%20%20%20%20%2014%20%20%20%20%20%20%20%202624%20%20%20%2020972857%2B%20%2083%20%20Linux%0A%2Fdev%2Fsda3%20%20%20%20%20%20%20%20%20%20%20%202625%20%20%20%20%20%20%20%204582%20%20%20%2015727635%20%20%2083%20%20Linux%0A%2Fdev%2Fsda4%20%20%20%20%20%20%20%20%20%20%20%204583%20%20%20%20%20%20%2077541%20%20%20586043167%2B%20%20%205%20%20Extended%0A%2Fdev%2Fsda5%20%20%20%20%20%20%20%20%20%20%20%204583%20%20%20%20%20%20%20%205887%20%20%20%2010482381%20%20%2083%20%20Linux%0A%2Fdev%2Fsda6%20%20%20%20%20%20%20%20%20%20%20%205888%20%20%20%20%20%20%20%207192%20%20%20%2010482381%20%20%2083%20%20Linux%0A%2Fdev%2Fsda7%20%20%20%20%20%20%20%20%20%20%20%207193%20%20%20%20%20%20%20%207845%20%20%20%20%205245191%20%20%2083%20%20Linux%0A%2Fdev%2Fsda8%20%20%20%20%20%20%20%20%20%20%20%207846%20%20%20%20%20%20%20%208367%20%20%20%20%204192933%2B%20%2082%20%20Linux%20swap%20%2F%20Solaris%0A%2Fdev%2Fsda9%20%20%20%20%20%20%20%20%20%20%20%208368%20%20%20%20%20%20%2077541%20%20%20555640123%2B%20%208e%20%20Linux%20LVM%0A” message=”Linux Code” highlight=”” provider=”manual”/]

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.
[pastacode lang=”bash” manual=”%5Broot%40tecmint%20~%5D%23%20fdisk%20%2Fdev%2Fsda” message=”Linux Code” highlight=”” provider=”manual”/]
  • 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.
[pastacode lang=”bash” manual=”Command%20(m%20for%20help)%3A%20p%0ADisk%20%2Fdev%2Fsda%3A%20637.8%20GB%2C%20637802643456%20bytes%0A255%20heads%2C%2063%20sectors%2Ftrack%2C%2077541%20cylinders%0AUnits%20%3D%20cylinders%20of%2016065%20*%20512%20%3D%208225280%20bytes%0ADevice%20Boot%20%20%20%20%20%20Start%20%20%20%20%20%20%20%20%20End%20%20%20%20%20%20Blocks%20%20%20Id%20%20System%0A%2Fdev%2Fsda1%20%20%20*%20%20%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%20%2013%20%20%20%20%20%20104391%20%20%2083%20%20Linux%0A%2Fdev%2Fsda2%20%20%20%20%20%20%20%20%20%20%20%20%20%2014%20%20%20%20%20%20%20%202624%20%20%20%2020972857%2B%20%2083%20%20Linux%0A%2Fdev%2Fsda3%20%20%20%20%20%20%20%20%20%20%20%202625%20%20%20%20%20%20%20%204582%20%20%20%2015727635%20%20%2083%20%20Linux%0A%2Fdev%2Fsda4%20%20%20%20%20%20%20%20%20%20%20%204583%20%20%20%20%20%20%2077541%20%20%20586043167%2B%20%20%205%20%20Extended%0A%2Fdev%2Fsda5%20%20%20%20%20%20%20%20%20%20%20%204583%20%20%20%20%20%20%20%205887%20%20%20%2010482381%20%20%2083%20%20Linux%0A%2Fdev%2Fsda6%20%20%20%20%20%20%20%20%20%20%20%205888%20%20%20%20%20%20%20%207192%20%20%20%2010482381%20%20%2083%20%20Linux%0A%2Fdev%2Fsda7%20%20%20%20%20%20%20%20%20%20%20%207193%20%20%20%20%20%20%20%207845%20%20%20%20%205245191%20%20%2083%20%20Linux%0A%2Fdev%2Fsda8%20%20%20%20%20%20%20%20%20%20%20%207846%20%20%20%20%20%20%20%208367%20%20%20%20%204192933%2B%20%2082%20%20Linux%20swap%20%2F%20Solaris%0A%2Fdev%2Fsda9%20%20%20%20%20%20%20%20%20%20%20%208368%20%20%20%20%20%20%2077541%20%20%20555640123%2B%20%208e%20%20Linux%20LVM%0ACommand%20(m%20for%20help)%3A%0A” message=”Linux Code” highlight=”” provider=”manual”/]

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.
[pastacode lang=”bash” manual=”%5Broot%40tecmint%20~%5D%23%20mkfs.ext4%20%2Fdev%2Fsda4″ message=”Linux Code” highlight=”” provider=”manual”/]

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.
[pastacode lang=”bash” manual=”%5Broot%40tecmint%20~%5D%23%20fdisk%20-s%20%2Fdev%2Fsda2%0A5194304%0A” message=”Linux Code” highlight=”” provider=”manual”/]

 

Categorized in: