Skip to content

Commit 3f07487

Browse files
committed
install: Move mntdevice dir into baseline
We only need our own mount points (including devtmpfs) in the baseline path. Signed-off-by: Colin Walters <[email protected]>
1 parent d096220 commit 3f07487

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

lib/src/install.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ pub(crate) struct State {
168168
override_disable_selinux: bool,
169169
config_opts: InstallConfigOpts,
170170
target_opts: InstallTargetOpts,
171-
/// Path to our devtmpfs
172-
devdir: Utf8PathBuf,
173-
mntdir: Utf8PathBuf,
174171
}
175172

176173
/// Path to initially deployed version information
@@ -630,26 +627,12 @@ async fn prepare_install(
630627
// Create our global (read-only) state which gets wrapped in an Arc
631628
// so we can pass it to worker threads too. Right now this just
632629
// combines our command line options along with some bind mounts from the host.
633-
let run_bootc = Utf8Path::new(RUN_BOOTC);
634-
let mntdir = run_bootc.join("mounts");
635-
if mntdir.exists() {
636-
std::fs::remove_dir_all(&mntdir)?;
637-
}
638-
let devdir = mntdir.join("dev");
639-
std::fs::create_dir_all(&devdir)?;
640-
Task::new_and_run(
641-
"Mounting devtmpfs",
642-
"mount",
643-
["devtmpfs", "-t", "devtmpfs", devdir.as_str()],
644-
)?;
645630
// Overmount /var/tmp with the host's, so we can use it to share state
646631
bind_mount_from_host("/var/tmp", "/var/tmp")?;
647632
let state = Arc::new(State {
648633
override_disable_selinux,
649634
source_imageref,
650635
source_digest,
651-
mntdir,
652-
devdir,
653636
config_opts,
654637
target_opts,
655638
});
@@ -724,9 +707,7 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
724707

725708
// This is all blocking stuff
726709
let mut rootfs = {
727-
let state = Arc::clone(&state);
728-
tokio::task::spawn_blocking(move || baseline::install_create_rootfs(&state, block_opts))
729-
.await??
710+
tokio::task::spawn_blocking(move || baseline::install_create_rootfs(block_opts)).await??
730711
};
731712

732713
install_to_filesystem_impl(&state, &mut rootfs).await?;

lib/src/install/baseline.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use serde::{Deserialize, Serialize};
2222

2323
use super::MountSpec;
2424
use super::RootSetup;
25-
use super::State;
25+
use super::RUN_BOOTC;
2626
use super::RW_KARG;
2727
use crate::lsm::lsm_label;
2828
use crate::mount;
@@ -156,10 +156,7 @@ fn mkfs<'a>(
156156
}
157157

158158
#[context("Creating rootfs")]
159-
pub(crate) fn install_create_rootfs(
160-
state: &State,
161-
opts: InstallBlockDeviceOpts,
162-
) -> Result<RootSetup> {
159+
pub(crate) fn install_create_rootfs(opts: InstallBlockDeviceOpts) -> Result<RootSetup> {
163160
// Verify that the target is empty (if not already wiped in particular, but it's
164161
// also good to verify that the wipe worked)
165162
let device = crate::blockdev::list_dev(&opts.device)?;
@@ -181,13 +178,26 @@ pub(crate) fn install_create_rootfs(
181178
);
182179
}
183180

181+
let run_bootc = Utf8Path::new(RUN_BOOTC);
182+
let mntdir = run_bootc.join("mounts");
183+
if mntdir.exists() {
184+
std::fs::remove_dir_all(&mntdir)?;
185+
}
186+
let devdir = mntdir.join("dev");
187+
std::fs::create_dir_all(&devdir)?;
188+
Task::new_and_run(
189+
"Mounting devtmpfs",
190+
"mount",
191+
["devtmpfs", "-t", "devtmpfs", devdir.as_str()],
192+
)?;
193+
184194
// Now at this point, our /dev is a stale snapshot because we don't have udev running.
185195
// So from hereon after, we prefix devices with our temporary devtmpfs mount.
186196
let reldevice = opts
187197
.device
188198
.strip_prefix("/dev/")
189199
.context("Absolute device path in /dev/ required")?;
190-
let device = state.devdir.join(reldevice);
200+
let device = devdir.join(reldevice);
191201

192202
let root_size = opts
193203
.root_size
@@ -198,9 +208,9 @@ pub(crate) fn install_create_rootfs(
198208

199209
// Create a temporary directory to use for mount points. Note that we're
200210
// in a mount namespace, so these should not be visible on the host.
201-
let rootfs = state.mntdir.join("rootfs");
211+
let rootfs = mntdir.join("rootfs");
202212
std::fs::create_dir_all(&rootfs)?;
203-
let bootfs = state.mntdir.join("boot");
213+
let bootfs = mntdir.join("boot");
204214
std::fs::create_dir_all(bootfs)?;
205215

206216
// Run sgdisk to create partitions.

0 commit comments

Comments
 (0)