diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 04a778b..0d0b0cd 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -1156,6 +1156,12 @@ def do_script(shellcmd: str, show_boot_console=False) -> None: if args.user: kernelargs.append("virtme_user=%s" % args.user) + # If we are running as root on the host pass this information to the guest + # (this can be useful to properly support running virtme-ng instances + # inside docker) + if os.geteuid() == 0: + kernelargs.append("virtme_root_user=1") + initrdpath: Optional[str] if need_initramfs: diff --git a/virtme/guest/virtme-init b/virtme/guest/virtme-init index d8cd707..ee92a72 100755 --- a/virtme/guest/virtme-init +++ b/virtme/guest/virtme-init @@ -36,6 +36,13 @@ done # Setup kernel modules kver="`uname -r`" +# Make sure to always have /lib/modules, otherwise we won't be able to +# configure kmod support properly (this can happen in some container +# environments, such as docker). +if [[ ! -d /lib/modules ]]; then + mkdir -p /lib/modules +fi + if [[ -n "$virtme_root_mods" ]]; then # /lib/modules is already set up true @@ -330,10 +337,12 @@ echo " |___/ " echo " kernel version: $(uname -mr)" echo "" -# Set up a basic environment -install -d -m 0755 /tmp/roothome -export HOME=/tmp/roothome -mount --bind /tmp/roothome /root +# Set up a basic environment (unless virtme-ng is running as root on the host) +if [[ ! -n "${virtme_root_user}" ]]; then + install -d -m 0755 /tmp/roothome + export HOME=/tmp/roothome + mount --bind /tmp/roothome /root +fi # $XDG_RUNTIME_DIR defines the base directory relative to which user-specific # non-essential runtime files and other file objects (such as sockets, named diff --git a/virtme_ng/run.py b/virtme_ng/run.py index 33f00aa..409e1a0 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -766,7 +766,7 @@ def _get_virtme_overlay_rwdir(self, args): else: self.virtme_param["overlay_rwdir"] = " ".join( f"--overlay-rwdir {d}" - for d in ("/etc", "/home", "/opt", "/srv", "/usr", "/var") + for d in ("/etc", "/lib", "/home", "/opt", "/srv", "/usr", "/var") ) # Add user-specified overlays. for item in args.overlay_rwdir: