Skip to content

Commit

Permalink
Fix partitioner not identifying mmc/nvme partitions
Browse files Browse the repository at this point in the history
We were expecting them to follow us the device name + numer at the end
but mmc and nvme partitions follow a different schema.

In order to make this work for anything and even new schemas that we may
not expect, we just get the actual device directly from udev by
resolving the /dev/disk/by-partlabel which links to the actual named
device.

Signed-off-by: Itxaka <itxaka@kairos.io>
  • Loading branch information
Itxaka committed Sep 26, 2024
1 parent a8e855b commit f7529c0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/elemental/elemental.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (e *Elemental) PartitionAndFormatDevice(i v1.SharedInstallSpec) error {
e.config.Logger.Errorf("Udevadm settle failed: %s", err)
}
// Partitions are in order so we can format them via that
for index, p := range table.GetPartitions() {
for _, p := range table.GetPartitions() {
for _, configPart := range i.GetPartitions().PartitionsByInstallOrder(i.GetExtraPartitions()) {
if configPart.Name == cnst.BiosPartName {
// Grub partition on non-EFI is not formatted. Grub is directly installed on it
Expand All @@ -112,7 +112,16 @@ func (e *Elemental) PartitionAndFormatDevice(i v1.SharedInstallSpec) error {
// we have to match the Fs it was asked with the partition in the system
if p.(*gpt.Partition).Name == configPart.Name {
e.config.Logger.Debugf("Formatting partition: %s", configPart.FilesystemLabel)
err = partitioner.FormatDevice(e.config.Runner, fmt.Sprintf("%s%d", i.GetTarget(), index+1), configPart.FS, configPart.FilesystemLabel)
// Get full partition path by the /dev/disk/by-partlabel/ facility
// So we don't need to infer the actual device under it but get udev to tell us
// So this works for "normal" devices that have the "expected" partitions (i.e. /dev/sda has /dev/sda1, /dev/sda2)
// And "weird" devices that have special subdevices like mmc or nvme
// i.e. /dev/mmcblk0 has /dev/mmcblk0p1, /dev/mmcblk0p2
device, err := filepath.EvalSymlinks(fmt.Sprintf("/dev/disk/by-partlabel/%s", configPart.Name))
if err != nil {
e.config.Logger.Errorf("Failed finding partition %s by partition label: %s", configPart.FilesystemLabel, err)
}
err = partitioner.FormatDevice(e.config.Runner, device, configPart.FS, configPart.FilesystemLabel)
if err != nil {
e.config.Logger.Errorf("Failed formatting partition: %s", err)
return err
Expand Down

0 comments on commit f7529c0

Please sign in to comment.