Skip to content

Commit 6f87a68

Browse files
committed
bootloader: Generalize chroot parameter in install_via_bootupd
This is less ostree specific; prep work for issue #2270, which wants the composefs backend to use the same chroot mechanism. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 20d17fc commit 6f87a68

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

crates/lib/src/bootloader.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ pub(crate) fn supports_bootupd(root: &Dir) -> Result<bool> {
9898
/// Check whether the target bootupd supports `--filesystem`.
9999
///
100100
/// Runs `bootupctl backend install --help` and looks for `--filesystem` in the
101-
/// output. When `deployment_path` is set the command runs inside a chroot
101+
/// output. When `chroot_target` is set the command runs inside a chroot
102102
/// (via [`ChrootCmd`]) so we probe the binary from the target image.
103-
fn bootupd_supports_filesystem(rootfs: &Utf8Path, deployment_path: Option<&str>) -> Result<bool> {
103+
fn bootupd_supports_filesystem(chroot_target: Option<&Utf8Path>) -> Result<bool> {
104104
let help_args = ["bootupctl", "backend", "install", "--help"];
105-
let output = if let Some(deploy) = deployment_path {
106-
let target_root = rootfs.join(deploy);
107-
ChrootCmd::new(&target_root)
105+
let output = if let Some(target_root) = chroot_target {
106+
ChrootCmd::new(target_root)
108107
.set_default_path()
109108
.run_get_string(help_args)?
110109
} else {
@@ -129,8 +128,9 @@ fn bootupd_supports_filesystem(rootfs: &Utf8Path, deployment_path: Option<&str>)
129128
///
130129
/// When the target bootupd supports `--filesystem` we pass it pointing at a
131130
/// block-backed mount so that bootupd can resolve the backing device(s) itself
132-
/// via `lsblk`. In the chroot path we bind-mount the physical root at
133-
/// `/sysroot` to give `lsblk` a real block-backed path.
131+
/// via `lsblk`. When `chroot_target` is set, bootupctl is executed inside the
132+
/// given chroot root via [`ChrootCmd`], with the physical root bind-mounted at
133+
/// `/sysroot` so `lsblk` can resolve a real block-backed path.
134134
///
135135
/// For older bootupd versions that lack `--filesystem` we fall back to the
136136
/// legacy `--device <device_path> <rootfs>` invocation.
@@ -139,7 +139,7 @@ pub(crate) fn install_via_bootupd(
139139
device: &bootc_blockdev::Device,
140140
rootfs: &Utf8Path,
141141
configopts: &crate::install::InstallConfigOpts,
142-
deployment_path: Option<&str>,
142+
chroot_target: Option<&Utf8Path>,
143143
) -> Result<()> {
144144
let verbose = std::env::var_os("BOOTC_BOOTLOADER_DEBUG").map(|_| "-vvvv");
145145
// bootc defaults to only targeting the platform boot method.
@@ -150,7 +150,7 @@ pub(crate) fn install_via_bootupd(
150150
// This makes sure we use binaries from the target image rather than the buildroot.
151151
// In that case, the target rootfs is replaced with `/` because this is just used by
152152
// bootupd to find the backing device.
153-
let rootfs_mount = if deployment_path.is_none() {
153+
let rootfs_mount = if chroot_target.is_none() {
154154
rootfs.as_str()
155155
} else {
156156
"/"
@@ -179,7 +179,7 @@ pub(crate) fn install_via_bootupd(
179179
// parent via require_single_root(). (Older bootupd doesn't support
180180
// multiple backing devices anyway.)
181181
// Computed before building bootupd_args so the String lives long enough.
182-
let root_device_path = if bootupd_supports_filesystem(rootfs, deployment_path)
182+
let root_device_path = if bootupd_supports_filesystem(chroot_target)
183183
.context("Probing bootupd --filesystem support")?
184184
{
185185
None
@@ -200,8 +200,7 @@ pub(crate) fn install_via_bootupd(
200200
// namespace and the necessary API filesystems in the target
201201
// deployment, without requiring a user namespace (which fails under
202202
// qemu-user — see <https://github.com/bootc-dev/bootc/issues/2111>).
203-
if let Some(deploy) = deployment_path {
204-
let target_root = rootfs.join(deploy);
203+
if let Some(target_root) = chroot_target {
205204
let boot_path = rootfs.join("boot");
206205
let rootfs_path = rootfs.to_path_buf();
207206

@@ -212,7 +211,7 @@ pub(crate) fn install_via_bootupd(
212211
let mut chroot_args = vec!["bootupctl"];
213212
chroot_args.extend(bootupd_args);
214213

215-
let mut cmd = ChrootCmd::new(&target_root)
214+
let mut cmd = ChrootCmd::new(target_root)
216215
// Bind mount /boot from the physical target root so bootupctl can find
217216
// the boot partition and install the bootloader there
218217
.bind(&boot_path, &"/boot");

crates/lib/src/install.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,14 +1868,16 @@ async fn install_with_sysroot(
18681868
} else {
18691869
match postfetch.detected_bootloader {
18701870
Bootloader::Grub => {
1871+
let root_path = rootfs
1872+
.target_root_path
1873+
.clone()
1874+
.unwrap_or(rootfs.physical_root_path.clone());
1875+
let chroot_target = root_path.join(deployment_path.as_str());
18711876
crate::bootloader::install_via_bootupd(
18721877
&rootfs.device_info,
1873-
&rootfs
1874-
.target_root_path
1875-
.clone()
1876-
.unwrap_or(rootfs.physical_root_path.clone()),
1878+
&root_path,
18771879
&state.config_opts,
1878-
Some(&deployment_path.as_str()),
1880+
Some(chroot_target.as_path()),
18791881
)?;
18801882
}
18811883
Bootloader::Systemd | Bootloader::GrubCC => {

0 commit comments

Comments
 (0)