Skip to content

Commit

Permalink
disk: fix partition type IDs for dos
Browse files Browse the repository at this point in the history
The correct partition type ID for ESP is 'ef' (not 'ef00') [1].
The partition type ID for LVM is '8e' [1].

BIOS boot partitions aren't meant for (or required) on dos partition
tables [2].  We will eventually make this a partitionless gap in the PT,
but for now let's simply use the code for 'empty'.

Use the getPartitionTypeIDfor() function for all partition type
assignments when creating partitions.

Add tests that cover all basic partition table configurations (plain,
lvm, btrfs) using dos and gpt.

[1] https://tldp.org/HOWTO/Partition-Mass-Storage-Definitions-Naming-HOWTO/x190.html
[2] https://www.gnu.org/software/grub/manual/grub/html_node/BIOS-installation.html#BIOS-installation
  • Loading branch information
achilleas-k committed Dec 10, 2024
1 parent 25ac080 commit 766d308
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 11 deletions.
14 changes: 10 additions & 4 deletions pkg/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ const (
// Partition type ID for any native Linux filesystem on dos
DosLinuxTypeID = "83"

// Partition type ID for BIOS boot partition on dos
DosBIOSBootID = "ef02"
// Partition type ID for LVM on dos
DosLVMTypeID = "8e"

// Partition type ID for BIOS boot partition on dos.
// Type ID is for 'empty'.
// TODO: drop this completely when we convert the bios BOOT space to a
// partitionless gap/offset.
DosBIOSBootID = "00"

// Partition type ID for ESP on dos
DosESPID = "ef00"
DosESPID = "ef"

// Partition type ID for swap
DosSwapID = "82"
Expand All @@ -87,7 +93,7 @@ var idMap = map[PartitionTableType]map[string]string{
"boot": DosLinuxTypeID,
"data": DosLinuxTypeID,
"esp": DosESPID,
"lvm": DosLinuxTypeID,
"lvm": DosLVMTypeID,
"swap": DosSwapID,
},
PT_GPT: {
Expand Down
19 changes: 15 additions & 4 deletions pkg/disk/partition_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,9 @@ func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, option
return nil, fmt.Errorf("%s %w", errPrefix, err)
}
case "btrfs":
addBtrfsPartition(pt, part)
if err := addBtrfsPartition(pt, part); err != nil {
return nil, fmt.Errorf("%s %w", errPrefix, err)
}
default:
return nil, fmt.Errorf("%s invalid partition type: %s", errPrefix, part.Type)
}
Expand Down Expand Up @@ -1406,8 +1408,12 @@ func addLVMPartition(pt *PartitionTable, partition blueprint.PartitionCustomizat
}

// create partition for volume group
partType, err := getPartitionTypeIDfor(pt.Type, "lvm")
if err != nil {
return fmt.Errorf("error creating lvm partition %q: %w", vgname, err)
}
newpart := Partition{
Type: LVMPartitionGUID,
Type: partType,
Size: partition.MinSize,
Bootable: false,
Payload: newvg,
Expand All @@ -1416,7 +1422,7 @@ func addLVMPartition(pt *PartitionTable, partition blueprint.PartitionCustomizat
return nil
}

func addBtrfsPartition(pt *PartitionTable, partition blueprint.PartitionCustomization) {
func addBtrfsPartition(pt *PartitionTable, partition blueprint.PartitionCustomization) error {
subvols := make([]BtrfsSubvolume, len(partition.Subvolumes))
for idx, subvol := range partition.Subvolumes {
newsubvol := BtrfsSubvolume{
Expand All @@ -1431,14 +1437,19 @@ func addBtrfsPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
}

// create partition for btrfs volume
partType, err := getPartitionTypeIDfor(pt.Type, "data")
if err != nil {
return fmt.Errorf("error creating btrfs partition: %w", err)
}
newpart := Partition{
Type: FilesystemDataGUID,
Type: partType,
Bootable: false,
Payload: newvol,
Size: partition.MinSize,
}

pt.Partitions = append(pt.Partitions, newpart)
return nil
}

// Determine if a boot partition is needed based on the customizations. A boot
Expand Down
Loading

0 comments on commit 766d308

Please sign in to comment.