Skip to content

Commit 41ea0b9

Browse files
committed
install: Support non EFI partition format
This patch enables partition layouts that do not include EFI partition and/or boot partition. Without this patch, partition numbers becomes not consecutive, and subsequent findpart will fail. Signed-off-by: Yohei Ueda <[email protected]>
1 parent 5aea3ca commit 41ea0b9

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/src/install/baseline.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ use super::RW_KARG;
2929
use crate::mount;
3030
use crate::task::Task;
3131

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

3836
#[derive(clap::ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -240,6 +238,8 @@ pub(crate) fn install_create_rootfs(
240238
let bootfs = mntdir.join("boot");
241239
std::fs::create_dir_all(bootfs)?;
242240

241+
let mut partno = 0;
242+
243243
// Run sgdisk to create partitions.
244244
let mut sgdisk = Task::new("Initializing partitions", "sgdisk");
245245
// sgdisk is too verbose
@@ -250,18 +250,20 @@ pub(crate) fn install_create_rootfs(
250250
#[allow(unused_assignments)]
251251
if cfg!(target_arch = "x86_64") {
252252
// BIOS-BOOT
253+
partno += 1;
253254
sgdisk_partition(
254255
&mut sgdisk.cmd,
255-
1,
256+
partno,
256257
"0:+1M",
257258
"BIOS-BOOT",
258259
Some("21686148-6449-6E6F-744E-656564454649"),
259260
);
260261
} else if cfg!(target_arch = "aarch64") {
261262
// reserved
263+
partno += 1;
262264
sgdisk_partition(
263265
&mut sgdisk.cmd,
264-
1,
266+
partno,
265267
"0:+1M",
266268
"reserved",
267269
Some("8DA63339-0007-60C0-C436-083AC8230908"),
@@ -271,24 +273,23 @@ pub(crate) fn install_create_rootfs(
271273
}
272274

273275
let esp_partno = if super::ARCH_USES_EFI {
276+
partno += 1;
274277
sgdisk_partition(
275278
&mut sgdisk.cmd,
276-
EFIPN,
279+
partno,
277280
format!("0:+{EFIPN_SIZE_MB}M"),
278281
"EFI-SYSTEM",
279282
Some("C12A7328-F81F-11D2-BA4B-00A0C93EC93B"),
280283
);
281-
Some(EFIPN)
284+
Some(partno)
282285
} else {
283286
None
284287
};
285288

286289
// Initialize the /boot filesystem. Note that in the future, we may match
287290
// what systemd/uapi-group encourages and make /boot be FAT32 as well, as
288291
// it would aid systemd-boot.
289-
let use_xbootldr = block_setup.requires_bootpart();
290-
let mut partno = EFIPN;
291-
if use_xbootldr {
292+
let boot_partno = if block_setup.requires_bootpart() {
292293
partno += 1;
293294
sgdisk_partition(
294295
&mut sgdisk.cmd,
@@ -297,8 +298,11 @@ pub(crate) fn install_create_rootfs(
297298
"boot",
298299
None,
299300
);
300-
}
301-
let rootpn = if use_xbootldr { BOOTPN + 1 } else { EFIPN + 1 };
301+
Some(partno)
302+
} else {
303+
None
304+
};
305+
let rootpn = partno + 1;
302306
let root_size = root_size
303307
.map(|v| Cow::Owned(format!("0:{v}M")))
304308
.unwrap_or_else(|| Cow::Borrowed("0:0"));
@@ -379,8 +383,8 @@ pub(crate) fn install_create_rootfs(
379383
};
380384

381385
// Initialize the /boot filesystem
382-
let bootdev = if use_xbootldr {
383-
Some(findpart(BOOTPN)?)
386+
let bootdev = if let Some(bootpn) = boot_partno {
387+
Some(findpart(bootpn)?)
384388
} else {
385389
None
386390
};

0 commit comments

Comments
 (0)