1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 06:45:13 +01:00

blockdev: add bootable property to find ESP partition

As Fedora IoT on the Raspberry Pi 3 is using `MBR` by default, we
need to find ESP partition via `bootable`.
See https://github.com/coreos/bootupd/issues/1019

Signed-off-by: Huijing Hei <hhei@redhat.com>
This commit is contained in:
Huijing Hei
2025-11-06 16:01:32 +08:00
committed by Colin Walters
parent e5249d1838
commit 4b83fa38ac

View File

@@ -117,6 +117,7 @@ pub struct Partition {
pub parttype: String,
pub uuid: Option<String>,
pub name: Option<String>,
pub bootable: Option<bool>,
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
@@ -169,6 +170,11 @@ impl PartitionTable {
pub fn find_partition_of_type(&self, uuid: &str) -> Option<&Partition> {
self.partitions.iter().find(|p| p.parttype_matches(uuid))
}
/// Find the partition with bootable is 'true'.
pub fn find_partition_of_bootable(&self) -> Option<&Partition> {
self.partitions.iter().find(|p| p.is_bootable())
}
}
impl Partition {
@@ -184,6 +190,11 @@ impl Partition {
pub fn parttype_matches(&self, uuid: &str) -> bool {
self.parttype.eq_ignore_ascii_case(uuid)
}
/// Check this partition's bootable property.
pub fn is_bootable(&self) -> bool {
self.bootable.unwrap_or(false)
}
}
#[context("Listing partitions of {dev}")]
@@ -531,6 +542,7 @@ mod test {
parttype: "c12a7328-f81f-11d2-ba4b-00a0c93ec93b".to_string(), // lowercase ESP UUID
uuid: Some("58A4C5F0-BD12-424C-B563-195AC65A25DD".to_string()),
name: Some("EFI System".to_string()),
bootable: None,
};
// Test exact match (lowercase)
@@ -602,4 +614,47 @@ mod test {
Ok(())
}
#[test]
fn test_find_partition_of_bootable() -> Result<()> {
let fixture = indoc::indoc! { r#"
{
"partitiontable": {
"label": "dos",
"id": "0xc1748067",
"device": "/dev/mmcblk0",
"unit": "sectors",
"sectorsize": 512,
"partitions": [
{
"node": "/dev/mmcblk0p1",
"start": 2048,
"size": 1026048,
"type": "6",
"bootable": true
},{
"node": "/dev/mmcblk0p2",
"start": 1028096,
"size": 2097152,
"type": "83"
},{
"node": "/dev/mmcblk0p3",
"start": 3125248,
"size": 121610240,
"type": "83"
}
]
}
}
"# };
let table: SfDiskOutput = serde_json::from_str(fixture).unwrap();
// Find ESP partition using bootalbe is true
assert_eq!(table.partitiontable.label, PartitionType::Dos);
let esp = table
.partitiontable
.find_partition_of_bootable()
.expect("bootable partition not found");
assert_eq!(esp.node, "/dev/mmcblk0p1");
Ok(())
}
}