Verified Commit ca548672 authored by A. Wilcox's avatar A. Wilcox

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.
parent 6a5af0c9
Pipeline #674 passed with stages
in 1 minute and 40 seconds
......@@ -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");
}
}
......
......@@ -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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment