diff --git a/pkg/blueprint/disk_customizations.go b/pkg/blueprint/disk_customizations.go index 09b92099fd..ad67070bc1 100644 --- a/pkg/blueprint/disk_customizations.go +++ b/pkg/blueprint/disk_customizations.go @@ -314,12 +314,12 @@ func (p *DiskCustomization) Validate() error { var errs []error for _, part := range p.Partitions { switch part.Type { + case "plain", "": + errs = append(errs, part.validatePlain(mountpoints)) case "lvm": errs = append(errs, part.validateLVM(mountpoints, vgnames)) case "btrfs": errs = append(errs, part.validateBtrfs(mountpoints)) - case "plain", "": - errs = append(errs, part.validatePlain(mountpoints)) default: errs = append(errs, fmt.Errorf("unknown partition type: %s", part.Type)) } @@ -382,19 +382,19 @@ func (p *DiskCustomization) ValidateLayoutConstraints() error { // Check that the fs type is valid for the mountpoint. func validateFilesystemType(path, fstype string) error { - badfsMsg := "unsupported filesystem type for %q: %s" + badfsMsgFmt := "unsupported filesystem type for %q: %s" switch path { case "/boot": switch fstype { case "xfs", "ext4": default: - return fmt.Errorf(badfsMsg, path, fstype) + return fmt.Errorf(badfsMsgFmt, path, fstype) } case "/boot/efi": switch fstype { case "vfat": default: - return fmt.Errorf(badfsMsg, path, fstype) + return fmt.Errorf(badfsMsgFmt, path, fstype) } } return nil diff --git a/pkg/blueprint/disk_customizations_test.go b/pkg/blueprint/disk_customizations_test.go index 980190015b..a8f8227e75 100644 --- a/pkg/blueprint/disk_customizations_test.go +++ b/pkg/blueprint/disk_customizations_test.go @@ -848,12 +848,6 @@ func TestPartitioningLayoutConstraints(t *testing.T) { "unhappy-btrfs+lvm": { partitioning: &blueprint.DiskCustomization{ Partitions: []blueprint.PartitionCustomization{ - { - Type: "ext4", - FilesystemTypedCustomization: blueprint.FilesystemTypedCustomization{ - Mountpoint: "/data", - }, - }, { Type: "btrfs", BtrfsVolumeCustomization: blueprint.BtrfsVolumeCustomization{ @@ -1276,12 +1270,6 @@ func TestPartitionCustomizationUnmarshalJSON(t *testing.T) { "mountpoint": "/home", "label": "home", "fs_type": "ext4" - }, - { - "name": "loglv", - "mountpoint": "/var/log", - "label": "log", - "fs_type": "xfs" } ] }`, diff --git a/pkg/disk/partition_table.go b/pkg/disk/partition_table.go index 9bed8eb611..7c0cd01c2f 100644 --- a/pkg/disk/partition_table.go +++ b/pkg/disk/partition_table.go @@ -1000,6 +1000,10 @@ func EnsureRootFilesystem(pt *PartitionTable, defaultFsType FSType) error { // partition to the end of the existing partition table therefore it is best to // call this function early to put boot near the front (as is conventional). func AddBootPartition(pt *PartitionTable, bootFsType FSType) error { + if bootFsType == FS_NONE { + return fmt.Errorf("error creating boot partition: no filesystem type") + } + // collect all labels to avoid conflicts labels := make(map[string]bool) _ = pt.ForEachMountable(func(mnt Mountable, path []Entity) error { @@ -1007,10 +1011,6 @@ func AddBootPartition(pt *PartitionTable, bootFsType FSType) error { return nil }) - if bootFsType == FS_NONE { - return fmt.Errorf("error creating boot partition: no filesystem type") - } - bootLabel, err := genUniqueString("boot", labels) if err != nil { return fmt.Errorf("error creating boot partition: %w", err) @@ -1158,12 +1158,8 @@ func (options *CustomPartitionTableOptions) getfstype(fstype string) (string, er // NewCustomPartitionTable creates a partition table based almost entirely on the disk customizations from a blueprint. func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, options *CustomPartitionTableOptions, rng *rand.Rand) (*PartitionTable, error) { if options == nil { - // init options with defaults - options = &CustomPartitionTableOptions{ - PartitionTableType: PT_GPT, - } + options = &CustomPartitionTableOptions{} } - if customizations == nil { customizations = &blueprint.DiskCustomization{} } @@ -1255,7 +1251,7 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz } partType, err := getPartitionTypeIDfor(pt.Type, typeName) if err != nil { - return fmt.Errorf("error creating root partition: %w", err) + return fmt.Errorf("error getting partition type ID for %q: %w", partition.Mountpoint, err) } newpart := Partition{ Type: partType, @@ -1275,7 +1271,7 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz func addLVMPartition(pt *PartitionTable, partition blueprint.PartitionCustomization, options *CustomPartitionTableOptions) error { vgname := partition.Name if vgname == "" { - // count existing volume groups and generate unique name + // get existing volume groups and generate unique name existing := make(map[string]bool) for _, part := range pt.Partitions { vg, ok := part.Payload.(*LVMVolumeGroup)