added new_root and old_root
This commit is contained in:
parent
620d870298
commit
a04400decc
23
src/void.rs
23
src/void.rs
@ -130,23 +130,26 @@ impl VoidBuilder {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// prepare a subdirectory to pivot the old root into
|
// prepare a subdirectory to pivot the old root into
|
||||||
let put_old = new_root.join("old_root/");
|
let old_root = new_root.join("old_root/");
|
||||||
debug!("new_root: {:?}; put_old: {:?}", &new_root, &put_old);
|
debug!("new_root: {:?}; put_old: {:?}", &new_root, &old_root);
|
||||||
fs::create_dir(&put_old)?;
|
fs::create_dir(&old_root)?;
|
||||||
|
|
||||||
// pivot the old root into a subdirectory of the new root
|
// pivot the old root into a subdirectory of the new root
|
||||||
pivot_root(&new_root, &put_old).map_err(|e| Error::Nix {
|
pivot_root(&new_root, &old_root).map_err(|e| Error::Nix {
|
||||||
msg: "pivot_root",
|
msg: "pivot_root",
|
||||||
src: e,
|
src: e,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let new_root = PathBuf::from("/");
|
||||||
|
let old_root = PathBuf::from("/old_root/");
|
||||||
|
|
||||||
// chdir after
|
// chdir after
|
||||||
std::env::set_current_dir("/")?;
|
std::env::set_current_dir(&new_root)?;
|
||||||
|
|
||||||
// mount paths before unmounting old_root
|
// mount paths before unmounting old_root
|
||||||
for (src, dst) in &self.mounts {
|
for (src, dst) in &self.mounts {
|
||||||
let src = PathBuf::from("/old_root/").join(src.strip_prefix("/").unwrap_or(src));
|
let src = old_root.join(src.strip_prefix("/").unwrap_or(src));
|
||||||
let dst = PathBuf::from("/").join(dst);
|
let dst = new_root.join(dst.strip_prefix("/").unwrap_or(dst));
|
||||||
|
|
||||||
debug!("mounting `{:?}` as `{:?}`", src, dst);
|
debug!("mounting `{:?}` as `{:?}`", src, dst);
|
||||||
|
|
||||||
@ -179,7 +182,7 @@ impl VoidBuilder {
|
|||||||
// the submounts (because MNT_DETACH is recursive)
|
// the submounts (because MNT_DETACH is recursive)
|
||||||
mount(
|
mount(
|
||||||
Option::<&str>::None,
|
Option::<&str>::None,
|
||||||
"/old_root/",
|
&old_root,
|
||||||
Option::<&str>::None,
|
Option::<&str>::None,
|
||||||
MsFlags::MS_REC | MsFlags::MS_PRIVATE,
|
MsFlags::MS_REC | MsFlags::MS_PRIVATE,
|
||||||
Option::<&str>::None,
|
Option::<&str>::None,
|
||||||
@ -190,13 +193,13 @@ impl VoidBuilder {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// unmount the old root
|
// unmount the old root
|
||||||
umount2("/old_root/", MntFlags::MNT_DETACH).map_err(|e| Error::Nix {
|
umount2(&old_root, MntFlags::MNT_DETACH).map_err(|e| Error::Nix {
|
||||||
msg: "umount2",
|
msg: "umount2",
|
||||||
src: e,
|
src: e,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// delete the old root mount point
|
// delete the old root mount point
|
||||||
fs::remove_dir("old_root/")?;
|
fs::remove_dir(&old_root)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user