Skip to content

Commit

Permalink
virtme-init: docker host support
Browse files Browse the repository at this point in the history
Minor changes to our virtme-init script required to run virtme-ng
instances inside docker containers.

This fixes issue #51.

Link: arighi/virtme-ng-init@6ed126b
Signed-off-by: Andrea Righi <[email protected]>
  • Loading branch information
Andrea Righi committed Dec 21, 2023
1 parent 6af33ee commit b25a203
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 13 additions & 4 deletions virtme/guest/virtme-init
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion virtme_ng/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b25a203

Please sign in to comment.