Skip to content

Commit acff8cc

Browse files
committed
install: Drop need for -v /:/target
Build on our new logic for bind mounting from the host mountns to also drop the need for the `-v /:/target` in the alongside install code. Signed-off-by: Colin Walters <[email protected]>
1 parent 99ef635 commit acff8cc

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

lib/src/install.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use ostree_ext::ostree;
4040
use ostree_ext::prelude::Cast;
4141
use ostree_ext::sysroot::SysrootLock;
4242
use rustix::fs::{FileTypeExt, MetadataExt as _};
43+
use rustix::thread::Pid;
4344
use serde::{Deserialize, Serialize};
4445

4546
use self::baseline::InstallBlockDeviceOpts;
@@ -56,6 +57,8 @@ use crate::utils::sigpolicy_from_opts;
5657
const BOOT: &str = "boot";
5758
/// Directory for transient runtime state
5859
const RUN_BOOTC: &str = "/run/bootc";
60+
/// The default path for the host rootfs
61+
const ALONGSIDE_ROOT_MOUNT: &str = "/target";
5962
/// This is an ext4 special directory we need to ignore.
6063
const LOST_AND_FOUND: &str = "lost+found";
6164
/// The filename of the composefs EROFS superblock; TODO move this into ostree
@@ -316,9 +319,10 @@ pub(crate) struct InstallToExistingRootOpts {
316319
#[clap(long)]
317320
pub(crate) acknowledge_destructive: bool,
318321

319-
/// Path to the mounted root; it's expected to invoke podman with
320-
/// `-v /:/target`, then supplying this argument is unnecessary.
321-
#[clap(default_value = "/target")]
322+
/// Path to the mounted root; this is now not necessary to provide.
323+
/// Historically it was necessary to ensure the host rootfs was mounted at here
324+
/// via e.g. `-v /:/target`.
325+
#[clap(default_value = ALONGSIDE_ROOT_MOUNT)]
322326
pub(crate) root_path: Utf8PathBuf,
323327
}
324328

@@ -1631,6 +1635,22 @@ pub(crate) async fn install_to_filesystem(
16311635
// And the last bit of state here is the fsopts, which we also destructure now.
16321636
let mut fsopts = opts.filesystem_opts;
16331637

1638+
// If we're doing an alongside install, automatically set up the host rootfs
1639+
// mount if it wasn't done already.
1640+
if targeting_host_root
1641+
&& fsopts.root_path.as_str() == ALONGSIDE_ROOT_MOUNT
1642+
&& !fsopts.root_path.try_exists()?
1643+
{
1644+
std::fs::create_dir(ALONGSIDE_ROOT_MOUNT)?;
1645+
crate::mount::bind_mount_from_pidns(
1646+
Pid::from_raw(1).unwrap(),
1647+
"/".into(),
1648+
ALONGSIDE_ROOT_MOUNT.into(),
1649+
true,
1650+
)
1651+
.context("Mounting host / to {ALONGSIDE_ROOT_MOUNT}")?;
1652+
}
1653+
16341654
// Check that the target is a directory
16351655
{
16361656
let root_path = &fsopts.root_path;

tests-integration/src/install.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
145145
Trial::test("Install and verify selinux state", move || {
146146
let sh = &xshell::Shell::new()?;
147147
reset_root(sh, image)?;
148-
cmd!(sh, "sudo {BASE_ARGS...} {target_args...} {image} bootc install to-existing-root --acknowledge-destructive {generic_inst_args...}").run()?;
148+
cmd!(sh, "sudo {BASE_ARGS...} {image} bootc install to-existing-root --acknowledge-destructive {generic_inst_args...}").run()?;
149149
generic_post_install_verification()?;
150150
let root = &Dir::open_ambient_dir("/ostree", cap_std::ambient_authority()).unwrap();
151151
let mut path = PathBuf::from(".");
@@ -155,7 +155,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
155155
Trial::test("Install to non-default stateroot", move || {
156156
let sh = &xshell::Shell::new()?;
157157
reset_root(sh, image)?;
158-
cmd!(sh, "sudo {BASE_ARGS...} {target_args...} {image} bootc install to-existing-root --stateroot {NON_DEFAULT_STATEROOT} --acknowledge-destructive {generic_inst_args...}").run()?;
158+
cmd!(sh, "sudo {BASE_ARGS...} {image} bootc install to-existing-root --stateroot {NON_DEFAULT_STATEROOT} --acknowledge-destructive {generic_inst_args...}").run()?;
159159
generic_post_install_verification()?;
160160
assert!(
161161
Utf8Path::new(&format!("/ostree/deploy/{NON_DEFAULT_STATEROOT}")).try_exists()?
@@ -167,7 +167,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
167167
reset_root(sh, image)?;
168168
let empty = sh.create_temp_dir()?;
169169
let empty = empty.path().to_str().unwrap();
170-
cmd!(sh, "sudo {BASE_ARGS...} {target_args...} -v {empty}:/usr/lib/bootc/install {image} bootc install to-existing-root {generic_inst_args...}").run()?;
170+
cmd!(sh, "sudo {BASE_ARGS...} -v {empty}:/usr/lib/bootc/install {image} bootc install to-existing-root {generic_inst_args...}").run()?;
171171
generic_post_install_verification()?;
172172
Ok(())
173173
}),

0 commit comments

Comments
 (0)