diff --git a/pkg/disk/partition_table.go b/pkg/disk/partition_table.go index 978b34d7fb..d91df09bdf 100644 --- a/pkg/disk/partition_table.go +++ b/pkg/disk/partition_table.go @@ -705,35 +705,35 @@ func (pt *PartitionTable) ensureLVM() error { if _, ok := parent.(*LVMLogicalVolume); ok { return nil - } else if part, ok := parent.(*Partition); ok { - filesystem := part.Payload - - vg := &LVMVolumeGroup{ - Name: "rootvg", - Description: "created via lvm2 and osbuild", - } + } + part, ok := parent.(*Partition) + if !ok { + return fmt.Errorf("Unsupported parent for LVM") + } + filesystem := part.Payload - // create root logical volume on the new volume group with the same - // size and filesystem as the previous root partition - _, err := vg.CreateLogicalVolume("rootlv", part.Size, filesystem) - if err != nil { - panic(fmt.Sprintf("Could not create LV: %v", err)) - } + vg := &LVMVolumeGroup{ + Name: "rootvg", + Description: "created via lvm2 and osbuild", + } - // replace the top-level partition payload with the new volume group - part.Payload = vg + // create root logical volume on the new volume group with the same + // size and filesystem as the previous root partition + _, err := vg.CreateLogicalVolume("rootlv", part.Size, filesystem) + if err != nil { + panic(fmt.Sprintf("Could not create LV: %v", err)) + } - // reset the vg partition size - it will be grown later - part.Size = 0 + // replace the top-level partition payload with the new volume group + part.Payload = vg - if pt.Type == PT_GPT { - part.Type = LVMPartitionGUID - } else { - part.Type = "8e" - } + // reset the vg partition size - it will be grown later + part.Size = 0 + if pt.Type == PT_GPT { + part.Type = LVMPartitionGUID } else { - return fmt.Errorf("Unsupported parent for LVM") + part.Type = "8e" } return nil @@ -763,43 +763,43 @@ func (pt *PartitionTable) ensureBtrfs() error { if _, ok := parent.(*Btrfs); ok { return nil - } else if part, ok := parent.(*Partition); ok { - rootMountable, ok := rootPath[0].(Mountable) - if !ok { - return fmt.Errorf("root entity is not mountable: %T, this is a violation of entityPath() contract", rootPath[0]) - } + } + part, ok := parent.(*Partition) + if !ok { + return fmt.Errorf("unsupported parent for btrfs: %T", parent) + } + rootMountable, ok := rootPath[0].(Mountable) + if !ok { + return fmt.Errorf("root entity is not mountable: %T, this is a violation of entityPath() contract", rootPath[0]) + } - opts, err := rootMountable.GetFSTabOptions() - if err != nil { - return err - } + opts, err := rootMountable.GetFSTabOptions() + if err != nil { + return err + } - btrfs := &Btrfs{ - Label: "root", - Subvolumes: []BtrfsSubvolume{ - { - Name: "root", - Mountpoint: "/", - Compress: DefaultBtrfsCompression, - ReadOnly: opts.ReadOnly(), - Size: part.Size, - }, + btrfs := &Btrfs{ + Label: "root", + Subvolumes: []BtrfsSubvolume{ + { + Name: "root", + Mountpoint: "/", + Compress: DefaultBtrfsCompression, + ReadOnly: opts.ReadOnly(), + Size: part.Size, }, - } + }, + } - // replace the top-level partition payload with a new btrfs filesystem - part.Payload = btrfs + // replace the top-level partition payload with a new btrfs filesystem + part.Payload = btrfs - // reset the btrfs partition size - it will be grown later - part.Size = 0 + // reset the btrfs partition size - it will be grown later + part.Size = 0 - part.Type, err = getPartitionTypeIDfor(pt.Type, "data") - if err != nil { - return fmt.Errorf("error converting partition table to btrfs: %w", err) - } - - } else { - return fmt.Errorf("unsupported parent for btrfs: %T", parent) + part.Type, err = getPartitionTypeIDfor(pt.Type, "data") + if err != nil { + return fmt.Errorf("error converting partition table to btrfs: %w", err) } return nil