On Tue, Nov 19, 2024 at 12:15:02PM GMT, anchal agarwal wrote: > Hi, > I have a use case which involves imaging of a system using custom > scripts. Imaging involves installing an operating system and > formatting all the disks and setting up a File System. > At times I would like to enable LUKS on certain disk partitions, so I > format the partition using cryptsetup to setup luks format. > However, I had been seeing issues with fetching UUID post luksFormat > using lsblk. I have seen the same issue with blkid but its > occurrences are exponentially less. > I want to use lsblk because its faster but seems like blkid is more > reliable here. > From what I understood from the code, blkid opens a FD for the device > and reads directly from super block; however, going through the code > of lsblk.c I see lsblk_device_get_properties() gets it from various > methods. > > I am slightly confused as at that point in time the device database is > not set up so is lsblk fetching the UUID the same way as blkid does > using libblkid? Any information on this will be helpful. > Please correct me if my understanding is incorrect. blkid (libblkid) is the primary and usually only way to read UUID from not yet mounted filesystems. It reads it directly from block devices, so the caller needs root permission to open the block device. The usual setup is to call blkid from udevd when a new device or a write change on a device is detected. Udevd gathers this information and keeps it in the udev DB. This DB should be used as the source for other system tools because it is (or should be) up to date and does not require root permissions. lsblk primarily reads information from the udev DB. If it is not available, then it tries to read it directly from the device, which is useless for non-root users. If you get incomplete information from lsblk, it is usually because the udevd prober is not done. The typical case when this happens is: mkfs.foo /dev/sda1 lsblk /dev/sda1 In this case, lsblk reads data at a time when udevd is still running. All you need to do is call "udevadm settle" before calling lsblk. mkfs.foo /dev/sda1 udevadm settle lsblk /dev/sda1 Karel -- Karel Zak <kzak@xxxxxxxxxx> http://karelzak.blogspot.com