-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for selecting a partition table type #1085
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the 🐦.
Users need to have control over the partition table type in certain cases. Most prominently, they need a dos-style partition table for single-board computers. Let's add a simple customizations for it.
1b04aa0
Pushed a commit that fixes DOS partition tables with legacy boot. Our code for generation grub stage options require having a protective bios boot partition, but this partition was not recognized by the code responsible for finding it, leading to a panic. I think that this fix will unblock us, but I wonder whether creating a protective bios boot partition on dos partition tables is the correct behaviour. IIRC, the BIOS core image was not protected, but I'm not sure why (maybe because of the partition count limits on dos?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this seems fine and we should probably merge to unblock the Pi users but I would also like to see a followup just like @achilleas-k suggested that cleans up the DosBIOSBootID/DosESPID
LVM test configs are failing to boot. |
Not sure what I saw when I said this. It's not a boot failure, it's a build failure. One without a good error message too:
Fully reproducible locally. |
@ondrejbudai correctly identified this is because we're trying to write a dos partition table with more than 4 partitions. |
Follow-up to the previous commit. Translates the given partition table type from a blueprint to the actual partition table.
Previously Partition.IsBIOSBoot could only recognize GPT-based bios boot.
46a85ad
I added stuff. @ondrejbudai PTAL as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Some minor nitpicks inline but feel free to ignore
DOS partition tables only support up to 4 partitions. Don't create the sfdisk stage options if this rule is violated. Stage validation failures panic, so we panic on the stage creation. This might change in the future (to return errors) but for now we use panics and put the responsibility on the callers to validate their inputs if they want to have better error control. Test sfdisk stage validation failure
Return an error when a partition table is created with type dos and more than 4 partitions. This check can only happen after the partition table is created, otherwise we would have to predict all the partitions that get created automatically, which would duplicate a lot of the logic in NewCustomPartitionTable(). Update tests: - Convert the plain+swap (valid) test to GPT since now it's invalid as DOS. - Add a fail test for a DOS partition table with too many partitions.
We can't catch all cases of dos partition table with too many partitions, but catching the obvious ones early can help.
Add a new test config with a dos partition table type. This is a copy of the LVM test config with the extra /data partition removed to make it valid (max 4 partitions). Only test on CentOS 9 and 10 to avoid growing the test cases by too much.
This should be green now, but I noticed a couple of issues with partition types being set to GUIDs for DOS. It doesn't break anything in light testing, but the partitions are marked as I can fix it here or in a quick follow-up. |
diff --git a/pkg/disk/partition_table.go b/pkg/disk/partition_table.go
index 797cf9567..4e91b7af4 100644
--- a/pkg/disk/partition_table.go
+++ b/pkg/disk/partition_table.go
@@ -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)
}
@@ -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,
@@ -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{
@@ -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 |
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
Fixed all partition type IDs and added tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
// Partition type ID for BIOS boot partition on dos | ||
DosBIOSBootID = "ef02" | ||
// Partition type ID for LVM on dos | ||
DosLVMTypeID = "8e" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for a followup, let's use this new constant everywhere, right now I still see:
$ git grep '"8e"'
cmd/otk/osbuild-gen-partition-table/main_test.go: Type: "8e",
pkg/disk/partition_table.go: part.Type = "8e"
Users need to have control over the partition table type in certain cases. Most prominently, they need a dos-style partition table for single-board computers.
Let's add a simple customizations for it.