Skip to content

Commit 916539e

Browse files
authored
Merge pull request #529 from cgwalters/bootpn-only-if-luks
install/to-disk: Drop separate /boot by default
2 parents 122827a + e5548d8 commit 916539e

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

lib/src/install.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,9 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
11951195

11961196
// Finalize mounted filesystems
11971197
if !rootfs.skip_finalize {
1198-
let bootfs = rootfs.rootfs.join("boot");
1199-
for fs in [bootfs.as_path(), rootfs.rootfs.as_path()] {
1198+
let bootfs = rootfs.boot.as_ref().map(|_| rootfs.rootfs.join("boot"));
1199+
let bootfs = bootfs.as_ref().map(|p| p.as_path());
1200+
for fs in std::iter::once(rootfs.rootfs.as_path()).chain(bootfs) {
12001201
finalize_filesystem(fs)?;
12011202
}
12021203
}

lib/src/install/baseline.rs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use crate::task::Task;
3232
pub(crate) const BOOTPN: u32 = 3;
3333
// This ensures we end up under 512 to be small-sized.
3434
pub(crate) const BOOTPN_SIZE_MB: u32 = 510;
35-
pub(crate) const ROOTPN: u32 = 4;
3635
pub(crate) const EFIPN: u32 = 2;
3736
pub(crate) const EFIPN_SIZE_MB: u32 = 512;
3837

@@ -94,6 +93,16 @@ pub(crate) struct InstallBlockDeviceOpts {
9493
pub(crate) root_size: Option<String>,
9594
}
9695

96+
impl BlockSetup {
97+
/// Returns true if the block setup requires a separate /boot aka XBOOTLDR partition.
98+
pub(crate) fn requires_bootpart(&self) -> bool {
99+
match self {
100+
BlockSetup::Direct => false,
101+
BlockSetup::Tpm2Luks => true,
102+
}
103+
}
104+
}
105+
97106
fn sgdisk_partition(
98107
sgdisk: &mut Command,
99108
n: u32,
@@ -274,19 +283,28 @@ pub(crate) fn install_create_rootfs(
274283
None
275284
};
276285

277-
sgdisk_partition(
278-
&mut sgdisk.cmd,
279-
BOOTPN,
280-
format!("0:+{BOOTPN_SIZE_MB}M"),
281-
"boot",
282-
None,
283-
);
286+
// Initialize the /boot filesystem. Note that in the future, we may match
287+
// what systemd/uapi-group encourages and make /boot be FAT32 as well, as
288+
// it would aid systemd-boot.
289+
let use_xbootldr = block_setup.requires_bootpart();
290+
let mut partno = EFIPN;
291+
if use_xbootldr {
292+
partno += 1;
293+
sgdisk_partition(
294+
&mut sgdisk.cmd,
295+
partno,
296+
format!("0:+{BOOTPN_SIZE_MB}M"),
297+
"boot",
298+
None,
299+
);
300+
}
301+
let rootpn = if use_xbootldr { BOOTPN + 1 } else { EFIPN + 1 };
284302
let root_size = root_size
285303
.map(|v| Cow::Owned(format!("0:{v}M")))
286304
.unwrap_or_else(|| Cow::Borrowed("0:0"));
287305
sgdisk_partition(
288306
&mut sgdisk.cmd,
289-
ROOTPN,
307+
rootpn,
290308
root_size,
291309
"root",
292310
Some("0FC63DAF-8483-4772-8E79-3D69D8477DE4"),
@@ -321,7 +339,7 @@ pub(crate) fn install_create_rootfs(
321339
Ok(devdir.join(devname).to_string())
322340
};
323341

324-
let base_rootdev = findpart(ROOTPN)?;
342+
let base_rootdev = findpart(rootpn)?;
325343

326344
let (rootdev, root_blockdev_kargs) = match block_setup {
327345
BlockSetup::Direct => (base_rootdev, None),
@@ -360,23 +378,29 @@ pub(crate) fn install_create_rootfs(
360378
}
361379
};
362380

363-
// Initialize the /boot filesystem. Note that in the future, we may match
364-
// what systemd/uapi-group encourages and make /boot be FAT32 as well, as
365-
// it would aid systemd-boot.
366-
let bootdev = &findpart(BOOTPN)?;
367-
let boot_uuid = mkfs(bootdev, root_filesystem, "boot", []).context("Initializing /boot")?;
381+
// Initialize the /boot filesystem
382+
let bootdev = if use_xbootldr {
383+
Some(findpart(BOOTPN)?)
384+
} else {
385+
None
386+
};
387+
let boot_uuid = if let Some(bootdev) = bootdev.as_deref() {
388+
Some(mkfs(bootdev, root_filesystem, "boot", []).context("Initializing /boot")?)
389+
} else {
390+
None
391+
};
368392

369393
// Initialize rootfs
370394
let root_uuid = mkfs(&rootdev, root_filesystem, "root", [])?;
371395
let rootarg = format!("root=UUID={root_uuid}");
372-
let bootsrc = format!("UUID={boot_uuid}");
373-
let bootarg = format!("boot={bootsrc}");
374-
let boot = MountSpec {
396+
let bootsrc = boot_uuid.as_ref().map(|uuid| format!("UUID={uuid}"));
397+
let bootarg = bootsrc.as_deref().map(|bootsrc| format!("boot={bootsrc}"));
398+
let boot = bootsrc.map(|bootsrc| MountSpec {
375399
source: bootsrc,
376400
target: "/boot".into(),
377401
fstype: MountSpec::AUTO.into(),
378402
options: Some("ro".into()),
379-
};
403+
});
380404
let install_config_kargs = state
381405
.install_config
382406
.as_ref()
@@ -387,7 +411,8 @@ pub(crate) fn install_create_rootfs(
387411
let kargs = root_blockdev_kargs
388412
.into_iter()
389413
.flatten()
390-
.chain([rootarg, RW_KARG.to_string(), bootarg].into_iter())
414+
.chain([rootarg, RW_KARG.to_string()].into_iter())
415+
.chain(bootarg)
391416
.chain(install_config_kargs)
392417
.collect::<Vec<_>>();
393418

@@ -398,7 +423,9 @@ pub(crate) fn install_create_rootfs(
398423
let bootfs = rootfs.join("boot");
399424
// Create the underlying mount point directory, which should be labeled
400425
crate::lsm::ensure_dir_labeled(&target_rootfs, "boot", None, 0o755.into(), sepolicy)?;
401-
mount::mount(bootdev, &bootfs)?;
426+
if let Some(bootdev) = bootdev.as_deref() {
427+
mount::mount(bootdev, &bootfs)?;
428+
}
402429
// And we want to label the root mount of /boot
403430
crate::lsm::ensure_dir_labeled(&target_rootfs, "boot", None, 0o755.into(), sepolicy)?;
404431

@@ -424,7 +451,7 @@ pub(crate) fn install_create_rootfs(
424451
rootfs,
425452
rootfs_fd,
426453
rootfs_uuid: Some(root_uuid.to_string()),
427-
boot: Some(boot),
454+
boot,
428455
kargs,
429456
skip_finalize: false,
430457
})

0 commit comments

Comments
 (0)