6

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

3

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 
2

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
0

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.

  • cfdisk Does not existed on red-hat . There is sfdisk – Abdennour TOUMI Jun 9 '14 at 11:00
  • Can't you download it from repositories? – makos Jun 9 '14 at 11:04
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.