2 Commits
Author SHA256 Message Date
kira fecd188b4d Bumping version to 0.2.1 2026-08-01 22:56:29 +02:00
kira ef16746068 Fixing /run remount on switch_root and elimenating /usr/bin/mount dependency. 2026-08-01 22:56:07 +02:00
4 changed files with 52 additions and 14 deletions
Generated
+3 -3
View File
@@ -305,7 +305,7 @@ checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f"
[[package]] [[package]]
name = "nyanit" name = "nyanit"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"nix", "nix",
"ratatui", "ratatui",
@@ -604,9 +604,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.54" version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e1d5e639ff6bab73cb6885cc7e7b1de96c3f32c68ec55f3952614bec1092244" checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
dependencies = [ dependencies = [
"deranged", "deranged",
"libc", "libc",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "nyanit" name = "nyanit"
version = "0.2.0" version = "0.2.1"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
+4 -1
View File
@@ -76,7 +76,10 @@ enum NyanitState {
/// Mounting bee-root and chiking if there any snapshots /// Mounting bee-root and chiking if there any snapshots
fn mount_and_check_snaps(bee_root_dev: &str) -> Result<NyanitState, ExecCommandError> { fn mount_and_check_snaps(bee_root_dev: &str) -> Result<NyanitState, ExecCommandError> {
// mount bee-root // mount bee-root
nyan_system::mount_bee_root(TMP_ROOT, bee_root_dev)?; nyan_system::mount_bee_root(bee_root_dev, TMP_ROOT)?;
// let root_list = nyan_system::list_dir(TMP_ROOT)?;
// return Err(ExecCommandError::Other(root_list));
// list snaps if any // list snaps if any
let mut snaps_list = nyan_system::list_bzzpss_snaps(TMP_ROOT_SNAPS)?; let mut snaps_list = nyan_system::list_bzzpss_snaps(TMP_ROOT_SNAPS)?;
+44 -9
View File
@@ -85,6 +85,12 @@ impl From<String> for ExecCommandError {
} }
} }
impl From<&str> for ExecCommandError {
fn from(err: &str) -> Self {
ExecCommandError::Other(err.to_string())
}
}
impl std::fmt::Display for ExecCommandError { impl std::fmt::Display for ExecCommandError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { match self {
@@ -294,14 +300,14 @@ fn wait_for_block_devices(timeout_secs: u64) -> bool {
false false
} }
// mounting process // mounting process
//# Mount essential virtual filesystems //# Mount essential virtual filesystems
// mount -t proc none /proc // mount -t proc none /proc
// mount -t sysfs none /sys // mount -t sysfs none /sys
// modprobe bcachefs // modprobe bcachefs
pub fn prepare_env() -> Result<(), String> { pub fn prepare_env() -> Result<(), ExecCommandError> {
use nix::mount::{MsFlags, mount}; use nix::mount::{MsFlags, mount};
use std::path::Path; use std::path::Path;
// Mount proc filesystem // Mount proc filesystem
@@ -313,7 +319,7 @@ pub fn prepare_env() -> Result<(), String> {
Path::new("/proc"), Path::new("/proc"),
Some("proc"), Some("proc"),
proc_mount_flags, proc_mount_flags,
Some("mode=0555"), None::<&str>,
) )
.map_err(|ex| format!("Error mounting /proc: {}", ex.to_string()))?; .map_err(|ex| format!("Error mounting /proc: {}", ex.to_string()))?;
@@ -325,13 +331,13 @@ pub fn prepare_env() -> Result<(), String> {
Path::new("/sys"), Path::new("/sys"),
Some("sysfs"), Some("sysfs"),
sys_mount_flags, sys_mount_flags,
Some("mode=0555"), None::<&str>,
) )
.map_err(|ex| format!("Error mounting /sys: {}", ex.to_string()))?; .map_err(|ex| format!("Error mounting /sys: {}", ex.to_string()))?;
//waiting for block devs population //waiting for block devs population
if wait_for_block_devices(WAIT_FOR_BLK_DEVS) == false { if wait_for_block_devices(WAIT_FOR_BLK_DEVS) == false {
return Err("Waiting for block devices to get populated timed out.".to_string()); return Err("Waiting for block devices to get populated timed out.".into());
} }
let dev_mount_flags = MsFlags::MS_NOSUID | MsFlags::MS_RELATIME; let dev_mount_flags = MsFlags::MS_NOSUID | MsFlags::MS_RELATIME;
@@ -344,8 +350,24 @@ pub fn prepare_env() -> Result<(), String> {
) )
.map_err(|ex| format!("Error mounting /dev: {}", ex.to_string()))?; .map_err(|ex| format!("Error mounting /dev: {}", ex.to_string()))?;
//mount -t tmpfs -o nosuid,nodev,noexec,mode=0755 none /run
let run_mount_flags = MsFlags::MS_NOSUID | MsFlags::MS_NODEV | MsFlags::MS_NOEXEC | MsFlags::MS_RELATIME;
mount(
Some("run"),
"/run",
Some("tmpfs"),
run_mount_flags,
Some("mode=0755"),
)
.map_err(|ex| format!("Error mounting /run: {}", ex.to_string()))?;
// modprobe bcachefs // modprobe bcachefs
// exec_command("modprobe", &vec!["bcachefs"])?; // exec_command("modprobe", &vec!["bcachefs"])?;
// Creating dir for udev so this little shit wont hang
// fs::create_dir("/run/udev")?;
Ok(()) Ok(())
} }
@@ -378,18 +400,31 @@ pub fn prepare_env() -> Result<(), String> {
// } // }
// # Mount the real root filesystem // # Mount the real root filesystem
pub fn mount_bee_root(mount_point: &str, dev_name: &str) -> Result<(), ExecCommandError> { pub fn mount_bee_root(dev_name: &str, mount_point: &str) -> Result<(), ExecCommandError> {
exec_command("/usr/bin/mount", &vec!["-o", "ro", dev_name, mount_point])?; use nix::mount::{MsFlags, mount};
use std::path::Path;
let root_mount_flags = MsFlags::MS_RDONLY | MsFlags::MS_RELATIME;
mount(
Some(dev_name),
Path::new(mount_point),
Some("bcachefs"),
root_mount_flags,
None::<&str>,
)
.map_err(|ex| format!("Error mounting root {} to {} :\n{}",dev_name, mount_point, ex.to_string()))?;
// exec_command("/usr/bin/mount", &vec!["-o", "ro", dev_name, mount_point])?;
Ok(()) Ok(())
} }
// finish boot // finish boot
pub fn hand_off_control(mnt_root: &str, init_path: &str) -> Result<(), ExecCommandError> { pub fn hand_off_control(mnt_root: &str, init_path: &str) -> Result<(), ExecCommandError> {
use std::env; //use std::env;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
// 2. Change directory to the new root (Mandatory for switch_root) // 2. Change directory to the new root (Mandatory for switch_root)
env::set_current_dir(mnt_root)?; // Actually this may be a problem!
// env::set_current_dir(mnt_root)?;
// # Clean up virtual filesystems // # Clean up virtual filesystems
// !!! do not do this, switch_root handle this stuff and fail if thay not present! // !!! do not do this, switch_root handle this stuff and fail if thay not present!