On Thu, Aug 04, 2022 at 06:27:46PM +0200, Philipp Rudo wrote:
Hi Coiby,
[...]
Can we really rely on ls providing the right order here? If so why not simply do 'ls -1 ${dev}p2' ?
Yes, I should have simply used "ls -1 ${dev}". However your suggestion of using lsblk inspires me to find a more reliable method which also works for RHEL cloud base image,
if [[ $(lsblk -f ${dev}p2 -n -o LABEL 2> /dev/null) == boot ]] echo ${dev}p2 fi
Originally I refrained from using LABEL as the way I understand it it is more a scratchpad for users so they can remember which partition contains what. So especially on systems with a custom partition scheme there is no guarantee that the LABEL on the boot partition contains
(although when thinking about it PARTLABEL probably has the same problem).
Anyway, on second thought this script is only run in a very specific environment and isn't shipped to customers. So we don't have to be generic but can take some shortcuts. So using LABEL should be fine.
But I'm not sure if the suggestion you made above makes sense. Originally the function was used to return the boot partition of a device (which happens to be the second partition). Now you are verifying that the second partition is the boot partition.
For REHL9 cloud image, the second partition is an efi partition and there is no separate boot partition. Verifying that the second partition is the boot partition could avoid this problem.
Anyway when you are using the LABEL you can also use findfs to get the partition. I don't know what findfs does when there are multiple partitions with the same LABEL so I think it is better to pipe the output to grep. I.e. this should work
findfs LABEL=boot 2> /dev/null | grep $dev
I can confirm it works, thanks for teaching me one more tip:)