SHA256
Trying to fix blkid thing. Add wayting for sysfs logic.
This commit is contained in:
+36
-2
@@ -22,6 +22,10 @@ use nix;
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
|
||||
// timeout for block deices population
|
||||
const WAIT_FOR_BLK_DEVS: u64 = 5u64;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CommandFailed {
|
||||
pub stderr: Vec<u8>,
|
||||
@@ -260,6 +264,29 @@ pub fn list_bzzpss_snaps(snaps_dir: &str) -> Result<Vec<String>, ExecCommandErro
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
||||
// pulls /sys/class/block
|
||||
fn wait_for_block_devices(timeout_secs: u64) -> bool {
|
||||
use std::path::Path;
|
||||
use std::{thread, time::Duration};
|
||||
|
||||
let start = std::time::Instant::now();
|
||||
while start.elapsed().as_secs() < timeout_secs {
|
||||
// Check if any block device exists (e.g., sda, nvme0n1, vda)
|
||||
// You can refine this to check for a specific device needed for root
|
||||
if Path::new("/sys/class/block").read_dir().ok()
|
||||
.and_then(|mut d| d.next().is_some().then_some(true))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
// Optional: Verify specific device needed for root exists
|
||||
// if Path::new("/dev/nvme0n1").exists() { return true; }
|
||||
return true;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
// mounting process
|
||||
//# Mount essential virtual filesystems
|
||||
// mount -t proc none /proc
|
||||
@@ -291,15 +318,22 @@ pub fn prepare_env() -> Result<(), String> {
|
||||
)
|
||||
.map_err(|ex| format!("Error mounting /sys: {}", ex.to_string()))?;
|
||||
|
||||
if wait_for_block_devices(WAIT_FOR_BLK_DEVS) == false {
|
||||
return Err("Waiting for block devices to get populated timed out.".to_string());
|
||||
}
|
||||
|
||||
let dev_mount_flags = MsFlags::MS_NOSUID | MsFlags::MS_RELATIME;
|
||||
mount(
|
||||
Some("devtmpfs"),
|
||||
"/dev",
|
||||
Some("devtmpfs"),
|
||||
MsFlags::empty(),
|
||||
None::<&str>,
|
||||
dev_mount_flags,
|
||||
Some("mode=0755"),
|
||||
)
|
||||
.map_err(|ex| format!("Error mounting /dev: {}", ex.to_string()))?;
|
||||
|
||||
|
||||
|
||||
// modprobe bcachefs
|
||||
// exec_command("modprobe", &vec!["bcachefs"])?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user