Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blkid --match-types has no effect #3111

Open
bdrung opened this issue Jul 3, 2024 · 2 comments
Open

blkid --match-types has no effect #3111

bdrung opened this issue Jul 3, 2024 · 2 comments

Comments

@bdrung
Copy link

bdrung commented Jul 3, 2024

blkid --match-types seems to have no effect:

$ blkid
/dev/vda2: UUID="a89f4e16-bf48-4c85-8555-04f2fa8a6eb7" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="62d912c9-c2f0-4b8d-b1f2-bf0dba2787f5"
$ sudo blkid -p /dev/vda2
/dev/vda2: UUID="a89f4e16-bf48-4c85-8555-04f2fa8a6eb7" VERSION="1.0" FSBLOCKSIZE="4096" BLOCK_SIZE="4096" FSLASTBLOCK="6277888" FSSIZE="25714229248" TYPE="ext4" USAGE="filesystem" PART_ENTRY_SCHEME="gpt" PART_ENTRY_UUID="62d912c9-c2f0-4b8d-b1f2-bf0dba2787f5" PART_ENTRY_TYPE="0fc63daf-8483-4772-8e79-3d69d8477de4" PART_ENTRY_NUMBER="2" PART_ENTRY_OFFSET="2203648" PART_ENTRY_SIZE="50223104" PART_ENTRY_DISK="253:0"
$ sudo blkid -p --match-types swap /dev/vda2 || echo $?
/dev/vda2: PART_ENTRY_SCHEME="gpt" PART_ENTRY_UUID="62d912c9-c2f0-4b8d-b1f2-bf0dba2787f5" PART_ENTRY_TYPE="0fc63daf-8483-4772-8e79-3d69d8477de4" PART_ENTRY_NUMBER="2" PART_ENTRY_OFFSET="2203648" PART_ENTRY_SIZE="50223104" PART_ENTRY_DISK="253:0"

I expect blkid will fail if the type does not match.

This behavior is the same on Ubuntu 22.04, Ubuntu 24.04, Ubuntu 24.10 (util-linux 2.39.3-9ubuntu6), and Debian unstable (util-linux 2.40.1-9).

Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/2071807

@karelzak
Copy link
Collaborator

karelzak commented Jul 3, 2024

It works as expected; maybe the man page should be more accurate.

The option disables/enables the probing functions in the libblkid. This means that when you restrict it to "swap," it can detect only a swap area, and other filesystems are invisible to the prober. It's not an error if nothing is detected. Yes, the name of the option is not ideal ...

Anyway, it returns "2" if nothing is detected on the device:

# blkid -p --match-types vfat /dev/sda1 --no-part-details; echo $?
/dev/sda1: SEC_TYPE="msdos" LABEL_FATBOOT="EFI" LABEL="EFI" UUID="F2BC-BFEC" VERSION="FAT16" FSBLOCKSIZE="4096" BLOCK_SIZE="512" FSSIZE="209715200" TYPE="vfat" USAGE="filesystem"
0

# blkid -p --match-types swap /dev/sda1 --no-part-details; echo $?
2

If you want to filter devices by filesystem type, it's better to use lsblk --fs | grep or, in recent releases, lsblk -Q 'FSTYPE=="swap"'.

@bdrung
Copy link
Author

bdrung commented Jul 3, 2024

Thanks for the explanation. The man page mislead me. It would be nice if the man page could be clarified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants