Bug 1940607

Summary: lsblk sometimes returns block devices in wrong order with --pairs
Product: Red Hat Enterprise Linux 8 Reporter: Jonathan Lebon <jlebon>
Component: util-linuxAssignee: Karel Zak <kzak>
Status: CLOSED ERRATA QA Contact: Vojtech Eichler <veichler>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.3CC: bgilbert, miabbott, veichler
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: util-linux-2.32.1-28.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 20:02:21 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jonathan Lebon 2021-03-18 17:34:42 UTC
Description of problem:

In some cases, e.g. LUKS on an NVMe partition, the order in which lsblk returns entries changes when using --pairs:

$ lsblk /dev/nvme0n1
NAME        MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
nvme0n1     259:0    0   20G  0 disk
|-nvme0n1p1 259:1    0    1M  0 part
|-nvme0n1p2 259:2    0  127M  0 part
|-nvme0n1p3 259:3    0  384M  0 part  /boot
`-nvme0n1p4 259:4    0 19.5G  0 part
  `-root    253:0    0 19.5G  0 crypt /sysroot

$ lsblk --pairs /dev/nvme0n1
NAME="root" MAJ:MIN="253:0" RM="0" SIZE="19.5G" RO="0" TYPE="crypt" MOUNTPOINT="/sysroot"
NAME="nvme0n1" MAJ:MIN="259:0" RM="0" SIZE="20G" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="nvme0n1p1" MAJ:MIN="259:1" RM="0" SIZE="1M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="nvme0n1p2" MAJ:MIN="259:2" RM="0" SIZE="127M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="nvme0n1p3" MAJ:MIN="259:3" RM="0" SIZE="384M" RO="0" TYPE="part" MOUNTPOINT="/boot"
NAME="nvme0n1p4" MAJ:MIN="259:4" RM="0" SIZE="19.5G" RO="0" TYPE="part" MOUNTPOINT=""

Notice how the root LUKS device is listed first. This makes it unusable for scripts that want to go down the hierarchy starting from the bottom of the stack.

Version-Release number of selected component (if applicable):

util-linux-2.32.1-24.el8.x86_64

How reproducible:

100%

Steps to Reproduce:
1. Set up LUKS on NVMe.
2. Run `lsblk --pairs`

Actual results:

The "leaf" LUKS container is listed before the partition it's sitting on.

Expected results:

The "leaf" LUKS container is listed after the partition it's sitting on.

Additional info:

We've hit this multiple times in RHCOS and have had to work around it:
https://github.com/coreos/coreos-installer/pull/453
https://bugzilla.redhat.com/show_bug.cgi?id=1934174#c4

Comment 1 Karel Zak 2021-03-24 12:04:03 UTC
Should be fixed by upstream commit https://github.com/karelzak/util-linux/commit/529b51706ef06611a8165023f14e6593e06901de.

Comment 5 Jonathan Lebon 2021-06-08 20:39:53 UTC
Yes, confirmed working with the same setup as in comment 0:

```
[root@cosa-devsh ~]# lsblk /dev/nvme0n1 --pairs
NAME="root" MAJ:MIN="253:0" RM="0" SIZE="15.5G" RO="0" TYPE="crypt" MOUNTPOINT="/sysroot"
NAME="nvme0n1" MAJ:MIN="259:0" RM="0" SIZE="16G" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="nvme0n1p1" MAJ:MIN="259:1" RM="0" SIZE="1M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="nvme0n1p2" MAJ:MIN="259:2" RM="0" SIZE="127M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="nvme0n1p3" MAJ:MIN="259:3" RM="0" SIZE="384M" RO="0" TYPE="part" MOUNTPOINT="/boot"
NAME="nvme0n1p4" MAJ:MIN="259:4" RM="0" SIZE="15.5G" RO="0" TYPE="part" MOUNTPOINT=""
[root@cosa-devsh ~]# rpm -Uvh *.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:libuuid-2.32.1-28.el8            ################################# [  8%]
   2:libblkid-2.32.1-28.el8           ################################# [ 17%]
   3:libfdisk-2.32.1-28.el8           ################################# [ 25%]
   4:libmount-2.32.1-28.el8           ################################# [ 33%]
   5:libsmartcols-2.32.1-28.el8       ################################# [ 42%]
   6:util-linux-2.32.1-28.el8         ################################# [ 50%]
Cleaning up / removing...
   7:util-linux-2.32.1-27.el8         ################################# [ 58%]
   8:libfdisk-2.32.1-27.el8           ################################# [ 67%]
   9:libmount-2.32.1-27.el8           ################################# [ 75%]
  10:libblkid-2.32.1-27.el8           ################################# [ 83%]
  11:libuuid-2.32.1-27.el8            ################################# [ 92%]
  12:libsmartcols-2.32.1-27.el8       ################################# [100%]
[root@cosa-devsh ~]# lsblk /dev/nvme0n1 --pairs
NAME="nvme0n1" MAJ:MIN="259:0" RM="0" SIZE="16G" RO="0" TYPE="disk" MOUNTPOINT=""
NAME="nvme0n1p1" MAJ:MIN="259:1" RM="0" SIZE="1M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="nvme0n1p2" MAJ:MIN="259:2" RM="0" SIZE="127M" RO="0" TYPE="part" MOUNTPOINT=""
NAME="nvme0n1p3" MAJ:MIN="259:3" RM="0" SIZE="384M" RO="0" TYPE="part" MOUNTPOINT="/boot"
NAME="nvme0n1p4" MAJ:MIN="259:4" RM="0" SIZE="15.5G" RO="0" TYPE="part" MOUNTPOINT=""
NAME="root" MAJ:MIN="253:0" RM="0" SIZE="15.5G" RO="0" TYPE="crypt" MOUNTPOINT="/sysroot"
```

Thanks a lot Karel!

Comment 11 errata-xmlrpc 2021-11-09 20:02:21 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (util-linux bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4490