From ca5486725468e69569ff352d0d075e8081e1e22d Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 23 Jun 2020 01:11:14 -0500 Subject: hscript: Recursively bind-mount /dev and /sys We need this for /dev/shm to be present in the target. We need to bind-mount /sys recursively for efivarfs to be available for GRUB's use in the target. While we're here, unmount /dev and /sys recursively when creating an image. --- hscript/script_e.cc | 6 ++++-- image/creator.cc | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hscript/script_e.cc b/hscript/script_e.cc index 5917b19..cf004a0 100644 --- a/hscript/script_e.cc +++ b/hscript/script_e.cc @@ -169,7 +169,8 @@ bool Script::execute() const { if(!fs::exists(devpath, ec)) { fs::create_directory(devpath, ec); } - if(mount("/dev", devpath.c_str(), nullptr, MS_BIND, nullptr) != 0) { + if(mount("/dev", devpath.c_str(), nullptr, MS_BIND | MS_REC, + nullptr) != 0) { output_warning("internal", "could not bind-mount /dev; " "bootloader configuration may fail"); } @@ -184,7 +185,8 @@ bool Script::execute() const { if(!fs::exists(syspath, ec)) { fs::create_directory(syspath, ec); } - if(mount("none", syspath.c_str(), "sysfs", 0, nullptr) != 0) { + if(mount("/sys", syspath.c_str(), nullptr, MS_BIND | MS_REC, + nullptr) != 0) { output_warning("internal", "target sysfs could not be mounted"); } } diff --git a/image/creator.cc b/image/creator.cc index 1a064f1..a95e743 100644 --- a/image/creator.cc +++ b/image/creator.cc @@ -22,6 +22,7 @@ #include "backends/basic.hh" #include "hscript/meta.hh" #include "hscript/script.hh" +#include "hscript/util.hh" #include "util/filesystem.hh" #include "util/output.hh" @@ -247,9 +248,9 @@ int main(int argc, char *argv[]) { trouble: /* delete the Script and exit */ /* ensure that our target mounts are unmounted */ - umount((ir_dir + "/target/sys").c_str()); + run_command("umount", {"-R", (ir_dir + "/target/sys")}); umount((ir_dir + "/target/proc").c_str()); - umount((ir_dir + "/target/dev").c_str()); + run_command("umount", {"-R", (ir_dir + "/target/dev")}); delete my_script; early_trouble: /* no script yet */ -- cgit v1.2.3-60-g2f50