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
|
||||
fn mount_and_check_snaps(bee_root_dev: &str) -> Result<NyanitState, ExecCommandError> {
|
||||
// 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
|
||||
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 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
@@ -294,14 +300,14 @@ fn wait_for_block_devices(timeout_secs: u64) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
// mounting process
|
||||
//# Mount essential virtual filesystems
|
||||
// mount -t proc none /proc
|
||||
// mount -t sysfs none /sys
|
||||
// modprobe bcachefs
|
||||
pub fn prepare_env() -> Result<(), String> {
|
||||
pub fn prepare_env() -> Result<(), ExecCommandError> {
|
||||
use nix::mount::{MsFlags, mount};
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
// Mount proc filesystem
|
||||
@@ -313,7 +319,7 @@ pub fn prepare_env() -> Result<(), String> {
|
||||
Path::new("/proc"),
|
||||
Some("proc"),
|
||||
proc_mount_flags,
|
||||
Some("mode=0555"),
|
||||
None::<&str>,
|
||||
)
|
||||
.map_err(|ex| format!("Error mounting /proc: {}", ex.to_string()))?;
|
||||
|
||||
@@ -325,13 +331,13 @@ pub fn prepare_env() -> Result<(), String> {
|
||||
Path::new("/sys"),
|
||||
Some("sysfs"),
|
||||
sys_mount_flags,
|
||||
Some("mode=0555"),
|
||||
None::<&str>,
|
||||
)
|
||||
.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.".to_string());
|
||||
return Err("Waiting for block devices to get populated timed out.".into());
|
||||
}
|
||||
|
||||
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()))?;
|
||||
|
||||
//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
|
||||
// exec_command("modprobe", &vec!["bcachefs"])?;
|
||||
|
||||
// Creating dir for udev so this little shit wont hang
|
||||
// fs::create_dir("/run/udev")?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -378,18 +400,31 @@ pub fn prepare_env() -> Result<(), String> {
|
||||
// }
|
||||
|
||||
// # Mount the real root filesystem
|
||||
pub fn mount_bee_root(mount_point: &str, dev_name: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command("/usr/bin/mount", &vec!["-o", "ro", dev_name, mount_point])?;
|
||||
pub fn mount_bee_root(dev_name: &str, mount_point: &str) -> Result<(), ExecCommandError> {
|
||||
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(())
|
||||
}
|
||||
|
||||
// finish boot
|
||||
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;
|
||||
|
||||
// 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
|
||||
// !!! do not do this, switch_root handle this stuff and fail if thay not present!
|
||||
|
||||
Reference in New Issue
Block a user