umount modules before switch_root

This commit is contained in:
Mikaël Cluseau
2026-04-18 20:07:32 +02:00
parent ba0a304095
commit 8596389970
5 changed files with 26 additions and 15 deletions

View File

@@ -144,6 +144,9 @@ pub async fn run() {
warn!("failed to copy {INIT_LOG} to system: {e}");
}
if let Err(e) = nix::mount::umount2("/modules", nix::mount::MntFlags::MNT_DETACH) {
warn!("failed to umount /modules: {e}");
}
retry(async || switch_root("/system").await).await;
}

View File

@@ -17,7 +17,7 @@ use crate::{fs::walk_dir, utils};
pub async fn bootstrap(cfg: Config) {
let verifier = retry(async || Verifier::from_config(&cfg)).await;
let bs = cfg.bootstrap;
let bs = &cfg.bootstrap;
mount(Some(&bs.dev), "/bootstrap", "ext4", None).await;
@@ -53,7 +53,7 @@ pub async fn bootstrap(cfg: Config) {
})
.await;
mount_system(&sys_cfg, base_dir, &verifier).await;
mount_system(&sys_cfg, &cfg, base_dir, &verifier).await;
retry_or_ignore(async || {
let path = "/etc/resolv.conf";
@@ -187,7 +187,12 @@ fn default_root_tmpfs_opts() -> Option<String> {
Some(format!("size={fs_size}m"))
}
async fn mount_system(cfg: &dkl::Config, bs_dir: &str, verifier: &Verifier) {
async fn mount_system(
cfg: &dkl::Config,
bs_cfg: &Config,
bs_dir: &str,
verifier: &Verifier,
) {
let opts = match utils::param("root-opts") {
Some(s) => Some(s.to_string()),
None => default_root_tmpfs_opts(),
@@ -201,8 +206,7 @@ async fn mount_system(cfg: &dkl::Config, bs_dir: &str, verifier: &Verifier) {
for layer in &cfg.layers {
let src = retry(async || {
if layer == "modules" {
let src = "/modules.sqfs";
if layer == "modules" && let Some(src) = bs_cfg.modules.as_ref() {
(fs::read(src).await).map_err(|e| format_err!("read {src} failed: {e}"))
} else {
verifier.verify_path(&format!("{bs_dir}/{layer}.fs")).await