On Tue, Dec 17, 2024 at 11:21:26AM +0100, Zdenek Kabelac wrote: > Dne 17. 12. 24 v 10:13 Glass Su napsal(a): > > > > > On Dec 17, 2024, at 16:34, Heming Zhao <heming.zhao@xxxxxxxx> wrote: > > > > > > Hi LVM2 maintainers, > > > > > > One of SUSE's customers encountered an issue with LVM2. The user created several partitions, one of which was marked as "BIOS boot" (4) instead of "LINUX LVM" (8E). Subsequently, the user ran pvcreate/vgcreate/lvcreate on this partition. During a system update, grub2-install installed GRUB2 in the "BIOS boot" partition, resulting in LVM2 metadata corruption. > > > > > > The root cause of this issue is that grub2-install targets the "BIOS boot" partition when this lvm2 device is specified for installation. If the user had initially marked the partition as "LINUX LVM", grub2-install would not have chosen this partition. > > > > > > On the other hand, it would be beneficial if LVM2 could implement a new filter or a filter function to detect and exclude the "BIOS boot" partition from being considered a valid target for LVM2 device creation. This could involve issuing a warning or error message to alert the user of the potential conflict. This may also help user to notice the issue more easily. > > Hi > > lvm2 is using blkid to detect 'present' signature on a block device - and > normally prompt to confirm wiping such signature. > > We may possibly add similar logic for 'partition signatures'. > > However there is still the plain fact that lvm2 with --force or even just > '--yes' option is assumed to simply proceed and clean&clear such > conflicting signatures and simply makes the block device to be a PV. > > All that said IMHO primary bug here is within 'grub2-install' which simply > should not be blindingly overwriting block device which is in use - this > should be fixed ASAP as there is the biggest risk of data loss, although I > guess everyone is using 'grub2-install --force' - as without this option > (even in my personal experience) is typically refusing to do any work.... IMHO, the BIOS Boot partition is dedicated to grub boot code and cannot be shared with other software. Any attempt other than grub writing to this area should be prohibited, it should not be the other way around. Furthermore, adding such check could lead to unexpected failures if the data is a leftover. Grub does not write blindly, it checks that the partition is indeed a BIOS Boot partition before writing to it, as the user is required to explicitly set the partition type. For LVM root with legacy BIOS boot, having a BIOS Boot partition is mandatory, otherwise grub won't have usable space to embed the boot code in the GPT partition layout, and you won't be able to boot or access a functional system in the first place. That said, the BIOS Boot partition is in use by grub before it is mistakenly used to create a PV and extend the LVM root onto it. It is unlikely that GRUB is overwriting it. In such cases, it's more likely the other way around. Thanks, Michael > > And same applies to most UI tools I've seen that use lvm2 - all seem to be > pushing '--force & --yes' with each it emitted lvm2 command... > > Regards > > Zdenek >