Skip to contentSkip to conversation

lsblk vice fdisk, etc

DISCUSSION jb 2 participants 7 messages Aug 19, 2014 – Aug 25, 2014 Util-Linux package

lore
Share & tools
lore

jb

author
#0 lore raw

Hi,
I think there is a need to fix and reconcile lsblk with fdisk, cfdisk, etc, as demonstrated on example of usb flash drive, shown as /dev/sdb device.

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0 37.3G  0 disk 
├─sda1   8:1    0   20G  0 part 
├─sda2   8:2    0  1.5G  0 part [SWAP]
├─sda3   8:3    0 13.4G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0  2.4G  0 part 
sdb      8:16   1  7.3G  0 disk 
└─sdb1   8:17   1  683M  0 part 
sr0     11:0    1 1024M  0 rom  
$

Where does sr0's size of 1024M come from ?

$ lsblk -f
NAME   FSTYPE  LABEL             UUID                                 MOUNTPOINT
sda                                                                   
├─sda1 ext4                      38b23ec9-4947-46ae-a2b2-d48f4582af3f 
├─sda2 swap                      8074aa4f-489e-4adc-a356-ff09d633534f [SWAP]
├─sda3 ext4                      d067602d-f15d-49c0-abad-865adab2cc8f /
├─sda4                                                                
└─sda5 ext4                      4f168c8f-ac1d-4048-ac3f-254fa4392c60 
sdb    iso9660 Test
                                 2014-07-22-17-24-48-12               
└─sdb1 iso9660 Test
                                 2014-07-22-17-24-48-12               
sr0                                                                   
$

The line
sdb iso9660 Test
should be consistent with sda and show
sdb

The line
└─sdb1 iso9660 Test
should be reconciled with what fdisk, etc show.

# fdisk -l /dev/sdb
...
Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1  *        0 1398783 1398784  683M 17 Hidden HPFS/NTFS
# cfdisk /dev/sdb
...
Device       Boot     Start       End   Sectors   Size  Id Type
/dev/sdb1    *            0   1398783   1398784   683M  17 Hidden HPFS/NTFS 
Free space          1398784  15356159  13957376   6.7G
# parted -l
...
Number  Start   End     Size    Type      File system     Flags
 1      1049kB  21.4GB  21.4GB  primary   ext4            boot
 2      21.4GB  23.0GB  1578MB  primary   linux-swap(v1)
 3      23.0GB  37.4GB  14.4GB  primary   ext4
 4      37.4GB  40.0GB  2579MB  extended
 5      37.4GB  40.0GB  2579MB  logical   ext4

Error: Invalid partition table - recursive partition on /dev/sdb. Ignore/Cancel?
#

# partprobe 
Error: Invalid partition table - recursive partition on /dev/sdb.
# partx -s /dev/sdb
NR START     END SECTORS SIZE NAME UUID
 1     0 1398783 1398784 683M      3054920d-01
# partx -o type,flags,scheme /dev/sdb
TYPE FLAGS SCHEME
0x17 0x80  dos

Note: TYPE shows 0x17, which represents "Hidden HPFS/NTFS"

jb

author
#1 lore raw
Quoted 5 lines · jb

...
The line
└─sdb1 iso9660 Test
should be reconciled with what fdisk, etc show.
...

The following display demonstrates it better.

$ lsblk -o name,fstype,parttype,size
NAME   FSTYPE  PARTTYPE  SIZE
sda                     37.3G
├─sda1 ext4    0x83       20G
├─sda2 swap    0x82      1.5G
├─sda3 ext4    0x83     13.4G
└─sda5 ext4    0x83      2.4G
sdb    iso9660           7.3G
└─sdb1 iso9660 0x17      683M
sr0                     1024M
$

Note the sda device lines - they have proper "FSTYPE PARTTYPE" translation.

This line
└─sdb1 iso9660 0x17 683M
is contradictory as 0x17 represents "Hidden HPFS/NTFS" elsewhere (fdisk, etc).

jb

#2 lore raw
Quoted 22 lines · jb
Quoted 5 lines · jb

...
The line
└─sdb1 iso9660 Test
should be reconciled with what fdisk, etc show.
...

The following display demonstrates it better.

$ lsblk -o name,fstype,parttype,size
NAME   FSTYPE  PARTTYPE  SIZE
sda                     37.3G
├─sda1 ext4    0x83       20G
├─sda2 swap    0x82      1.5G
├─sda3 ext4    0x83     13.4G
└─sda5 ext4    0x83      2.4G
sdb    iso9660           7.3G
└─sdb1 iso9660 0x17      683M
sr0                     1024M
$
Quoted 5 lines

Note the sda device lines - they have proper "FSTYPE PARTTYPE" translation.

This line
└─sdb1 iso9660 0x17 683M
is contradictory as 0x17 represents "Hidden HPFS/NTFS" elsewhere (fdisk, etc).

Why do you think this is contradictory? The filesystem type and partition type are two disparate types.

d

author
#3 lore raw
Quoted 3 lines · Dave Reisner <d <at> falconindy.com> writes:

...
Why do you think this is contradictory? The filesystem type and partition type are two disparate types.

Yes, you are right, technically.

But I mentioned it because it bothers me, and confuses slightly. Let me explain why, and I reserve the right to be wrong if I miss some aspects of it.
It is about the business of partition types and file system types, perhaps even partitions and file systems in general.

Example:

# lsblk -o name,fstype,parttype,label,mountpoint /dev/sdb
NAME   FSTYPE PARTTYPE LABEL MOUNTPOINT
sdb                          
├─sdb1 ntfs   0x83           
└─sdb2 ext4   0x17           
# fdisk -l /dev/sdb
...
Device     Boot   Start      End Sectors  Size Id Type
/dev/sdb1  *       2048  7522303 7520256  3.6G 83 Linux
/dev/sdb2       7522304 15356159 7833856  3.8G 17 Hidden HPFS/NTFS
#

This is what I mean, a mixture of partition types (with their type names suggesting something) and file system types, contradicting each other at least in descriptions.

Somehow I have an impression that there was an intention at some time in the past to associate partition types with only certain file system types. But it never worked, or was misunderstood, or was abandoned. That's my guess.

There is some evidence to that assumption (note that they are actually contradictory in their wording):

http://en.wikipedia.org/wiki/Disk_partition
"The partition type code for a primary partition can either correspond to a file system contained within (e.g. 0x07 means either an NTFS or an OS/2 HPFS file system) or indicate that the partition has a special use (e.g. code 0x82 usually indicates a Linux swap partition). The FAT16 and FAT32 file systems have made use of a number of partition type codes due to the limits of various DOS and Windows OS versions. Though a Linux operating system may recognize a number of different file systems (ext4, ext3, ext2, ReiserFS, etc.), they have all consistently used the same partition type code: 0x83 (Linux native file system)."

http://tldp.org/HOWTO/Partition/partition-types.html
"A partition is labeled to host a certain kind of file system (...). Such a file system could be the linux standard ext2 file system or linux swap space, or even foreign file systems like (Microsoft) NTFS or (Sun) UFS."

I would like to get to the point here.
Why not abandon the partition and file system dichotomy.
Why not use just one term, let's call it fspart (file system partition), encompassing functionality of both partition and file system. For example, fspart would mean "none" for empty space (no fs), ext4, swap, NTFS, etc.
Basically, let's eliminate partition and file system as known today.

jb

author
#4 lore raw
In reply to jb
Quoted 1 line · jb

...

To continue with "Dazed and Confused" ...
I assume all of them became programmers.
https://www.youtube.com/watch?v=wknywxfcE5M

It would be good to have some rules in field naming (meaning and continuity of their use) in similar (almost identical) displays.
All of these entries display the same data types, so it is imperative that they correspond to each other clearly.

This will give you an overview of output columns:

$ lsblk -h
...
# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0 37.3G  0 disk 
├─sda1   8:1    0   17G  0 part 
├─sda2   8:2    0  4.4G  0 part [SWAP]
├─sda3   8:3    0 13.4G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0  2.4G  0 part 
sr0     11:0    1 1024M  0 rom  

The field TYPE refers to a device type, so it should be renamed to DEVTYPE. This would avoid confusion with other TYPE-like fields, e.g.
- cfdisk and fdisk
Type means partition type (by Id): Linux, Linux swap, Extended, FAT12, empty, AIX, Dell Utility, etc
- parted
Type means partition type: primary, extended, logical
- partx
Type means partition type (a string, a UUID, or hex)

# lsblk -o name,fstype,label,parttype,partlabel,mountpoint
NAME   FSTYPE LABEL  PARTTYPE PARTLABEL MOUNTPOINT
sda                                     
├─sda1 ext4          0x83               
├─sda2 swap          0x82               [SWAP]
├─sda3 ext4   Arch   0x83               /
├─sda4               0x5                
└─sda5 ext4   backup 0x83               
sr0                                     

The field LABEL should be renamed to FSLABEL, as there is also a partition label PARTLABEL.

# blkid 
/dev/sda1: UUID="fb838405-607c-4723-9355-47ccbf1eb273" TYPE="ext4"
PARTUUID="3db012b3-01" 
/dev/sda5: LABEL="backup" UUID="4f168c8f-ac1d-4048-ac3f-254fa4392c60"
TYPE="ext4" PARTUUID="3db012b3-05" 
/dev/sda2: UUID="8afa3b49-ae96-4496-9335-1afd62d67097" TYPE="swap"
PARTUUID="3db012b3-02" 
/dev/sda3: LABEL="Arch" UUID="d067602d-f15d-49c0-abad-865adab2cc8f"
TYPE="ext4" PTTYPE="dos" PARTUUID="3db012b3-03" 

The fields:
LABEL corresponds to LABEL in lsblk display, which is suggested to be renamed to FSLABEL, so this one should be too.
TYPE refers to "ext4" and "swap", which suggests a fs type, so it should be renamed to FSTYPE to correspond to lsblk display.
PTTYPE refers to "dos" ... here I am at a loss; I assume it means partition type, so it should be renamed to PARTTYPE to correspond to lsblk display; why "dos" ? why for /dev/sda3 only ?

jb

author
#5 lore raw
Quoted 4 lines · jb

...
PTTYPE refers to "dos" ... here I am at a loss; I assume it means partition type, so it should be renamed to PARTTYPE to correspond to lsblk display; why "dos" ? why for /dev/sda3 only ?

I have to correct myself here.
PTTYPE refers to partition table type, in this case "dos", which is correct. But the question "why for /dev/sda3 only ?" stands.
Actually, it should not be included in 'blkid' display at all. According to BLKID(8), only option -p should display this field.

# blkid -p /dev/sda
/dev/sda: PTUUID="3db012b3" PTTYPE="dos" 

jb

author
#6 lore raw
Quoted 6 lines · jb

...
But the question "why for /dev/sda3 only ?" stands. Actually, it should not be included in 'blkid' display at all. According to BLKID(8), only option -p should display this field.

# blkid -p /dev/sda
/dev/sda: PTUUID="3db012b3" PTTYPE="dos" 

This should be further qualified.

# blkid /dev/sda
/dev/sda: PTUUID="3db012b3" PTTYPE="dos" 
# blkid -p /dev/sda
/dev/sda: PTUUID="3db012b3" PTTYPE="dos" 

and so I think that 'blkid' entry I referred previously to (with that PTTYPE="dos" in /dev/sda3 row, believed to be erroneously displayed there), should have the "/dev/sda: ..." line displayed at the top:

# blkid
/dev/sda: PTUUID="3db012b3" PTTYPE="dos"
/dev/sda1: UUID="fb838405-607c-4723-9355-47ccbf1eb273" TYPE="ext4"
PARTUUID="3db012b3-01" 
...

because BLKID(8) says:
" When device is specified, tokens from only this device are
displayed.
It is possible to specify multiple device arguments on the
command line. If none is given, all devices which appear in
/proc/partitions are shown, if they are recognized."

$ cat /proc/partitions 
major minor  #blocks  name
  11        0    1048575 sr0
   8        0   39070080 sda
   8        1   17825792 sda1
   8        2    4647936 sda2
   8        3   14076928 sda3
   8        4          1 sda4
   8        5    2518368 sda5

jb