Skip to main content

How to know if /dev/hda2 is Primary partition or Extended partition [Resolved]

If all four primary partitions exist on an IDE drive, they are numbered as follows:

  • /dev/hda1
  • /dev/hda2
  • /dev/hda3
  • /dev/hda4

We have also the partitions on a disk with one primary partition and the sole extended partition might be numbered as follows:

  • /dev/hda1 (primary)
  • /dev/hda2 (extended)

This naming strategy leads to confusion :
How it is named : /dev/hda2 in both of cases :

  • Primary partition
  • Extended Partition

Another way to express the issue : How to distinct if it is primary or extended partition

Question Credit: Abdennour TOUMI
Question Reference
Asked April 5, 2019
Posted Under: Unix Linux
4 Answers

From terminal, you type parted /dev/hda then type print as result:

Number  Start   End    Size   Type     File system  Flags     
 1      32.3kB  107MB  107MB  primary  ext3         boot, raid
 2      107MB   250GB  250GB  primary               raid 

credit: i2day
Answered April 5, 2019

Check the output of fdisk -l /dev/hda or a similar tool (sfdisk -l /dev/hda, parted -l, …).

You can't tell whether a partition is primary or extended from its number. In the classic PC partition scheme, each partition numbered 1, 2, 3 or 4 can be either primary or extended. (It's possible but not recommended to have multiple extended partitions; Linux itself doesn't mind but some management tools do.)

There's an almost-guaranteed way to check without root access: you can look up the size of each partition in /proc/partitions. The size of extended partitions is always reported as a single block. For instance, in the example below, sda4 is an extended partition.

major minor  #blocks  name
   8        1     489951 sda1
   8        4          1 sda4

credit: Gilles
Answered April 5, 2019

You can always try sudo cfdisk /dev/hda to display a table with all partitions. It also shows whether it is a primary or extended partition.

credit: makos
Answered April 5, 2019

I wanted only the path of the primary partition, and came up with this.

sudo fdisk -l 2> /dev/null | awk '$2 ~ /\*/ {print $1}'
  • fdisk -l lists out the partitions,
  • 2> /dev/null redirects error messages so that they don't print; I kept getting a message about a partition not being on the physical disk,
  • Pipe to awk to process the output:
    • $2 refers to the second word (the value of the Boot column),
    • $2 ~ /^\*$/ refers to matching only lines where the second word is an asterisk only,
    • {print $1} prints the first word in the line matching the preceding expression, which is the Device column.

credit: Rui F Ribeiro
Answered April 5, 2019
Your Answer