From: Ian Jackson Subject: Re: sidecar (hvm shim) creation script Date: Wed, 10 Jan 2018 15:39:20 +0000 Message-ID: <23126.13224.18254.699605@mariner.uk.xensource.com> References: <23123.44604.284781.889416@mariner.uk.xensource.com> <20180109194351.mmbmjzwhptlkr5as@citrix.com> <20180110083224.cmgr7flxewhx5enf@MacBook-Pro-de-Roger.local> <20180110122734.rgut34iw6ltqeipy@citrix.com> <23126.4117.777031.227394@mariner.uk.xensource.com> <20180110131049.rv6emm32efbczhl2@citrix.com> <23126.11606.582758.38945@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BiHOZehDZk" Content-Transfer-Encoding: 7bit Return-path: Received: from all-amaz-eas1.inumbo.com ([34.197.232.57]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZITQ-0001f3-ME for xen-devel@lists.xenproject.org; Wed, 10 Jan 2018 15:39:28 +0000 In-Reply-To: <23126.11606.582758.38945@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" To: Wei Liu , Roger Pau =?iso-8859-1?Q?Monn=E9?= , xen-devel@lists.xenproject.org, committers@xenproject.org, security@xenproject.org, Jan Beulich , Dario Faggioli List-Id: xen-devel@lists.xenproject.org --BiHOZehDZk Content-Type: text/plain; charset="us-ascii" Content-Description: message body text Content-Transfer-Encoding: 7bit Ian Jackson writes ("Re: sidecar (hvm shim) creation script"): > Here is the converter script where I just got my guest to boot with > the Vixen shim, as built and provided by Wei. And here is one which handles the guest console correctly. Vixen sends the L2 guest console to the emulated serial, along with the shim's own output. --BiHOZehDZk Content-Type: text/plain; name="pvshim-converter" Content-Description: for vixen, fixed the console Content-Disposition: inline; filename="pvshim-converter" Content-Transfer-Encoding: 7bit #!/usr/bin/perl -w # # usage: # pvshim-converter [OPTIONS] OLD-CONFIG NEW-CONFIG # # options: # --sidecars-directory DIR default is /var/lib/xen/pvshim-sidecars # --shim SHIM overrides domain config file # --debug verbose, and leaves sidecar prep dir around # # What we do # # read existing config file using python # determine kernel, ramdisk and cmdline # use them to produce sidecar and save it under domain name # mess with the things that need to be messed with # spit out new config file use strict; use Getopt::Long; use JSON; use IO::Handle; use POSIX; use Fcntl qw(:flock); our $debug; sub runcmd { print STDERR "+ @_\n" if $debug; $!=0; $?=0; system @_ and die "$_[0]: $! $?"; } our $shim; our $sidecars_dir = '/var/lib/xen/pvshim-sidecars'; GetOptions('sidecars-directory=s' => \$sidecars_dir, 'shim=s' => \$shim, 'debug' => \$debug) or die "pvshim-converter: bad options\n"; @ARGV==2 or die "pvshim-converter: need old and new config filenames"; our ($in,$out) = @ARGV; our $indata; if ($in ne '-') { open I, '<', "$in" or die "open input config file: $!\n"; } else { open I, '<&STDIN' or die $!; } { local $/; $indata = ; } I->error and die $!; close I; open P, "-|", qw(python -c), <; $!=0; $?=0; close P or die "$! $?"; $c = decode_json $_; } die "no domain name ?" unless exists $c->{name}; die "bootloader not yet supported" if $c->{bootloader}; die "no kernel" unless $c->{kernel}; our $sidecar = $c->{pvshim_sidecar_path} || "$sidecars_dir/$c->{name}.iso"; our $dmwrap = $c->{pvshim_sidecar_path} || "$sidecars_dir/$c->{name}.dm"; $shim ||= $c->{pvshim_path}; $shim ||= '/usr/local/lib/xen/boot/xen-shim'; our $shim_cmdline = $c->{pvshim_cmdline} || 'console=com1 com1=115200n1 loglvl=all guest_loglvl=all'; $shim_cmdline .= ' '.$c->{pvshim_extra} if $c->{pvshim_extra}; our $kernel_cmdline = $c->{cmdline} || ''; $kernel_cmdline .= ' root='.$c->{root} if $c->{root}; $kernel_cmdline .= ' '.$c->{extra} if $c->{extra}; print "pvshim-converter: creating sidecar in $sidecar\n"; runcmd qw(mkdir -m700 -p --), $sidecars_dir; open L, ">", "$sidecar.lock" or die "$sidecar.lock: open $!"; flock L, LOCK_EX or die "$sidecar.lock: lock: $!"; my $sd = "$sidecar.dir"; system qw(rm -rf --), $sd; mkdir $sd, 0700; runcmd qw(cp --), $shim, "$sd/shim"; runcmd qw(cp --), $c->{kernel}, "$sd/kernel"; runcmd qw(cp --), $c->{ramdisk}, "$sd/ramdisk" if $c->{ramdisk}; my $grubcfg = <", "$sd/boot/grub/grub.cfg" or die "$sd, grub.cfg: $!"; print G $grubcfg or die $!; close G or die $!; unlink "$sidecar.new" or $!==ENOENT or die "$sidecar.new: rm: $!"; runcmd qw(grub-mkrescue -o), "$sidecar.new", "$sidecar.dir"; if (!stat "$sidecar.new") { $!==ENOENT or die "$sidecar.new: stat: $!"; print STDERR <", "$dmwrap.new" or die "$dmwrap: $!"; print Q <<'END_DMWRAP'; #!/bin/bash set -x : "$@" set +x newargs=() newarg () { newargs+=("$1") } while [ $# -gt 1 ]; do case "$1" in -no-shutdown|-nodefaults|-no-user-config) newarg "$1"; shift ;; -xen-domid|-chardev|-mon|-display|-boot|-m|-machine) newarg "$1"; shift newarg "$1"; shift ;; -name) newarg "$1"; shift name="$1"; shift newarg "$name" ;; -netdev|-cdrom) : fixme newarg "$1"; shift newarg "$1"; shift ;; -drive|-kernel|-initrd|-append|-vnc) shift; shift ;; -device) shift case "$1" in XXXrtl8139*) newarg "-device" newarg "$1"; shift ;; *) shift ;; esac ;; *) echo >&2 "warning: unexpected argument $1 being passed through" newarg "$1"; shift ;; esac done #if [ "x$name" != x ]; then # logdir=/var/log/xen # logfile="$logdir/shim-$name.log" # savelog "$logfile" ||: # newarg -serial # newarg "file:$logfile" #fi set -x exec /usr/local/lib/xen/bin/qemu-system-i386 "${newargs[@]}" END_DMWRAP chmod 0755, "$dmwrap.new" or die "$dmwrap: chmod: $!"; close Q or die $!; rename "$sidecar.new", $sidecar or die "$sidecar: install: $!"; rename "$dmwrap.new", $dmwrap or die "$dmwrap: install: $!"; print STDERR <", "$out.tmp" or die "open output config temp: $out.tmp: $!\n"; } else { open O, ">&STDOUT" or die $!; } print O $indata, "\n", $append or die "write output: $!"; close O or die "close output: $!"; if ($out ne '-') { rename "$out.tmp", $out or die "install output: $!"; print STDERR "pvshim-converter: wrote new guest config to $out\n"; } else { print STDERR "pvshim-converter: wrote new guest config to stdout\n"; } --BiHOZehDZk Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcKaHR0cHM6Ly9saXN0 cy54ZW5wcm9qZWN0Lm9yZy9tYWlsbWFuL2xpc3RpbmZvL3hlbi1kZXZlbA== --BiHOZehDZk--