4

How does one interpret fdisk -l output. I've included a sample output based on an image with my "best guesses", and then show the output based on the device which was used to create the image. Anything you can do to explain how these three different "views" of the same thing relate would be appreciated.

[michael@devserver ~]$ sudo fdisk -l backup.img

Disk backup.img: 31.9 GB, 31914983424 bytes, 62333952 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00009590

              Device Boot      Start         End      Blocks   Id  System
backup.img1            8192     2496093     1243951    e  W95 FAT16 (LBA)
backup.img2         2496094    62333951    29918929    5  Extended
backup.img5         2498560     2564093       32767   83  Linux
backup.img6         2564096     2699263       67584    c  W95 FAT32 (LBA)
backup.img7         2703360    62333951    29815296   83  Linux
[michael@devserver ~]$
  • Line 1 displays bytes, GB (bytes/2^30) and sectors (bytes/512 where 512 is addressed on the next bullet).
  • Lines 2, 3, and 4 all appear to imply the same thing that there are 512 bytes per sector for this disk (???)
  • Line 5 displays the disk label type of the Master Boot Record (???). Why "dos" as I thought this was a Microsoft thing?
  • Line 6 displays the disk identifier which is a randomly generated hexadecimal number stuck onto the MBR, and is likely used by the operating system.

The following relates to each column of the table:

  • Device is each partition, and displays partitions 1, 2, 5, 6, and 7. Not sure why the above output and the next two display different names and how they all relate.
  • Boot is if it is bootable?
  • Start is the number of bytes from the very begging of the disk where the partition starts, and similar for end. I've recently read that to mount the partition, I would take 512 x start as the offset, and then for example can mount the second partition using mount -o loop,offset=1278000128 backup.img /mnt/tmp (untested).
  • From inspection, I found that blocks can be calculated as (end-start+1)/2. Maybe it is divided by 2 because blocks are sometimes defined as 1K, but I have 512 bytes?
  • Not really sure about the ID.
  • System is the operating system of the partition.

The above image file was created using sudo dd bs=4M if=/dev/sda of= backup.img where /dev/sda is a SD card inserted in a USB card reader. I've also included the fdisk output of this SD.

michael@rpi1:~ $ sudo fdisk -l

....

Disk /dev/sda: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00009590

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1          8192  2496093  2487902  1.2G  e W95 FAT16 (LBA)
/dev/sda2       2496094 62333951 59837858 28.5G  5 Extended
/dev/sda5       2498560  2564093    65534   32M 83 Linux
/dev/sda6       2564096  2699263   135168   66M  c W95 FAT32 (LBA)
/dev/sda7       2703360 62333951 59630592 28.4G 83 Linux

michael@rpi1:~ $

If the SD card is actually used in a Raspberry Pi,I get the following output:

michael@rpi2:~ $ sudo fdisk -l

...

Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00009590

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1         8192  2496093  2487902  1.2G  e W95 FAT16 (LBA)
/dev/mmcblk0p2      2496094 62333951 59837858 28.5G  5 Extended
/dev/mmcblk0p5      2498560  2564093    65534   32M 83 Linux
/dev/mmcblk0p6      2564096  2699263   135168   66M  c W95 FAT32 (LBA)
/dev/mmcblk0p7      2703360 62333951 59630592 28.4G 83 Linux

michael@rpi2:~ $
  • mostly right. Bootable shows whether it is flagged as bootable or not (no check is done to find out if it actually IS bootable). And Start & End for partitions are listed in sectors, not bytes....so 8192*512 means that first partition starts 4MB into the disk. – cas Dec 27 '17 at 14:15
  • And the Id you weren't sure about is just a hex code for the filesystem type. – bu5hman Dec 27 '17 at 14:45
  • @cas Good point about units of sectors and not bytes. I see these starts and ends and all but the first set appears to overlap. I also haven't grasped the pattern. For instance, p2 starts 1 after p1 ends, p6 starts 2^16 after p5 starts, p2 and p7 have the same ending, etc. – user1032531 Dec 27 '17 at 14:51
  • 1) Disk label: DOS is also known as MBR; comes from the old days, when this partition type was created. Other types are GPT (the current version), SGI and Sun where the latterare seldom used with Linux. 2) Partitions 1 and 2 are primary partitions, of which a DOS partition type only may have 4. Thus partition 2 is used as an "extended partition", which does not hold any filesystem, but "logical partition table". Therefore the "logical partitions" count from 5 and start near the start of P2 and end at the end of P2 (P2 is just sort of container for P5...P7). – ridgy Dec 27 '17 at 16:25
  • 3) The name of the device nodes (backup.img1, /dev/sdax, /dev/mmvblk0px) depends on the device and driver used. Formerly, /dev/hdxywas used for ata drives; /dev/sdxy is used for (pseudo) scsi drives, and /dev/mmcblkxy is used with highspeed MMC/SD cards (see tldp.org/HOWTO/Partition-Mass-Storage-Definitions-Naming-HOWTO/…). – ridgy Dec 27 '17 at 16:32

Your Answer

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

Browse other questions tagged or ask your own question.