How to fix fdisk and blkid not sorting drives properly?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
S3NTYN3L
Level 1
Level 1
Posts: 36
Joined: Fri Sep 27, 2019 5:36 pm

How to fix fdisk and blkid not sorting drives properly?

Post by S3NTYN3L »

Running fdisk -l gets me:

Code: Select all

Disk /dev/sdb: redacted
Disk /dev/sda: redacted
Disk /dev/sdc: redacted
Running blkid gets me:

Code: Select all

/dev/sdb1: redacted
/dev/sda1: redacted
/dev/sda2: redacted
/dev/sdc1: redacted
Both will sort the partitions under the above entries correctly, however.
Running lsblk sorts both drives and partitions correctly.

Code: Select all

sda 
├─sda1
└─sda2
sdb 
└─sdb1
sdc 
└─sdc1
Anyone know what's going on here and how to fix it?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Moonstone Man
Level 16
Level 16
Posts: 6054
Joined: Mon Aug 27, 2012 10:17 pm

Re: How to fix fdisk and blkid not sorting drives properly?

Post by Moonstone Man »

S3NTYN3L wrote: Wed May 05, 2021 7:25 pm Anyone know what's going on here ...
Yes. You haven't read man fdisk, man blkid or man lsblk, and if you have then you haven't understood it.

Neither fdisk nor blkid have a need to sort the output to your liking. lsblk on the other hand is explicitly designed for generating lists therefore it has a need to sort.
and how to fix it?
Write your own fdisk and blkid utilities or use lsblk.
t42
Level 11
Level 11
Posts: 3734
Joined: Mon Jan 20, 2014 6:48 pm

Re: How to fix fdisk and blkid not sorting drives properly?

Post by t42 »

S3NTYN3L wrote: Wed May 05, 2021 7:25 pm how to fix it?
As Kadaitcha Man noticed above it's not an issue so no fix required.
Anyway if you want to modify an output of blkid or fdisk -l you can, for example,

Code: Select all

sudo blkid |sort

Code: Select all

sudo fdisk -l /dev/sda /dev/sdb /dev/sdc
-=t42=-
S3NTYN3L
Level 1
Level 1
Posts: 36
Joined: Fri Sep 27, 2019 5:36 pm

Re: How to fix fdisk and blkid not sorting drives properly?

Post by S3NTYN3L »

How pissed in your corn flakes, KM? :roll:
Don't bother posting is you're just going to browbeat the OP and tell them to RTFM.
I did RTFM and it's of no help.

Every other install I've ever done has those commands sorting properly...
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to fix fdisk and blkid not sorting drives properly?

Post by rene »

This part's relevant though
Note that partx(8) provides a rich interface for scripts to print
disk layouts, fdisk is mostly designed for humans. Backward
compatibility in the output of fdisk is not guaranteed.
I.e., you should use partx if you need to rely on the output. Or just as per e.g. t42 say fdisk -l /dev/sd?.
Last edited by rene on Thu May 06, 2021 6:02 pm, edited 1 time in total.
S3NTYN3L
Level 1
Level 1
Posts: 36
Joined: Fri Sep 27, 2019 5:36 pm

Re: How to fix fdisk and blkid not sorting drives properly?

Post by S3NTYN3L »

rene wrote: Thu May 06, 2021 5:34 pm I.e., you should use partx if you need to rely on the output.
I don't need to "rely on the output".
I'm just wondering why it's not listing them on this install like it has on every other install I've ever done and how to get the "normal" output back if at all possible.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: How to fix fdisk and blkid not sorting drives properly?

Post by rene »

There being no guarantees is what is meant by said non-reliance. I mentioned a method (although I missed -l, now edited in), as slightly adjusted from t42 and possible courtesy of udev. If not good enough then the answer seemingly is that you're SOL.
Locked

Return to “Software & Applications”