bootstrap: chore: extract fn mount_modules

This commit is contained in:
Mikaël Cluseau
2025-07-18 08:19:15 +02:00
parent 423a9c53e6
commit e484802284
2 changed files with 25 additions and 42 deletions

View File

@ -75,7 +75,7 @@ pub async fn run() {
let arch = lz4::Decoder::new(zarch.as_slice())?;
extract_cpio(arch).await
} else {
return Ok(());
Ok(())
}
})
.await;
@ -96,24 +96,8 @@ pub async fn run() {
// tokio::spawn(child_reaper());
// mount modules
if let Some(ref modules) = cfg.modules {
retry_or_ignore(async || {
info!("mounting modules");
mount(Some(modules), "/modules", "squashfs", None).await;
fs::create_dir_all("/lib/modules").await?;
let modules_path = &format!("/modules/lib/modules/{kernel_version}");
if !std::fs::exists(modules_path)? {
return Err(format_err!(
"invalid modules package: {modules_path} should exist"
));
}
symlink(modules_path, format!("/lib/modules/{kernel_version}"))?;
Ok(())
})
.await;
if let Some(modules) = cfg.modules.as_deref() {
retry_or_ignore(async || mount_modules(modules, &kernel_version).await).await;
} else {
warn!("modules NOT mounted (not configured)");
}
@ -181,6 +165,23 @@ pub async fn run() {
use std::path::Path;
async fn mount_modules(modules: &str, kernel_version: &str) -> Result<()> {
info!("mounting modules");
mount(Some(modules), "/modules", "squashfs", None).await;
fs::create_dir_all("/lib/modules").await?;
let modules_path = &format!("/modules/lib/modules/{kernel_version}");
if !std::fs::exists(modules_path)? {
return Err(format_err!(
"invalid modules package: {modules_path} should exist"
));
}
symlink(modules_path, format!("/lib/modules/{kernel_version}"))?;
Ok(())
}
async fn chmod(path: impl AsRef<Path>, mode: u32) -> std::io::Result<()> {
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;