Skip to content

Commit

Permalink
Merge pull request #623 from yoheiueda/non-efi
Browse files Browse the repository at this point in the history
install: Support non EFI partition format
  • Loading branch information
cgwalters committed Jun 21, 2024
2 parents 72bca1b + 41ea0b9 commit 63d3e3e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ use super::RW_KARG;
use crate::mount;
use crate::task::Task;

pub(crate) const BOOTPN: u32 = 3;
// This ensures we end up under 512 to be small-sized.
pub(crate) const BOOTPN_SIZE_MB: u32 = 510;
pub(crate) const EFIPN: u32 = 2;
pub(crate) const EFIPN_SIZE_MB: u32 = 512;

#[derive(clap::ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -239,6 +237,8 @@ pub(crate) fn install_create_rootfs(
let bootfs = mntdir.join("boot");
std::fs::create_dir_all(bootfs)?;

let mut partno = 0;

// Run sgdisk to create partitions.
let mut sgdisk = Task::new("Initializing partitions", "sgdisk");
// sgdisk is too verbose
Expand All @@ -249,18 +249,20 @@ pub(crate) fn install_create_rootfs(
#[allow(unused_assignments)]
if cfg!(target_arch = "x86_64") {
// BIOS-BOOT
partno += 1;
sgdisk_partition(
&mut sgdisk.cmd,
1,
partno,
"0:+1M",
"BIOS-BOOT",
Some("21686148-6449-6E6F-744E-656564454649"),
);
} else if cfg!(target_arch = "aarch64") {
// reserved
partno += 1;
sgdisk_partition(
&mut sgdisk.cmd,
1,
partno,
"0:+1M",
"reserved",
Some("8DA63339-0007-60C0-C436-083AC8230908"),
Expand All @@ -270,24 +272,23 @@ pub(crate) fn install_create_rootfs(
}

let esp_partno = if super::ARCH_USES_EFI {
partno += 1;
sgdisk_partition(
&mut sgdisk.cmd,
EFIPN,
partno,
format!("0:+{EFIPN_SIZE_MB}M"),
"EFI-SYSTEM",
Some("C12A7328-F81F-11D2-BA4B-00A0C93EC93B"),
);
Some(EFIPN)
Some(partno)
} else {
None
};

// Initialize the /boot filesystem. Note that in the future, we may match
// what systemd/uapi-group encourages and make /boot be FAT32 as well, as
// it would aid systemd-boot.
let use_xbootldr = block_setup.requires_bootpart();
let mut partno = EFIPN;
if use_xbootldr {
let boot_partno = if block_setup.requires_bootpart() {
partno += 1;
sgdisk_partition(
&mut sgdisk.cmd,
Expand All @@ -296,8 +297,11 @@ pub(crate) fn install_create_rootfs(
"boot",
None,
);
}
let rootpn = if use_xbootldr { BOOTPN + 1 } else { EFIPN + 1 };
Some(partno)
} else {
None
};
let rootpn = partno + 1;
let root_size = root_size
.map(|v| Cow::Owned(format!("0:{v}M")))
.unwrap_or_else(|| Cow::Borrowed("0:0"));
Expand Down Expand Up @@ -379,8 +383,8 @@ pub(crate) fn install_create_rootfs(
};

// Initialize the /boot filesystem
let bootdev = if use_xbootldr {
Some(findpart(BOOTPN)?)
let bootdev = if let Some(bootpn) = boot_partno {
Some(findpart(bootpn)?)
} else {
None
};
Expand Down

0 comments on commit 63d3e3e

Please sign in to comment.