SHA256
Compare commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
fecd188b4d | ||
|
|
ef16746068 | ||
|
|
1998df9720 | ||
|
|
84d210d07c | ||
|
|
9601cc300b | ||
|
|
316ffce414 |
Generated
+3
-3
@@ -305,7 +305,7 @@ checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nyanit"
|
name = "nyanit"
|
||||||
version = "0.1.6"
|
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
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nyanit"
|
name = "nyanit"
|
||||||
version = "0.1.6"
|
version = "0.2.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+17
-9
@@ -41,7 +41,7 @@ const BEE_CAT: &str = include_str!("bee_cat.txt");
|
|||||||
//const ROOT_PARTLABEL: &str = "bee-root";
|
//const ROOT_PARTLABEL: &str = "bee-root";
|
||||||
const ROOT_PARTLABEL: &str = "bee-root";
|
const ROOT_PARTLABEL: &str = "bee-root";
|
||||||
const TMP_ROOT: &str = "/mnt/bee_root";
|
const TMP_ROOT: &str = "/mnt/bee_root";
|
||||||
const TMP_ROOT_SNAPS: &str = "/mnt/bee-root/bzz_snaps";
|
const TMP_ROOT_SNAPS: &str = "/mnt/bee_root/bzz_snaps";
|
||||||
const SYS_INIT: &str = "/sbin/init";
|
const SYS_INIT: &str = "/sbin/init";
|
||||||
|
|
||||||
// fn bee_root_is_present() -> bool {
|
// fn bee_root_is_present() -> bool {
|
||||||
@@ -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)?;
|
||||||
@@ -95,9 +98,15 @@ fn init_stage() -> Result<(String, NyanitState), ExecCommandError> {
|
|||||||
nyan_system::prepare_env().map_err(|ex| format!("prepare_env error: {}", ex))?;
|
nyan_system::prepare_env().map_err(|ex| format!("prepare_env error: {}", ex))?;
|
||||||
|
|
||||||
// get bee-root device name aka /dev/sda1
|
// get bee-root device name aka /dev/sda1
|
||||||
let bee_root_dev = nyan_system::find_partlabel(ROOT_PARTLABEL)?;
|
// trying for max 3 sec
|
||||||
|
let bee_root_dev = nyan_system::try_find_partlabel(ROOT_PARTLABEL, 3)
|
||||||
|
.ok_or_else(|| "Timed out trying to find dev by partlabel.".to_string())?;
|
||||||
|
|
||||||
|
// works until this point!!!!
|
||||||
// check if device is encrypted
|
// 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 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
|
// if encrypted return EnterPassword so used get promted for pass
|
||||||
return Ok((bee_root_dev, NyanitState::EnterPassword));
|
return Ok((bee_root_dev, NyanitState::EnterPassword));
|
||||||
}
|
}
|
||||||
@@ -134,10 +143,10 @@ impl NyanitTUI<'_> {
|
|||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
self.bee_root_dev = res.0;
|
self.bee_root_dev = res.0;
|
||||||
res.1
|
res.1
|
||||||
},
|
}
|
||||||
Err(ex) => {
|
Err(ex) => {
|
||||||
NyanitState::Error(format!("Error while trying to bzzz-pss things:\n{}", ex))
|
NyanitState::Error(format!("Error while trying to bzzz-pss things:\n{}", ex))
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// if drive unencrypted and there is no root snapshots finish boot
|
// if drive unencrypted and there is no root snapshots finish boot
|
||||||
@@ -288,7 +297,8 @@ impl NyanitTUI<'_> {
|
|||||||
Ok(unlocked) => {
|
Ok(unlocked) => {
|
||||||
if unlocked {
|
if unlocked {
|
||||||
// need to check for subvolumes and stuff
|
// need to check for subvolumes and stuff
|
||||||
self.state = match mount_and_check_snaps(&self.bee_root_dev) {
|
self.state = match mount_and_check_snaps(&self.bee_root_dev)
|
||||||
|
{
|
||||||
Ok(st) => {
|
Ok(st) => {
|
||||||
self.time_counter = 0;
|
self.time_counter = 0;
|
||||||
st
|
st
|
||||||
@@ -342,8 +352,6 @@ impl NyanitTUI<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
// nyan_system::set_env_vars_unsafe();
|
// nyan_system::set_env_vars_unsafe();
|
||||||
let mut app = NyanitTUI::new().unwrap();
|
let mut app = NyanitTUI::new().unwrap();
|
||||||
|
|||||||
+150
-57
@@ -22,6 +22,9 @@ use nix;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
// timeout for block deices population
|
||||||
|
const WAIT_FOR_BLK_DEVS: u64 = 5u64;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CommandFailed {
|
pub struct CommandFailed {
|
||||||
pub stderr: Vec<u8>,
|
pub stderr: Vec<u8>,
|
||||||
@@ -82,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 {
|
||||||
@@ -110,15 +119,28 @@ pub fn exec_command(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn try_find_partlabel(partlabel: &str, timeout_secs: u64) -> Option<String> {
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
while start.elapsed().as_secs() < timeout_secs {
|
||||||
|
if let Ok(Some(label)) = find_partlabel(partlabel) {
|
||||||
|
return Some(label);
|
||||||
|
}
|
||||||
|
thread::sleep(Duration::from_millis(100));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets device node aka /dev/sda1 from gpr partition label
|
/// Gets device node aka /dev/sda1 from gpr partition label
|
||||||
/// blkid -s PARTLABEL --match-token "PARTLABEL=primary"
|
/// blkid -s PARTLABEL --match-token PARTLABEL="bzz-primary"
|
||||||
pub fn find_partlabel(partlabel: &str) -> Result<String, ExecCommandError> {
|
pub fn find_partlabel(partlabel: &str) -> Result<Option<String>, ExecCommandError> {
|
||||||
let out = Command::new("/usr/bin/blkid")
|
let out = Command::new("/usr/bin/blkid")
|
||||||
.args([
|
.args([
|
||||||
"-s",
|
"-s",
|
||||||
"PARTLABEL",
|
"PARTLABEL",
|
||||||
"--match-token",
|
"-t",
|
||||||
format!("\"PARTLABEL={}\"", partlabel).as_str(),
|
format!("PARTLABEL=\"{}\"", partlabel).as_str(),
|
||||||
])
|
])
|
||||||
.output()?;
|
.output()?;
|
||||||
if out.status.success() {
|
if out.status.success() {
|
||||||
@@ -128,16 +150,32 @@ pub fn find_partlabel(partlabel: &str) -> Result<String, ExecCommandError> {
|
|||||||
ExecCommandError::Other(format!("Unexpected blkid output format: \"{}\"", out_text))
|
ExecCommandError::Other(format!("Unexpected blkid output format: \"{}\"", out_text))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(split_res.0.to_string())
|
Ok(Some(split_res.0.to_string()))
|
||||||
} else {
|
} else {
|
||||||
Err(ExecCommandError::Other(format!(
|
if let Some(code) = out.status.code()
|
||||||
"Connot find device with partlabel={} or something other is wrong: \"{}\"",
|
&& code == 2
|
||||||
partlabel,
|
{
|
||||||
String::from_utf8(out.stderr).unwrap_or_else(|_| String::new())
|
Ok(None)
|
||||||
)))
|
} else {
|
||||||
|
Err(ExecCommandError::Other(format!(
|
||||||
|
"Error while looking for partlabel={}: \"{}\"",
|
||||||
|
partlabel,
|
||||||
|
String::from_utf8(out.stderr).unwrap_or_else(|ex| ex.to_string())
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pub fn list_dir(dirname: &str) -> Result<String, ExecCommandError> {
|
||||||
|
// let res: String = fs::read_dir(dirname)?
|
||||||
|
// .filter_map(|entry| entry.ok())
|
||||||
|
// .map(|entry| entry.file_name().to_string_lossy().to_string())
|
||||||
|
// .collect::<Vec<String>>()
|
||||||
|
// .join("\n");
|
||||||
|
|
||||||
|
// Ok(res)
|
||||||
|
// }
|
||||||
|
|
||||||
/// exec given command with arguments, returning stdout parsed to UTF-8 string
|
/// exec given command with arguments, returning stdout parsed to UTF-8 string
|
||||||
/// capturing stderr in case or failure
|
/// capturing stderr in case or failure
|
||||||
// pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecCommandError> {
|
// pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecCommandError> {
|
||||||
@@ -149,21 +187,6 @@ pub fn find_partlabel(partlabel: &str) -> Result<String, ExecCommandError> {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// ls /dev/disk/by-partlabel/
|
|
||||||
// here we can find gpt part labels
|
|
||||||
// pub fn list_gpt_labeled_devs() -> Result<Vec<String>, ExecCommandError> {
|
|
||||||
// use std::os::unix::fs::FileTypeExt;
|
|
||||||
// let mut res: Vec<String> = Vec::new();
|
|
||||||
// for maybe_entry in fs::read_dir("/dev/disk/by-partlabel/")? {
|
|
||||||
// let entry = maybe_entry?;
|
|
||||||
// if entry.file_type()?.is_block_device() {
|
|
||||||
// res.push(entry.path().to_str().unwrap().to_string());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Ok(res)
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// bcachefs unlock --file=/tmp/bzzpsspass.txt /dev/loop0somedev
|
/// bcachefs unlock --file=/tmp/bzzpsspass.txt /dev/loop0somedev
|
||||||
/// Ok so. It is stupid, because bcacheutils far from ideal.
|
/// Ok so. It is stupid, because bcacheutils far from ideal.
|
||||||
/// But if we provide wrong password from file or stdin this stuff plays stupid and asks for right password.
|
/// But if we provide wrong password from file or stdin this stuff plays stupid and asks for right password.
|
||||||
@@ -229,10 +252,17 @@ pub fn bzzpss_dev_encrypted(dev_name: &str) -> Result<bool, ExecCommandError> {
|
|||||||
//const TMP_ROOT: &str = "/mnt/bee-root";
|
//const TMP_ROOT: &str = "/mnt/bee-root";
|
||||||
pub fn list_bzzpss_snaps(snaps_dir: &str) -> Result<Vec<String>, ExecCommandError> {
|
pub fn list_bzzpss_snaps(snaps_dir: &str) -> Result<Vec<String>, ExecCommandError> {
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
// root snapshoot in a form of bzz-yyyy-mm-ddTHH-MM-SS
|
// root snapshoot in a form of bzz-yyyy-mm-ddTHH-MM-SS
|
||||||
let re = Regex::new(r"^bzz-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}$").unwrap();
|
let re = Regex::new(r"^bzz-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}$").unwrap();
|
||||||
|
|
||||||
let mut res: Vec<String> = Vec::new();
|
let mut res: Vec<String> = Vec::new();
|
||||||
|
// if snaps dir path do not exist return empty list
|
||||||
|
if !Path::new(snaps_dir).exists() {
|
||||||
|
return Ok(res);
|
||||||
|
}
|
||||||
|
|
||||||
for maybe_entry in fs::read_dir(snaps_dir)? {
|
for maybe_entry in fs::read_dir(snaps_dir)? {
|
||||||
let entry = maybe_entry?;
|
let entry = maybe_entry?;
|
||||||
if entry.file_type()?.is_dir() {
|
if entry.file_type()?.is_dir() {
|
||||||
@@ -246,92 +276,155 @@ pub fn list_bzzpss_snaps(snaps_dir: &str) -> Result<Vec<String>, ExecCommandErro
|
|||||||
Ok(res)
|
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
|
// 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
|
||||||
// mount -t proc none /proc
|
// mount -t proc none /proc
|
||||||
|
let proc_mount_flags =
|
||||||
|
MsFlags::MS_NOSUID | MsFlags::MS_NODEV | MsFlags::MS_NOEXEC | MsFlags::MS_RELATIME;
|
||||||
mount(
|
mount(
|
||||||
Some("proc"),
|
Some("proc"),
|
||||||
Path::new("/proc"),
|
Path::new("/proc"),
|
||||||
Some("proc"),
|
Some("proc"),
|
||||||
MsFlags::empty(),
|
proc_mount_flags,
|
||||||
None::<&str>,
|
None::<&str>,
|
||||||
)
|
)
|
||||||
.map_err(|ex| format!("Error mounting /proc: {}", ex.to_string()))?;
|
.map_err(|ex| format!("Error mounting /proc: {}", ex.to_string()))?;
|
||||||
|
|
||||||
// mount -t sysfs none /sys
|
// mount -t sysfs none /sys
|
||||||
|
let sys_mount_flags =
|
||||||
|
MsFlags::MS_NOSUID | MsFlags::MS_NODEV | MsFlags::MS_NOEXEC | MsFlags::MS_RELATIME;
|
||||||
mount(
|
mount(
|
||||||
Some("sysfs"),
|
Some("sysfs"),
|
||||||
Path::new("/sys"),
|
Path::new("/sys"),
|
||||||
Some("sysfs"),
|
Some("sysfs"),
|
||||||
MsFlags::empty(),
|
sys_mount_flags,
|
||||||
None::<&str>,
|
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
|
||||||
|
if wait_for_block_devices(WAIT_FOR_BLK_DEVS) == false {
|
||||||
|
return Err("Waiting for block devices to get populated timed out.".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let dev_mount_flags = MsFlags::MS_NOSUID | MsFlags::MS_RELATIME;
|
||||||
mount(
|
mount(
|
||||||
Some("devtmpfs"),
|
Some("devtmpfs"),
|
||||||
"/dev",
|
"/dev",
|
||||||
Some("devtmpfs"),
|
Some("devtmpfs"),
|
||||||
MsFlags::empty(),
|
dev_mount_flags,
|
||||||
None::<&str>,
|
Some("mode=0755"),
|
||||||
)
|
)
|
||||||
.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(())
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// MUST be done before spawning any threads or async runtimes
|
/// MUST be done before spawning any threads or async runtimes
|
||||||
pub fn set_env_vars_unsafe() -> () {
|
// pub fn set_env_vars_unsafe() -> () {
|
||||||
use std::env;
|
// use std::env;
|
||||||
// 1. Define your custom paths
|
// // 1. Define your custom paths
|
||||||
let custom_bin = "/usr/bin";
|
// let custom_bin = "/usr/bin";
|
||||||
let custom_lib = "/usr/lib";
|
// let custom_lib = "/usr/lib";
|
||||||
|
|
||||||
// 2. Retrieve existing paths to append/prepend (optional but recommended)
|
// // 2. Retrieve existing paths to append/prepend (optional but recommended)
|
||||||
// 3. Construct new path strings
|
// // 3. Construct new path strings
|
||||||
let new_path = match env::var("PATH") {
|
// let new_path = match env::var("PATH") {
|
||||||
Err(_) => custom_bin.to_string(),
|
// Err(_) => custom_bin.to_string(),
|
||||||
Ok(v) => format!("{}:{}", custom_bin, v),
|
// Ok(v) => format!("{}:{}", custom_bin, v),
|
||||||
};
|
// };
|
||||||
|
|
||||||
let new_ld_path = match env::var("LD_LIBRARY_PATH") {
|
// let new_ld_path = match env::var("LD_LIBRARY_PATH") {
|
||||||
Err(_) => custom_lib.to_string(),
|
// Err(_) => custom_lib.to_string(),
|
||||||
Ok(v) => format!("{}:{}", custom_lib, v),
|
// Ok(v) => format!("{}:{}", custom_lib, v),
|
||||||
};
|
// };
|
||||||
|
|
||||||
// 4. Set environment variables (UNSAFE in Rust 2024+)
|
// // 4. Set environment variables (UNSAFE in Rust 2024+)
|
||||||
// MUST be done before spawning any threads or async runtimes
|
// // MUST be done before spawning any threads or async runtimes
|
||||||
unsafe {
|
// unsafe {
|
||||||
env::set_var("PATH", new_path);
|
// env::set_var("PATH", new_path);
|
||||||
env::set_var("LD_LIBRARY_PATH", new_ld_path);
|
// env::set_var("LD_LIBRARY_PATH", new_ld_path);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// # 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!
|
||||||
|
|||||||
Reference in New Issue
Block a user