SHA256
Fixing /run remount on switch_root and elimenating /usr/bin/mount dependency.
This commit is contained in:
+4
-1
@@ -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
@@ -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!
|
||||||
|
|||||||
Reference in New Issue
Block a user