Trying to fix blkid thing. Add wayting for sysfs logic.

This commit is contained in:
2026-07-30 14:11:00 +02:00
parent 316ffce414
commit 9601cc300b
4 changed files with 56 additions and 11 deletions
Generated
+1 -1
View File
@@ -305,7 +305,7 @@ checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f"
[[package]]
name = "nyanit"
version = "0.1.7"
version = "0.1.8"
dependencies = [
"nix",
"ratatui",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "nyanit"
version = "0.1.7"
version = "0.1.8"
edition = "2024"
[dependencies]
+18 -7
View File
@@ -90,17 +90,26 @@ fn mount_and_check_snaps(bee_root_dev: &str) -> Result<NyanitState, ExecCommandE
Ok(NyanitState::HandOff(TMP_ROOT.into()))
}
fn init_stage() -> Result<(String, NyanitState), ExecCommandError> {
// mount sysfss
nyan_system::prepare_env().map_err(|ex| format!("prepare_env error: {}", ex))?;
// get bee-root device name aka /dev/sda1
let bee_root_dev = match nyan_system::find_partlabel(ROOT_PARTLABEL) {
Err(_ex) => {
return Err(ExecCommandError::Other(nyan_system::list_partlabel().unwrap()))
},
Ok(v)=>v
};
let mut maybe_bee_root_dev = nyan_system::find_partlabel(ROOT_PARTLABEL);
if maybe_bee_root_dev.is_err() {
for _i in 0u32..5 {
thread::sleep(Duration::from_millis(100));
maybe_bee_root_dev = nyan_system::find_partlabel(ROOT_PARTLABEL);
if maybe_bee_root_dev.is_ok() {
break ;
}
}
}
let bee_root_dev= maybe_bee_root_dev?;
// check if device is encrypted
if nyan_system::bzzpss_dev_encrypted(&bee_root_dev).map_err(|ex| format!("Error checking if device is encrypted: {}", ex))? {
// if encrypted return EnterPassword so used get promted for pass
@@ -110,6 +119,7 @@ fn init_stage() -> Result<(String, NyanitState), ExecCommandError> {
// if unencrypted
let check_res = mount_and_check_snaps(&bee_root_dev)?;
Ok((bee_root_dev, check_res))
}
struct NyanitTUI<'a> {
@@ -138,7 +148,8 @@ impl NyanitTUI<'_> {
self.state = match init_stage() {
Ok(res) => {
self.bee_root_dev = res.0;
res.1
//res.1
NyanitState::Error(format!("bee_root_dev={} END EVERYTHING IS READY", self.bee_root_dev))
},
Err(ex) => {
NyanitState::Error(format!("Error while trying to bzzz-pss things:\n{}", ex))
+36 -2
View File
@@ -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(())