diff options
author | Andy Lutomirski <luto@kernel.org> | 2016-02-23 11:26:03 -0800 |
---|---|---|
committer | Andy Lutomirski <luto@kernel.org> | 2016-02-23 11:26:03 -0800 |
commit | 5d18ab897e4401b495a6368ccdb9b14f2535bb2e (patch) | |
tree | b20925bb208c286d0346e52ff7f1ae2e95d6b95f | |
parent | 448f808f156baf179281e80264963fa7c81e4580 (diff) | |
download | virtme-5d18ab897e4401b495a6368ccdb9b14f2535bb2e.tar.gz |
Grab guest tools from a separate mount even w/o initramfs
We no longer require guest tools to exist in the rootfs to avoid
initramfs, nor do we even try to use it if it's there. Instead we
pull it in using virtfs and boot from it using the '--' kernel
command line feature to embed a scriptlet.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
-rw-r--r-- | virtme/commands/run.py | 23 | ||||
-rwxr-xr-x | virtme/guest/virtme-init | 1 | ||||
-rw-r--r-- | virtme/guest_tools.py | 42 | ||||
-rw-r--r-- | virtme/mkinitramfs.py | 9 |
4 files changed, 14 insertions, 61 deletions
diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 75cc337..d92f643 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -187,21 +187,16 @@ def main(): # Set up virtfs export_virtfs(qemu, arch, qemuargs, args.root, '/dev/root', readonly=(not args.rw)) - guest_tools_in_guest, guest_tools_path = \ - guest_tools.find_best_guest_tools(args.root) + guest_tools_path = guest_tools.find_guest_tools() if guest_tools_path is None: - raise ValueError("couldn't find usable virtme guest tools") + raise ValueError("couldn't find guest tools -- virtme is installed incorrectly") - if guest_tools_in_guest: - virtme_init = os.path.join(guest_tools_path, 'virtme-init') - else: - virtme_init = '/run/virtme/guesttools/virtme-init' - export_virtfs(qemu, arch, qemuargs, guest_tools_path, - 'virtme.guesttools') - need_initramfs = True + export_virtfs(qemu, arch, qemuargs, guest_tools_path, + 'virtme.guesttools') - # TODO: This has escaping issues for now - kernelargs.append('init=%s' % os.path.join('/', virtme_init)) + kernelargs.append('init=/bin/sh') + + initargs = ['-c', 'mount -t tmpfs run /run;mkdir -p /run/virtme/guesttools;/bin/mount -n -t 9p -o ro,version=9p2000.L,trans=virtio,access=any virtme.guesttools /run/virtme/guesttools;exec /run/virtme/guesttools/virtme-init'] # Map modules if moddir is not None: @@ -393,6 +388,10 @@ def main(): ]) initrdpath = None + # Now that we're done setting up kernelargs, append initargs + kernelargs.append('--') + kernelargs.extend(initargs) + if args.xen is None: # Load a normal kernel qemuargs.extend(['-kernel', kimg]) diff --git a/virtme/guest/virtme-init b/virtme/guest/virtme-init index 1c715d0..541ecaf 100755 --- a/virtme/guest/virtme-init +++ b/virtme/guest/virtme-init @@ -35,7 +35,6 @@ fi mount -t tmpfs tmpfs /tmp/ [[ -w /var/log ]] || mount -t tmpfs tmpfs /var/log/ -[[ -n "${virtme_run_mounted}" ]] || mount -t tmpfs run /run # Fix up /etc a little bit touch /tmp/fstab diff --git a/virtme/guest_tools.py b/virtme/guest_tools.py index f288feb..0869019 100644 --- a/virtme/guest_tools.py +++ b/virtme/guest_tools.py @@ -10,7 +10,7 @@ import os import pkg_resources -def find_dist_guest_tools(): +def find_guest_tools(): """Return the path of the guest tools installed with the running virtme. This is much more complicated than it deserves to be. @@ -32,43 +32,3 @@ def find_dist_guest_tools(): # No luck. This is somewhat surprising. return None - -def find_installed_guest_tools(root): - def has_dir(path): - # Don't use os.path.join: we want to treat absolute paths - # as relative. - return os.path.isdir(root + '/' + path) - - if has_dir('usr/local/share/virtme-guest-0'): - return '/usr/local/share/virtme-guest-0' - elif has_dir('usr/share/virtme-guest-0'): - return 'usr/share/virtme-guest-0' - else: - return None - -def find_best_guest_tools(root): - """Returns the path to the best choice of guest tools. - - This returns a tuple (in_guest, relative_path). If in_guest is true, - then relative_path is guaranteed to be relative. - """ - - # Always prefer the installed guest tools. This way blocking access - # to /home is more likely to work. - path = find_installed_guest_tools(root) - if path is not None: - return (True, path) - - # Now try the host's copy. This is here to keep root != '/' as consistent - # as possible - if root != '/': - path = find_installed_guest_tools('/') - if path is not None: - return (False, path) - - # Now try the dist copy. - path = find_dist_guest_tools() - if path is not None: - return (root == '/', os.path.relpath(path, '/')) - - return (None, None) diff --git a/virtme/mkinitramfs.py b/virtme/mkinitramfs.py index 1a295a7..a84e014 100644 --- a/virtme/mkinitramfs.py +++ b/virtme/mkinitramfs.py @@ -75,7 +75,7 @@ source /modules/load_all.sh log 'mounting hostfs...' if ! /bin/mount -n -t 9p -o ro,version=9p2000.L,trans=virtio,access=any /dev/root /newroot/; then - echo "Failed to switch to real root. We are stuck." + echo "Failed to mount real root. We are stuck." sleep 5 exit 1 fi @@ -91,7 +91,7 @@ else fi if ! [[ -d /newroot/run ]]; then - log "your host does not have /run -- using a fallback tmpfs" + log "your guest's root does not have /run -- using a fallback tmpfs" need_fallback_tmpfs=1 fi @@ -113,7 +113,6 @@ fi mount -t tmpfs run /newroot/run cp -a /run_virtme /newroot/run/virtme -export virtme_run_mounted=1 # Find init mount -t proc none /proc @@ -130,10 +129,6 @@ if [[ -z "$init" ]]; then exit 1 fi -if /bin/mount -n -t 9p -o ro,version=9p2000.L,trans=virtio,access=any virtme.guesttools /newroot/run/virtme/guesttools 2>/dev/null; then - log 'using separate guest tools' -fi - log 'done; switching to real root' exec /bin/switch_root /newroot "$init" "$@" """ |