vms-0.2.1/0000755000000000000000000000000013341764426011027 5ustar rootrootvms-0.2.1/packaging/0000755000000000000000000000000013341764426012753 5ustar rootrootvms-0.2.1/packaging/slackware/0000755000000000000000000000000013341764426014727 5ustar rootrootvms-0.2.1/packaging/slackware/02_make_package.sh0000644000000000000000000000005313341764426020152 0ustar rootroot#/bin/sh cd vms TAG=did sh vms.SlackBuild vms-0.2.1/packaging/slackware/03_prepare_sbo.sh0000644000000000000000000000020013341764426020056 0ustar rootroot#!/bin/sh mv vms/vms-*.tar.gz . if [ -f vms.tar.gz ]; then rm vms.tar.gz fi tar --owner 0 --group 0 -cvf vms.tar.gz vms/ vms-0.2.1/packaging/slackware/vms/0000755000000000000000000000000013341764426015534 5ustar rootrootvms-0.2.1/packaging/slackware/vms/vms.SlackBuild0000644000000000000000000000635013341764426020304 0ustar rootroot#!/bin/sh # Slackware build script for vms # Copyright 2018 Nikos Giotis, Athens, Greece # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PRGNAM=vms VERSION=${VERSION:-0.2.1} BUILD=${BUILD:-1} TAG=${TAG:-_SBo} # Automatically determine the architecture we're building on: if [ -z "$ARCH" ]; then case "$( uname -m )" in i?86) ARCH=i586 ;; arm*) ARCH=arm ;; # Unless $ARCH is already set, use uname -m for all other archs: *) ARCH=$( uname -m ) ;; esac fi CWD=$(pwd) TMP=${TMP:-/tmp/SBo} PKG=$TMP/package-$PRGNAM OUTPUT=${OUTPUT:-/tmp} if [ "$ARCH" = "i586" ]; then SLKCFLAGS="-O2 -march=i586 -mtune=i686" LIBDIRSUFFIX="" elif [ "$ARCH" = "i686" ]; then SLKCFLAGS="-O2 -march=i686 -mtune=i686" LIBDIRSUFFIX="" elif [ "$ARCH" = "x86_64" ]; then SLKCFLAGS="-O2 -fPIC" LIBDIRSUFFIX="64" else SLKCFLAGS="-O2" LIBDIRSUFFIX="" fi set -e # Exit on most errors rm -rf $PKG mkdir -p $TMP $PKG $OUTPUT cd $TMP rm -rf $PRGNAM-$VERSION tar xvf $CWD/$PRGNAM-$VERSION.tar.gz cd $PRGNAM-$VERSION chown -R root:root . find -L . \ \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ -o -perm 511 \) -exec chmod 755 {} \; -o \ \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; cp -a src/* $PKG mv $PKG/etc/rc.d/rc.vms $PKG/etc/rc.d/rc.vms.new mv $PKG/etc/rc.d/rc.vms.conf $PKG/etc/rc.d/rc.vms.conf.new mv $PKG/var/lib/vms/vm.sh $PKG/var/lib/vms/vm.sh.new # Copy man pages for i in 1 5 7 8; do mkdir -p $PKG/usr/man/man$i cp doc/man/man$i/*.$i $PKG/usr/man/man$i done # Compress man pages find $PKG/usr/man -type f -exec gzip -9 {} \; for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done # Copy program documentation into the package # Also, include the SlackBuild script in the documentation directory mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION cp -a \ README* \ $PKG/usr/doc/$PRGNAM-$VERSION cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild # Copy the slack-desc and a custom doinst.sh into ./install mkdir -p $PKG/install cat $CWD/slack-desc > $PKG/install/slack-desc cat $CWD/doinst.sh > $PKG/install/doinst.sh # Make the package cd $PKG /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-noarch-$BUILD$TAG.${PKGTYPE:-tgz} vms-0.2.1/packaging/slackware/vms/README0000644000000000000000000000243313341764426016416 0ustar rootroot# vms A collection of `bash` scripts for running `qemu` virtual machines ## Requirements To use vnc a `vncviewer` such as `tigervnc` from `extra` is required. ## Description Simple `bash` scripts for easy creation and managing `qemu` virtual machines. The whole system is to be used as a helper to generate the `qemu` command line using a single configuration file for each user of the system `~/.vms/vms.conf`. A command line utility is provided, `vms` that can be used to create and manage virtual machines. The user edits his `~/.vms/vms.conf` file to add more options, such as more devices or raw `qemu` command line options. The `vms` utility can also be used to list, start, stop, kill the configured virtual machines and provides access to vnc, serial and `qemu` monitor consoles. It has minimal dependencies, `bash` and `qemu` are needed for most of the functionality. `vms stop` uses `socat`, `vms monitor` uses `unixterm` from the `vde2` package, `vms serial` uses `minicom` and `vms vnc` needs `vncviewer`. An init script `rc.vms` is also provided with a simple mechanism for the administrator to enable booting any user's virtual machine on boot by editing `rc.vms.conf`. As a bonus two scripts are provided, `pci-stub-bind` and `vfio-bind` to ease the pain when using pci passthrough. vms-0.2.1/packaging/slackware/vms/doinst.sh0000644000000000000000000000121713341764426017371 0ustar rootrootconfig() { NEW="$1" OLD="$(dirname $NEW)/$(basename $NEW .new)" # If there's no config file by that name, mv it over: if [ ! -r $OLD ]; then mv $NEW $OLD elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then # toss the redundant copy rm $NEW fi # Otherwise, we leave the .new copy for the admin to consider... } preserve_perms() { NEW="$1" OLD="$(dirname $NEW)/$(basename $NEW .new)" if [ -e $OLD ]; then cp -a $OLD ${NEW}.incoming cat $NEW > ${NEW}.incoming mv ${NEW}.incoming $NEW fi config $NEW } preserve_perms etc/rc.d/rc.vms.new config etc/rc.d/rc.vms.conf.new config var/lib/vms/vm.sh.new vms-0.2.1/packaging/slackware/vms/vms.info0000644000000000000000000000042013341764426017212 0ustar rootrootPRGNAM="vms" VERSION="0.2.1" HOMEPAGE="https://bitbucket.org/yotis/vms" DOWNLOAD="https://bitbucket.org/yotis/vms/downloads/vms-0.2.1.tar.gz" MD5SUM="" DOWNLOAD_x86_64="" MD5SUM_x86_64="" REQUIRES="qemu socat vde2" MAINTAINER="Nikos Giotis" EMAIL="nikos.giotis@gmail.com" vms-0.2.1/packaging/slackware/vms/slack-desc0000644000000000000000000000125113341764426017467 0ustar rootroot# HOW TO EDIT THIS FILE: # The "handy ruler" below makes it easier to edit a package description. # Line up the first '|' above the ':' following the base package name, and # the '|' on the right side marks the last column you can put a character in. # You must make exactly 11 lines for the formatting to be correct. It's also # customary to leave one space after the ':' except on otherwise blank lines. |-----handy-ruler------------------------------------------------------| vms: vms (More qemu virtual machines!) vms: vms: A collection of bash scripts for running qemu virtual machines vms: vms: Homepage: https://bitbucket.org/yotis/vms vms: vms: vms: vms: vms: vms: vms-0.2.1/packaging/slackware/01_prepare_source.sh0000644000000000000000000000105513341764426020602 0ustar rootroot#/bin/sh VERSION=${VERSION:-0.2.0} last_commit=$( git log -n1 | grep commit ) COMMIT=$( echo $last_commit | cut -c 8- - | cut -c -12 - ) echo preparing $COMMIT if [ ! -f $COMMIT.tar.gz ]; then wget https://bitbucket.org/yotis/vms/get/$COMMIT.tar.gz fi tar xvf $COMMIT.tar.gz mv yotis-vms-$COMMIT vms-$VERSION tar --owner 0 --group 0 -cvf vms-$VERSION.tar.gz vms-$VERSION rm -r vms-$VERSION new_md5=$( md5sum vms-$VERSION.tar.gz | cut -c -32 - ) echo $new_md5 sed -i -e "s/MD5SUM=.*/MD5SUM=\"${new_md5}\"/g" vms/vms.info mv vms-$VERSION.tar.gz vms/ vms-0.2.1/src/0000755000000000000000000000000013341764426011616 5ustar rootrootvms-0.2.1/src/var/0000755000000000000000000000000013341764426012406 5ustar rootrootvms-0.2.1/src/var/lib/0000755000000000000000000000000013341764426013154 5ustar rootrootvms-0.2.1/src/var/lib/vms/0000755000000000000000000000000013341764426013761 5ustar rootrootvms-0.2.1/src/var/lib/vms/vm.sh0000644000000000000000000000116613341764426014743 0ustar rootroot#!/bin/bash DIR=$( dirname "${BASH_SOURCE[0]}" ) . /usr/bin/vms-parse VM_NAME=$(basename "$0" | cut -d'.' -f1) unset VM; declare -A VM setup_VM $VM_NAME || exit 1 # Basic error checking if [ "$(declare | grep $VM_NAME)" = "" ]; then echo "$VM_NAME configuration missing from $HOME/.vms/vms.conf" exit 1 fi # Call qemu qemu-system-${VM[arch]} \ -name ${VM[name]} -uuid ${VM[uuid]} -pidfile ${VM[pid]} \ $RTC $KVM $CPU $SMP $MEM $KVM $DISKS $CDROM $BOOTCD $VNC \ $BRS $VDES $NICS $SERIAL $CONSOLE $EXTRAS $SECURE $LOG $DAEMON result=$? if [ $result -ne 0 ]; then echo "qemu error $result" exit 1 fi vms-0.2.1/src/etc/0000755000000000000000000000000013341764426012371 5ustar rootrootvms-0.2.1/src/etc/rc.d/0000755000000000000000000000000013341764426013217 5ustar rootrootvms-0.2.1/src/etc/rc.d/rc.vms0000755000000000000000000000700113341764426014353 0ustar rootroot#!/bin/bash # Copyright 2018 Nikos Giotis, Athens, GR # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # rc.vms init script. # See rc.vms.conf file for configuration print_usage() { cat << EOF Usage: $0 [command] Commands status Display the status of all machines in the set start Start all the machines in the set stop Stop all the machines in the set restart Restart all the machines in the set cmd Call 'vms ' as user See rc.vms(8) EOF } # Allow normal users to only run rc.vms without arguments if [ "$1" != "" ] && [ "$(id -u)" != "0" ]; then echo "$0 must be run as root" exit 2 fi confs=$( cat /etc/rc.d/rc.vms.conf | grep -o '^[^#]*' ) vms_cmd() { if [ "$1" == "" -o "$2" == "" ]; then echo "usage: $0 cmd " exit 2 fi # This hack needs to be reviewed secure=$( su -c "vms info $3" $1 | grep 'secure: yes' ) if [ "${secure: -3}" == "yes" ]; then vm_dir=$(su -c 'echo $HOME' $1)/.vms/$3 if [ "$1" != 'root' ]; then echo -n 'S:' if [ ! -d $HOME/.vms ]; then mkdir -p $HOME/.vms fi if [ ! -L $HOME/.vms/$3 ]; then echo "Creating link for $3 for root" ln -s $vm_dir $HOME/.vms/$3 fi vmsconf=$HOME/.vms/vms.conf if [ -f $vmsconf ]; then mv $vmsconf $vmsconf.bak fi cp $vm_dir/../vms.conf $vmsconf vms $2 $3 rm $vmsconf if [ -f $vmsconf.bak ]; then mv $vmsconf.bak $vmsconf fi fi else su -c "vms $2 $3" $1 fi } vms_cmd_all() { if [ "$1" == "" ]; then echo "usage: $0 [rev]" exit 2 fi if [ "$2" == "rev" ]; then confs=$(tac /etc/rc.d/rc.vms.conf | grep -o '^[^#]*') fi index=0; user="" for conf in $confs; do if [[ $(( index % 2 )) -eq 0 ]]; then user=$conf else vms_cmd $user $1 $conf fi index=$(( index + 1 )) done } vms_status() { vms_cmd_all status } vms_start() { vms_cmd_all start } vms_stop() { vms_cmd_all stop rev } vms_restart() { vms_cmd_all stop rev vms_cmd_all start } case "$1" in 'status') vms_status ;; 'start') vms_start ;; 'stop') vms_stop ;; 'restart') vms_restart ;; 'cmd') vms_cmd $2 $3 $4 ;; *) print_usage exit 2 esac vms-0.2.1/src/etc/rc.d/rc.vms.conf0000644000000000000000000000024513341764426015277 0ustar rootroot# rc.vms.conf # # Configuration file used by rc.vms # Lines starting with '#' are ignored. # # This file contains pairs in the following form # # joe vm1 # doe vm2 vms-0.2.1/src/usr/0000755000000000000000000000000013341764426012427 5ustar rootrootvms-0.2.1/src/usr/sbin/0000755000000000000000000000000013341764426013362 5ustar rootrootvms-0.2.1/src/usr/sbin/pci-stub-bind0000755000000000000000000000313013341764426015745 0ustar rootroot#!/bin/bash # Copyright 2018 Nikos Giotis, Athens, GR # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /sbin/modprobe pci-stub for var in "$@"; do if [ ! -d "/sys/bus/pci/devices/$var/iommu_group/devices" ]; then echo "Cannot find iommu group for $var" exit 1 fi for dev in $(ls /sys/bus/pci/devices/$var/iommu_group/devices); do vendor=$(cat /sys/bus/pci/devices/$dev/vendor) device=$(cat /sys/bus/pci/devices/$dev/device) if [ -e /sys/bus/pci/devices/$dev/driver ]; then echo $dev > /sys/bus/pci/devices/$dev/driver/unbind fi echo $vendor $device > /sys/bus/pci/drivers/pci-stub/new_id done done vms-0.2.1/src/usr/sbin/vfio-bind0000755000000000000000000000375113341764426015173 0ustar rootroot#!/bin/bash # Copyright 2018 Nikos Giotis, Athens, GR # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. VFIO_GROUP=${VFIO_GROUP:-users} /sbin/modprobe vfio /sbin/modprobe vfio-pci for var in "$@"; do if [ ! -d "/sys/bus/pci/devices/0000:$var/iommu_group/devices" ]; then echo "Cannot find iommu group for $var" exit 1 fi for dev in $(ls /sys/bus/pci/devices/0000:$var/iommu_group/devices); do read -r vendor < /sys/bus/pci/devices/$dev/vendor read -r device < /sys/bus/pci/devices/$dev/device if [ -e /sys/bus/pci/devices/$dev/driver ]; then echo -n "Unbinding old driver from $dev ... " echo $dev > /sys/bus/pci/devices/$dev/driver/unbind echo "done." fi echo -n "New id $vendor:$device to vfio-pci ... " echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id echo "done." done group_link=$(readlink /sys/bus/pci/devices/0000:$var/iommu_group) group=$(basename $group_link) # ls -l /dev/vfio/$group chown root:$VFIO_GROUP /dev/vfio/$group chmod g+rw /dev/vfio/$group # ls -l /dev/vfio/$group done vms-0.2.1/src/usr/share/0000755000000000000000000000000013341764426013531 5ustar rootrootvms-0.2.1/src/usr/share/vms/0000755000000000000000000000000013341764426014336 5ustar rootrootvms-0.2.1/src/usr/share/vms/vms.conf.example0000644000000000000000000000312313341764426017443 0ustar rootroot#!/bin/bash ## ## This is an example vms.conf that exists in ~/.vms/vms.conf ## This file lists all the available options to the parser ## Use it as a reference or a starting point when creating a vm ## Copy, paste, edit and uncomment accordingly ## All lines starting with '##' should be deleted ## ## Options that end with numbers can be used for multiple devices ## eg. disk0, disk1, nic0, nic1, ... ## ## This is needed for declaring the vm named avm declare -A avm ## The next three are mandatory for every vm ## 'vms create avm' can be used to create these avm[name]=avm avm[uuid]='ffffffff-ffff-ffff-ffff-ffffffffffff' avm[arch]=x86_64 ## The rest are all the optional possible options # avm[disk0]=/path/to/disk.qcow2 # avm[vde0]='net1,sock=/path/to/vde-socket' # avm[br0]='net0' # avm[br1]='net1,br=br1' # avm[nic0]='virtio-net-pci,mac=FF:FF:FF:FF:FF:FF,netdev=net0' # avm[nic1]='virtio-net-pci,mac=FF:FF:FF:FF:FF:FF,netdev=net1' # avm[cpu]='host' # avm[mem]=1024 # avm[smp]=2 # avm[rtc]='base=utc' # avm[bootcd]=/path/to/boot.iso # avm[vnc]=5 # avm[kvm]=yes # avm[log]=yes # avm[serial]=yes # avm[monitor]=yes ## Any extra lines can be passed as raw parameters to the qemu command line ## as shown below # avm[extra0]='-nodefaults' # avm[extra1]='-device vfio-pci,host=06:00.0,romfile=/path/to/device-bios.rom' # avm[extra2]='-usbdevice tablet -k en-us' ## Set deamon key to yes. This way the machine can be used during startup. # avm[daemon]=yes ## Set secure key to yes. avm is intented to be used by root via eg. ## /etc/rc.d/rc.vms start ## Also, secure implies 'avm[deamon]=yes' # avm[secure]=yes vms-0.2.1/src/usr/bin/0000755000000000000000000000000013341764426013177 5ustar rootrootvms-0.2.1/src/usr/bin/vms-parse0000644000000000000000000001267313341764426015050 0ustar rootroot#!/bin/bash # Copyright 2018 Nikos Giotis, Athens, GR # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # vms-parse # Purpose: more qemu virtual machines ! A simple parser for a set of # predefined keys in an associative array. Used by vms script. vmsconf="$HOME/.vms/vms.conf" if [ ! -f $vmsconf ]; then echo "Can't find vms.conf"; exit 1 fi . "$vmsconf" valid_vm() { if [ "${VM[name]}" == "" ]; then echo 'vm does not exist' exit 1 fi if [ "${VM[uuid]}" == "" ]; then echo 'vm[uuid] is missing' exit 1 fi } check_vm() { valid_vm pid=$( pgrep -f "${VM[uuid]}" ) if [ "$pid" != "" ]; then echo -n "${VM[name]} is running as " echo $pid exit 1 fi } get_rundir() { rundir="/var/run/${VM[name]}" if [ "${VM[secure]}" != "yes" ] && [ "$(id -u)" != "0" ]; then rundir="$HOME/.vms/run/${VM[name]}" fi echo $rundir } create_rundir() { RUNDIR=$(get_rundir) if [ -d $RUNDIR ]; then rm -rf $RUNDIR fi mkdir -p $RUNDIR } parse_vm() { declare -n selected_vm=$1 VM[name]=${selected_vm[name]} VM[uuid]=${selected_vm[uuid]} VM[arch]=${selected_vm[arch]} for attr in ${!selected_vm[*]}; do VM[$attr]=${selected_vm[$attr]} done for attr in ${!selected_vm[*]}; do parse_attribute $attr done VM[pid]=$(get_rundir).pid } # ---- ?? -- review function names .. unset VM; declare -A VM valid_VM() { parse_vm $1 valid_vm } secure_VM() { parse_vm $1 if [ "${VM[secure]}" == "yes" ] && [ "$(id -u)" != "0" ]; then echo "no" else echo "yes" fi } rundir_VM() { parse_vm $1 if [ "${VM[name]}" == "" ]; then echo 'vm does not exist' exit 1 fi if [ "${VM[uuid]}" == "" ]; then echo 'vm[uuid] is missing' exit 1 fi echo $(get_rundir) } process_VM() { parse_vm $1 if [ "${VM[name]}" == "" ]; then echo 'vm does not exist' exit 1 fi if [ "${VM[uuid]}" == "" ]; then echo 'vm[uuid] is missing' exit 1 fi pid=$( pgrep -f "${VM[uuid]}" ) if [ "$pid" != "" ]; then pgrep -f "${VM[uuid]}" fi } vnc_VM() { parse_vm $1 if [ "${VM[vnc]}" != "" ]; then echo ${VM[vnc]} fi } status_VM() { parse_vm $1 check_vm } info_VM() { parse_vm $1 if [ "${VM[name]}" == "" ]; then echo "$1 does not exist" exit 1 fi attrs=$(for attr in ${!VM[*]}; do echo $attr; done | sort) for attr in $attrs; do printf "%8s: %s\n" "$attr" "${VM[$attr]}" done } setup_VM() { parse_vm $1 check_vm || exit 1 create_rundir || exit 1 # if [ ! -f ${VM[disk01]} ]; then # echo ${VM[disk01]} does not exist # exit 1 # fi } parse_attribute() { if [[ $1 == disk* ]]; then DISKS="$DISKS -drive file=${VM[$1]}" elif [[ $1 == vde* ]]; then VDES="$VDES -netdev vde,id=${VM[$1]}" elif [[ $1 == br* ]]; then BRS="$BRS -netdev bridge,id=${VM[$1]}" elif [[ $1 == nic* ]]; then NICS="$NICS -device ${VM[$1]}" elif [[ $1 == extra* ]]; then EXTRAS="$EXTRAS ${VM[$1]}" elif [[ $1 == cpu ]]; then CPU="-cpu ${VM[cpu]}" elif [[ $1 == mem ]]; then MEM="-m ${VM[mem]}" elif [[ $1 == smp ]]; then SMP="-smp ${VM[smp]}" elif [[ $1 == rtc ]]; then RTC="-rtc ${VM[rtc]}" elif [[ $1 == bootcd ]]; then BOOTCD="-cdrom ${VM[bootcd]} -boot once=d" elif [[ $1 == vnc ]]; then VNC="-vnc :${VM[vnc]}" elif [[ $1 == kvm ]]; then if [[ ${VM[kvm]} == yes ]]; then KVM="-enable-kvm" fi elif [[ $1 == log ]]; then if [[ ${VM[log]} == yes ]]; then LOG="-D $(get_rundir).log" fi elif [[ $1 == daemon ]]; then if [[ ${VM[daemon]} == yes ]]; then DAEMON='-daemonize' fi elif [[ $1 == secure ]]; then if [[ ${VM[secure]} == yes ]]; then rundir=$(get_rundir) SECURE="-runas nobody -daemonize -chroot $rundir" fi elif [[ $1 == serial ]]; then if [[ ${VM[serial]} == yes ]]; then SERIAL="-chardev socket,id=serial0,path=$(get_rundir).serial,server,nowait -serial chardev:serial0" fi elif [[ $1 == monitor ]]; then if [[ ${VM[monitor]} == yes ]]; then CONSOLE="-chardev socket,id=monitor,path=$(get_rundir).monitor,server,nowait -monitor chardev:monitor" fi fi } vms-0.2.1/src/usr/bin/vms0000755000000000000000000002227213341764426013737 0ustar rootroot#!/bin/bash # Copyright 2018 Nikos Giotis, Athens, GR # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # vms command sript VMS_LIB=/var/lib/vms vms_create() { name=$1 template=$2 if [ "$name" == "" ]; then echo 'Usage: vms create ' exit 1 fi vmdir="$HOME/.vms/$name" if [ -d "$vmdir" ]; then echo "$name already exists" exit 1 fi mkdir -p $vmdir vmsconf="$HOME/.vms/vms.conf" if [ ! -f $vmsconf ]; then echo '#!/bin/bash' >> $vmsconf fi vms_stub $name cp "$VMS_LIB/vm.sh" "$vmdir/$name.sh" if [ "$template" != "" ]; then echo "Using $template template" if [ ! -d "$VMS_LIB/templates/$template" ]; then echo "$template does not exist" exit 1 fi fi } vms_stub() { name=$1 vmsconf="$HOME/.vms/vms.conf" cat << EOF >> $vmsconf declare -A $name $name[name]='$name' $name[uuid]='$(uuidgen)' $name[arch]='$(uname -m)' EOF } . /usr/bin/vms-parse vms_info() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms info ' exit 1 fi info_VM $name } vms_conf() { name=$1; key=$2; value="$3" if [ "$name" == "" ] || [ "$key" == "" ] || [ "$value" == "" ]; then echo 'Usage: vms conf ' exit 1 fi valid_VM $name IFS=$'\n' # Find all the lines that start with $name[] lines=$(<"$HOME/.vms/vms.conf") keylines=() lastclean="" for l in $lines; do clean=$( echo $l | grep -v -E "^\s*#.*" ) if [ "$clean" != "" ] || [ "$clean" != "\n" ]; then if echo $clean | grep -E "^\s*$name\[.*].*" >/dev/null; then lastclean=$clean keyl=$( echo $clean | grep -E "^\s*$name\[$key].*" ) if [ "$keyl" != "" ]; then keylines+=($keyl) fi fi fi done if [ ${#keylines[@]} -gt 1 ]; then echo "Found more than one match and will exit!" for l in ${keylines[@]}; do echo $l; done exit 1 fi newline="$name\[$key]=$value" if [ "$keylines" != "" ]; then # Found existing $key, modify it oldline="${keylines/'['/'\['}" if [ "$value" == "--" ]; then # User requested delete required_keys="name uuid arch pid" if echo "$required_keys" | grep -w $key > /dev/null; then echo "You should not delete $key" else sed -i "/$oldline/d" ~/.vms/vms.conf echo "Deleted $keylines" fi else if [ "$oldline" == "$newline" ]; then echo "$keylines is already set" else sed -i "s|$oldline|$newline|1" ~/.vms/vms.conf echo "Modified $keylines -> ${newline/'\['/'['}" fi fi else # $key was not found, add a new one if [ "$value" == "--" ]; then echo "Can't find $key" else lastkey=${lastclean##*[} lastkey=${lastkey%]*} sed -i "/\s*$name\[$lastkey]/a $newline" ~/.vms/vms.conf echo "Added ${newline/'\['/'['}" fi fi } vms_status() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms status ' exit 1 fi status_VM $name if [ $? -eq 0 ]; then echo "$name is not running" fi } vms_list() { for f in $(ls $HOME/.vms/*/*.sh) ; do vm=$(basename "$f" | rev | cut -c 4- | rev ) echo -n $vm status=$( status_VM $vm ) if [ "$status" != "" ]; then echo -n " [R]" fi echo done } vms_start() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms start ' exit 1 fi if [ "$( secure_VM $name)" == "no" ]; then echo "vms start $name must be run as root via rc.vms" exit 1 fi vmdir="$HOME/.vms/$name" if [ -f "$vmdir/$name.sh" ]; then echo -n "starting $name ..." ret=$(bash "$vmdir/$name.sh") if [ "$ret" != "" ]; then echo " error!" echo $ret exit 1 else echo " done." fi else echo "$name does not exist" exit 1 fi } vms_stop() { name=$1 timeout=$2 if [ "$name" == "" ]; then echo 'Usage: vms status ' exit 1 fi pid=$(process_VM $name) if [ "$( secure_VM $name)" == "no" ]; then echo "vms stop $name must be run as root via rc.vms" exit 2 fi if [ "$pid" != "" ]; then echo -n "stopping $name ($pid) .." while ps -p "$pid" > /dev/null; do echo -n '.' monitor=$( rundir_VM $name ).monitor if [ ! -w $monitor ]; then echo "Use ${name}[monitor]=yes to send ACPI shutdown event" exit 1 fi total_time=0 echo 'system_powerdown' | socat "unix-connect:$monitor" stdin wait_time=0 while ps -p "$pid" > /dev/null && [ $wait_time -lt 50 ]; do sleep 1 ((wait_time++)) ((total_time++)) if [ "$timeout" != "" ]; then if [ $total_time -gt $timeout ]; then echo -n '.' vms_kill $name echo " killed after $timeout!" fi fi done done vms_clean_files echo " done." else echo "$name is not running" fi } vms_clean_files() { rundir=$( rundir_VM $name ) if [ "$rundir" != "" ] && [ -w "$rundir" ]; then rm -f "$rundir.monitor" rm -f "$rundir.serial" rm -f "$rundir.pid" rmdir "$rundir" fi } vms_kill() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms kill ' exit 1 fi vmdir="$HOME/.vms/$name" pid=$( process_VM $name ) if [ "$pid" != "" ]; then echo -n "killing $1 ... " kill $pid if [ $? -eq 0 ]; then echo 'done.' vms_clean_files else echo 'ERROR!' fi else echo "$name is not running" fi } vms_restart() { name=$1 timeout=$2 if [ "$name" == "" ]; then echo 'Usage: vms kill ' exit 1 fi vms_stop $name $timeout vms_start $name } vms_log() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms log ' exit 1 fi logfile="$( rundir_VM $name ).log" if [ -r "$logfile" ]; then tail "$logfile" else echo "can't access log" fi } vms_monitor() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms monitor ' exit 1 fi monitor="$( rundir_VM $name ).monitor" if [ -w "$monitor" ]; then unixterm "$monitor" else echo "Can't access $monitor" fi } vms_serial() { name=$1 if [ "$name" == "" ]; then echo 'Usage: vms serial ' exit 1 fi serial="$( rundir_VM $name ).serial" if [ -w "$serial" ]; then minicom -D "unix#$serial" else echo "Can't access serial" fi } vms_vnc() { name=$1; verbose=$2 if [ "$name" == "" ]; then echo 'Usage: vms vnc ' exit 1 fi vnc=$(vnc_VM $name) if [ "$vnc" != "" ]; then if [ "$verbose" == "-v" ]; then vncviewer :$vnc & else vncviewer :$vnc 1>/dev/null 2>&1 & fi else echo "$name does not have VNC server" fi } case "$1" in 'create') vms_create $2 $3 ;; 'list') vms_list ;; 'info') vms_info $2 ;; 'conf') vms_conf $2 $3 "$4" ;; 'status') vms_status $2 ;; 'start') vms_start $2 ;; 'kill') vms_kill $2 ;; 'stop') vms_stop $2 $3 ;; 'restart') vms_restart $2 $3 ;; 'log') vms_log $2 ;; 'monitor') vms_monitor $2 ;; 'serial') vms_serial $2 ;; 'vnc') vms_vnc $2 $3 ;; *) echo "Usage: vms create [vm_template] vms list vms info vms conf vms status vms start vms kill vms stop [timeout] vms restart [timeout] vms log vms monitor vms serial vms vnc [-v]" esac vms-0.2.1/README.html0000644000000000000000000002166613341764426012665 0ustar rootroot

vms

A command for running and managing qemu virtual machines

Description

vms is a command that creates, edits and manages qemu virtual machines. It lists, starts, stops and configures them. It also provides shortcuts to vnc, serial and qemu monitor consoles. It is small and being written in bash makes it easily customizable.

Each user has a configuration file ~/.vms/vms.conf. All the user's virtual machines are configured in there, using a very simple format. By editing this file the user controls the options that are passed to qemu.

It has minimal dependencies, bash and qemu are needed for most of the functionality. vms stop uses socat, vms monitor uses unixterm, vms serial uses minicom and vms vnc needs vncviewer.

An init script rc.vms is also provided with a simple mechanism for managing all the system's virtual machines. It can also be used during the host's boot sequence to start the machines defined by the administrator in rc.vms.conf.

As a bonus two scripts are provided, pci-stub-bind and vfio-bind to ease the pain when using pci passthrough.

Prebuild packages

slackware vms-0.2.1-noarch-1did.tgz

Latest source release

vms-0.2.1.tar.gz

Latest manuals (master)

vms(1), vms.conf(5), rc.vms(8), rc.vms.conf(5), vms-tutorial(7)

Basic usage example

Show vms usage summary

vms

Create a virtual machine named vm1

vms create vm1
qemu-img create -f qcow2 ~/.vms/vm1/disk.img 20G`

Configure vm1

vms conf vm1 mem 1024
vms conf vm1 smp 2
vms conf vm1 disk0 '~/.vms/vm1/disk.img'
vms conf vm1 bootcd '"$APATH/to/install-dvd-iso"'

or, edit ~/.vms/vms.conf to configure vm1 like this

# See /usr/share/vms/vms.conf.example
vm1[arch]=x86_64
vm1[mem]=1024
vm1[smp]=2
vm1[disk0]=~/.vms/vm1/disk.img
vm1[bootcd]="$APATH/to/install-dvd.iso"

List the user's virtual machines, start vm1 and display it's status

vms list
vms start vm1
vms status vm1

Stop vm1 (via ACPI command), optionally with a timeout of 10 seconds

vms stop vm1
vms stop vm1 10

Kill vm1 virtual machine

vms kill vm1

If vm1 is configured with monitor, serial, vnc or log, the following can be used to access them

vms vnc vm1
vms monitor vm1
vms serial vm1
vms log vm1

Concepts

The general idea is to have a directory with a bash script for each virtual machine. All these directories are stored per user inside ~/.vms directory.

For each user there is a ~/.vms/vms.conf file that contains all the configuration for all the user's virtual machines. The configuration for each virtual machine is kept as one bash associative array, declared in the user's vms.conf file. The system has a very simple parser that matches keys of this array to generate the qemu command line options for most commonly used options, such as cpu, disk#, nic#, mem, etc. Raw command line options are also supported, as well as providing the option to totally bypass the parser and use a custom bash script that calls qemu bypassing the whole system.

A typical ~/.vms directory looks like this

~/.vms
~/.vms/vms.conf
~/.vms/vm1/vm1.sh
~/.vms/vm1/disk1.img
~/.vms/vm2/vm2.sh
~/.vms/vm2/....

For each virtual machine there is a directory under ~/.vms, eg. for vm1 there is a directory named ~/.vms/vm1. This can be used to store files such as disk image files and bios files related to vm1, although this is optional. The only required file is the script ~/vms/vm1/vm1.sh.

The actual qemu call is done in ~/.vms/vm1/vm1.sh. This file is copied from /var/lib/vms/vm.sh when creating vm1 with `vms create vm1`. This could be edited if needed or totally replaced by a custom script. The suggested way is to configure vm1 by editing the appropriate section in vms.conf, either by hand using your favorite editor or with vms conf commands.

The section of vm1 in ~/.vms/vms.conf looks like this.

declare -A vm1
vm1[name]='vm1'
vm1[uuid]='ffffffff-ffff-ffff-ffff-ffffffffffff'
vm1[arch]='x86_64'
vm1[kvm]=yes
vm1[cpu]=host
vm1[smp]=2
vm1[mem]=1024
vm1[...

name, uuid and arch are needed by vms for each virtual machine. vms identifies the qemu process by the uuid, so no virtual machine can be started twice.

This a bash associative array that holds all the configuration for vm1. See /usr/share/vms/vms.conf.example for all the available options.

Administration

An init script rc.vms is provided is used to launch a set of virtual machines during boot. Assuming the host keeps this init script in /etc/rc.d/, the root user can use the following line with the host's init system to start the virtual machines defined in rc.vms.conf.

/etc/rc.d/rc.vms start

Accordingly, one can use the following to restart and stop the machines in the set.

/etc/rc.d/rc.vms restart
/etc/rc.d/rc.vms stop

The following diplays the status of the machines.

/etc/rc.d/rc.vms status

Also, rc.vms can be used to call any vms command as any user. Assuming the user joe has a machine named vm1, the root user can use this script like this to display information about vm1

/etc/rc.d/rc.vms cmd joe info vm1

Accordingly root can start, stop and restart vm1 like this

/etc/rc.d/rc.vms cmd joe start vm1
/etc/rc.d/rc.vms cmd joe stop vm1
/etc/rc.d/rc.vms cmd joe restart vm1

When launching the vm1 machine with the following line in ~/.vms/vms.conf

vm1[secure]=yes

then only the root user can launch vm1, since root privileges are needed to chroot and run as nobody. If this is not set, rc.vms will start the qemu process as the normal user joe.

/etc/rc.d/rc.vms cmd joe start vm1

Directories & files

  • user configuration

    ~/.vms/vms.conf

  • user configuration example

    /usr/share/vms/vms.conf.example

  • template scripts for vm creation

    /var/lib/vms/

    /var/lib/vms/vm.sh

  • vms command and parser scripts

    /usr/bin/vms

    /usr/bin/vms-parse

  • helpers for pci passthrough

    /usr/sbin/vfio-bind

    /usr/sbin/pci-stub-bind

  • init script

    /etc/rc.d/rc.vms

  • init script configuration

    /etc/rc.d/rc.vms.conf

vms-0.2.1/doc/0000755000000000000000000000000013341764426011574 5ustar rootrootvms-0.2.1/doc/vms-HOW-TO0000644000000000000000000000427613341764426013310 0ustar rootroot====== vms ====== An example using vms for creating and managing a qemu virtual machine ===== Installation ===== You need to install vde2, tigervnc and qemu first Get the ready made package, you should use the latest release wget https://bitbucket.org/yotis/vms/vms-0.2.0-noarch-1did.tgz Install or upgrade vms with upgradepkg --install-new vms-0.2.0-noarch-1did.tgz ===== Creating vm1 ===== Create the vm1 virtual machine and show the related configuration and files vms create vm1 vms list grep vm1 ~/.vms/vms.conf ls ~/.vms/vm1 You can use the ~/.vms/vm1 directory to store anything you want, but this is not mandatory. The only thing that is needed is the ~/.vms/vm1.sh script. To show the configuration for the vm1 virtual machine, use this vms info vm1 You should be able to start vm1 now with vms start vm1 To display the running status of vm1 use this vms status vm1 If you want to kill vm1, you can do it like this vms kill vm1 Now, add 2GB of memory vms conf vm1 mem 2048 Let's create a 20G disk and attach it to vm1 cd ~/.vms/vm1 qemu-img create -f qcow2 disk0.img 20G vms conf vm1 disk0 '~/.vms/vm1/disk0.img' And now, let's add a cdrom and boot from it. If there is a slackware install dvd located in ~/os vms conf vm1 bootcd ~/os/slackware64-14.2-install-dvd.iso vms info vm1 Even though you can edit vm1's configuration via vms conf commands, you are encouraged to edit ~/.vms/vms.conf by hand. The format is very simple and since this file is sourced during vms execution you can be creative with bash variables. For example, you could configure shared storage for the os images by declaring a variable at the beginning of ~/.vms/vms.conf. ISOS=/path/to/isos Then you would use the ISOS variable via 'vms conf' like this vms conf vm1 bootcd '"$ISOS/slackware64-14.2-install-dvd.iso"' Notice the use of single and double quotes. ===== Sources ===== * Nikos Giotis {{tag>vms qemu}} https://docs.slackware.com/howtos:emulators:vms-HOW-TOvms-0.2.1/doc/prepare_docs.sh0000644000000000000000000000100713341764426014574 0ustar rootroot#!/bin/bash from_version=$1 to_version=$2 if [ "$from_version" != "" -a "$to_version" == "" ]; then echo "Both versions are needed" exit 1 fi if [ "$from_version" != "" -a "$to_version" != "" ]; then for md in $( ls man/man?/*.md ); do sed -i -e "s/$from_version/$to_version/g" $md done fi #for f in $( find . * -type f ); do grep '0.1.2' $f; done |less cd .. pandoc README.md -s -t html > README.html cd doc for md in $( ls man/man?/*.md ); do pandoc $md -s -t man > ${md::-3} done vms-0.2.1/doc/man/0000755000000000000000000000000013341764426012347 5ustar rootrootvms-0.2.1/doc/man/man5/0000755000000000000000000000000013341764426013207 5ustar rootrootvms-0.2.1/doc/man/man5/vms.conf.5.md0000644000000000000000000001034013341764426015423 0ustar rootroot% VMS.CONF(5) vms 0.2.1 | ~/.vms/vms.conf file format % Nikos Giotis % 27 August 2018 NAME ==== **vms.conf** - **vms** per user configuration file format SYNOPSIS ======== The **vms.conf** is a per user configuration file that is located at **~/.vms/vms.conf**. It is used by the **vms** command. It stores **bash** associative arrays, one for each virtual machine. DESCRIPTION =========== An example **vms.conf** is located at **/usr/share/vms/vms.conf.example**. A typical **vms.conf** can be like this #!/bin/bash VMSTORE=/path/to/directory declare -A avm avm[name]=avm avm[uuid]='xxxxxxxx-ffff-ffff-ffff-ffffffffffff' avm[arch]=x86_64 avm[mem]=2048 avm[smp]=2 avm[disk0]="$VMSTORE/avm-system.img" avm[bootcd]="$VMSTORE/install-dvd.iso" # declare -A bvm # bvm[name]=bvm # bvm[... A set of predefined keys are supported by a very simple parser (**vms-parse**). The parser uses the value for the key in the array to compose an option for qemu. For example, for the following line bvm[br0]='net0,br=br1' the parser will compose this qemu option -netdev bridge,id=net0,br=br1 The keys **name**, **uuid** and **arch** are required for each virtual machine. Some keys can be numbered, like **disk0**, **disk1**, **nic0**, **nic1**, etc. These are referred as **disk#** and **nic#**. Some keys are boolean, these can be set to _yes_ or _no_. The configuration can also be edited with **vms conf**. REQUIRED KEYS ============= name : The name of the virtual machine uuid : A uuid for the virtual machine, see uuidgen(1) arch : The virtual machine architecture, eg. x86_64, arm SUPPORTED KEYS ============== disk# : A path to a disk to attach to the virtual machine vde# : A VDE network device br# : A bridge network device nic# : A network interface device extra# : Raw qemu command line options cpu : The qemu cpu type mem : The amount of virtual machine memory smp : SMP configuration for the virtual machine rtc : The virtual machine's RTC configuration bootcd : A path to an disk.iso vnc : The VNC number to use for qemu's VNC console kvm : Enable KVM, boolean log : Enable logging, boolean serial : Enable serial console, boolean monitor : Enable monitor console, boolean daemon : Run qemu as a daemon, boolean secure : Run qemu as a daemon, as user nobody inside an empty chroot, boolean EXAMPLE ======= Expanding upon the avm example from above, declare the _bvm_ virtual machine. Let's attach the _bvm[disk0]_ to _virtio_. declare -A bvm bvm[name]=bvm bvm[uuid]='xxxxxxxx-ffff-ffff-ffff-ffffffffffff' bvm[arch]=x86_64 bvm[mem]=2048 bvm[smp]=2 bvm[bootcd]="$VMSTORE/install-dvd.iso" bvm[disk0]="$VMSTORE/bvm-system.img,if=virtio,index=0" Enable KVM and configure the guest cpu. Notice that for some options like **cpu**, anything can be passed to qemu, like the _-M q35_. See **vms-parse** for more details. Alternatively, the same can be done by using the **extra#** keys. bvm[kvm]=yes bvm[cpu]='host -M q35' ## Or comment the above and use the next line to emulate a specific ## Intel model with kvm disabled on the guest, overriding the cpu ## vendor for the guest, even when qemu is running on an AMD host. #bvm[cpu]='Penryn,kvm=off,vendor=GenuineIntel' Connect to two network bridges on the host. One with a _virtio-net-pci_ interface and the other with an _e1000_ on the guest. bvm[br0]=net0 bvm[nic0]='virtio-net-pci,mac=52:54:00:XX:XX:XX,netdev=net0' bvm[br1]='net1,br=br1' bvm[nic1]='e1000,mac=52:54:00:XX:XX:XX,netdev=net1' Connect to two VDE switches running on the host. bvm[vde0]=net2 bvm[nic2]='virtio-net-pci,mac=52:54:00:XX:XX:XX,netdev=net2' bvm[vde1]=net3,sock=/path/to/vde.sock bvm[nic3]='e1000,mac=52:54:00:XX:XX:XX,netdev=net3' Start VNC server and run as a daemon bvm[vnc]=7 bvm[daemon]=yes Now, one can start _bvm_ and display it's status by using $ vms start bvm $ vms status bvm Assuming the user that owns _bvm_ is called _joe_, _bvm_ can be configured to start during the host's boot sequence like this # echo 'joe bvm' >> /etc/rc.d/rc.vms.conf SEE ALSO ======== **vms(1)**vms-0.2.1/doc/man/man5/rc.vms.conf.5.md0000644000000000000000000000141113341764426016025 0ustar rootroot% RC.VMS.CONF(5) vms 0.2.1 | rc.vms.conf configuration file % Nikos Giotis % 28 August 2018 NAME ==== **rc.vms.conf** - **rc.vms** configuration file DESCRIPTION =========== The **rc.vms.conf** defines a set of virtual machines. Almost all the options passed to the **rc.vms** are operations to be done on this set. Each machine is specified with one line like this username virtual_machine Lines starting with '#' are comments EXAMPLE ======= Assume user _sam_ has the virtual machines named _vm01_ and _vm02_ and the administrator wants to start them during the host's boot by calling \`rc.vms start\`. An example **rc.vms.conf** to do this would be like this. # rc.vms.conf sam vm01 sam vm02 SEE ALSO ======== rc.vms(8) vms-0.2.1/doc/man/man5/vms.conf.50000644000000000000000000001161613341764426015033 0ustar rootroot.\" Automatically generated by Pandoc 1.17.0.3 .\" .TH "VMS.CONF" "5" "27 August 2018" "vms 0.2.1" "~/.vms/vms.conf file format" .hy .SH NAME .PP \f[B]vms.conf\f[] \- \f[B]vms\f[] per user configuration file format .SH SYNOPSIS .PP The \f[B]vms.conf\f[] is a per user configuration file that is located at \f[B]~/.vms/vms.conf\f[]. It is used by the \f[B]vms\f[] command. It stores \f[B]bash\f[] associative arrays, one for each virtual machine. .SH DESCRIPTION .PP An example \f[B]vms.conf\f[] is located at \f[B]/usr/share/vms/vms.conf.example\f[]. A typical \f[B]vms.conf\f[] can be like this .IP .nf \f[C] #!/bin/bash VMSTORE=/path/to/directory declare\ \-A\ avm avm[name]=avm avm[uuid]=\[aq]xxxxxxxx\-ffff\-ffff\-ffff\-ffffffffffff\[aq] avm[arch]=x86_64 avm[mem]=2048 avm[smp]=2 avm[disk0]="$VMSTORE/avm\-system.img" avm[bootcd]="$VMSTORE/install\-dvd.iso" #\ declare\ \-A\ bvm #\ bvm[name]=bvm #\ bvm[... \f[] .fi .PP A set of predefined keys are supported by a very simple parser (\f[B]vms\-parse\f[]). The parser uses the value for the key in the array to compose an option for qemu. For example, for the following line .IP .nf \f[C] bvm[br0]=\[aq]net0,br=br1\[aq] \f[] .fi .PP the parser will compose this qemu option .IP .nf \f[C] \-netdev\ bridge,id=net0,br=br1 \f[] .fi .PP The keys \f[B]name\f[], \f[B]uuid\f[] and \f[B]arch\f[] are required for each virtual machine. Some keys can be numbered, like \f[B]disk0\f[], \f[B]disk1\f[], \f[B]nic0\f[], \f[B]nic1\f[], etc. These are referred as \f[B]disk#\f[] and \f[B]nic#\f[]. Some keys are boolean, these can be set to \f[I]yes\f[] or \f[I]no\f[]. The configuration can also be edited with \f[B]vms conf\f[]. .SH REQUIRED KEYS .TP .B name The name of the virtual machine .RS .RE .TP .B uuid A uuid for the virtual machine, see uuidgen(1) .RS .RE .TP .B arch The virtual machine architecture, eg. x86_64, arm .RS .RE .SH SUPPORTED KEYS .TP .B disk# A path to a disk to attach to the virtual machine .RS .RE .TP .B vde# A VDE network device .RS .RE .TP .B br# A bridge network device .RS .RE .TP .B nic# A network interface device .RS .RE .TP .B extra# Raw qemu command line options .RS .RE .TP .B cpu The qemu cpu type .RS .RE .TP .B mem The amount of virtual machine memory .RS .RE .TP .B smp SMP configuration for the virtual machine .RS .RE .TP .B rtc The virtual machine\[aq]s RTC configuration .RS .RE .TP .B bootcd A path to an disk.iso .RS .RE .TP .B vnc The VNC number to use for qemu\[aq]s VNC console .RS .RE .TP .B kvm Enable KVM, boolean .RS .RE .TP .B log Enable logging, boolean .RS .RE .TP .B serial Enable serial console, boolean .RS .RE .TP .B monitor Enable monitor console, boolean .RS .RE .TP .B daemon Run qemu as a daemon, boolean .RS .RE .TP .B secure Run qemu as a daemon, as user nobody inside an empty chroot, boolean .RS .RE .SH EXAMPLE .PP Expanding upon the avm example from above, declare the \f[I]bvm\f[] virtual machine. Let\[aq]s attach the \f[I]bvm[disk0]\f[] to \f[I]virtio\f[]. .IP .nf \f[C] declare\ \-A\ bvm bvm[name]=bvm bvm[uuid]=\[aq]xxxxxxxx\-ffff\-ffff\-ffff\-ffffffffffff\[aq] bvm[arch]=x86_64 bvm[mem]=2048 bvm[smp]=2 bvm[bootcd]="$VMSTORE/install\-dvd.iso" bvm[disk0]="$VMSTORE/bvm\-system.img,if=virtio,index=0" \f[] .fi .PP Enable KVM and configure the guest cpu. Notice that for some options like \f[B]cpu\f[], anything can be passed to qemu, like the \f[I]\-M q35\f[]. See \f[B]vms\-parse\f[] for more details. Alternatively, the same can be done by using the \f[B]extra#\f[] keys. .IP .nf \f[C] bvm[kvm]=yes bvm[cpu]=\[aq]host\ \-M\ q35\[aq] ##\ Or\ comment\ the\ above\ and\ use\ the\ next\ line\ to\ emulate\ a\ specific ##\ Intel\ model\ with\ kvm\ disabled\ on\ the\ guest,\ overriding\ the\ cpu ##\ vendor\ for\ the\ guest,\ even\ when\ qemu\ is\ running\ on\ an\ AMD\ host. #bvm[cpu]=\[aq]Penryn,kvm=off,vendor=GenuineIntel\[aq] \f[] .fi .PP Connect to two network bridges on the host. One with a \f[I]virtio\-net\-pci\f[] interface and the other with an \f[I]e1000\f[] on the guest. .IP .nf \f[C] bvm[br0]=net0 bvm[nic0]=\[aq]virtio\-net\-pci,mac=52:54:00:XX:XX:XX,netdev=net0\[aq] bvm[br1]=\[aq]net1,br=br1\[aq] bvm[nic1]=\[aq]e1000,mac=52:54:00:XX:XX:XX,netdev=net1\[aq] \f[] .fi .PP Connect to two VDE switches running on the host. .IP .nf \f[C] bvm[vde0]=net2 bvm[nic2]=\[aq]virtio\-net\-pci,mac=52:54:00:XX:XX:XX,netdev=net2\[aq] bvm[vde1]=net3,sock=/path/to/vde.sock bvm[nic3]=\[aq]e1000,mac=52:54:00:XX:XX:XX,netdev=net3\[aq] \f[] .fi .PP Start VNC server and run as a daemon .IP .nf \f[C] bvm[vnc]=7 bvm[daemon]=yes \f[] .fi .PP Now, one can start \f[I]bvm\f[] and display it\[aq]s status by using .IP .nf \f[C] $\ vms\ start\ bvm $\ vms\ status\ bvm \f[] .fi .PP Assuming the user that owns \f[I]bvm\f[] is called \f[I]joe\f[], \f[I]bvm\f[] can be configured to start during the host\[aq]s boot sequence like this .IP .nf \f[C] #\ echo\ \[aq]joe\ bvm\[aq]\ >>\ /etc/rc.d/rc.vms.conf \f[] .fi .SH SEE ALSO .PP \f[B]vms(1)\f[] .SH AUTHORS Nikos Giotis . vms-0.2.1/doc/man/man5/rc.vms.conf.50000644000000000000000000000164413341764426015436 0ustar rootroot.\" Automatically generated by Pandoc 1.17.0.3 .\" .TH "RC.VMS.CONF" "5" "28 August 2018" "vms 0.2.1" "rc.vms.conf configuration file" .hy .SH NAME .PP \f[B]rc.vms.conf\f[] \- \f[B]rc.vms\f[] configuration file .SH DESCRIPTION .PP The \f[B]rc.vms.conf\f[] defines a set of virtual machines. Almost all the options passed to the \f[B]rc.vms\f[] are operations to be done on this set. Each machine is specified with one line like this .IP .nf \f[C] \ username\ virtual_machine \f[] .fi .PP Lines starting with \[aq]#\[aq] are comments .SH EXAMPLE .PP Assume user \f[I]sam\f[] has the virtual machines named \f[I]vm01\f[] and \f[I]vm02\f[] and the administrator wants to start them during the host\[aq]s boot by calling `rc.vms start`. An example \f[B]rc.vms.conf\f[] to do this would be like this. .IP .nf \f[C] #\ rc.vms.conf sam\ vm01 sam\ vm02 \f[] .fi .SH SEE ALSO .PP rc.vms(8) .SH AUTHORS Nikos Giotis . vms-0.2.1/doc/man/man1/0000755000000000000000000000000013341764426013203 5ustar rootrootvms-0.2.1/doc/man/man1/vms.1.md0000644000000000000000000000514113341764426014472 0ustar rootroot% VMS(1) vms 0.2.1 | vms command manual % Nikos Giotis % 28 August 2018 NAME ==== **vms** - a command for managing and creating virtual machines SYNOPSIS ======== **vms** [_option_] DESCRIPTION =========== The **vms** command is used for creating and managing qemu virtual machines. The configuration for all the user's virtual machines is stored under the **~/.vms** directory. There is a per user configuration file **~/.vms/vms.conf** that stores the settings for all the user's virtual machines. See **vms.conf(5)** for more information about virtual machine configuration. OPTIONS ======= list : List the current user's virtual machines create _vm_ : Create a virtual machine named _vm_ info _vm_ : Display the configuration of _vm_ as defined in ~/.vms/vms.conf conf _vm_ _key_ _value_ : Edit the configuration of _vm_ in ~/.vms/vms.conf. Add a new line or modify an existing line to this _vm[key]=value_. Use this syntax \`vms conf vm key '"value"'\` to create this line _vm[key]="value"_. The special _value_ -- can be used to delete the _key_ line. status _vm_ : Display the running status of _vm_ start _vm_ : Start the virtual machine named _vm_ stop _vm_ [_timeout_] : Stop the _vm_ virtual machine by sending it an ACPI system shutdown event restart _vm_ [_timeout_] : Restart _vm_ by calling **stop** and **start** kill _vm_ : Forcibly kill the qemu process for _vm_ vnc _vm_ [**-v**] : Connect to the VNC console, if _vm_ is configured with one. If **-v** is specified, the stdout of vncviewer is shown serial _vm_ : Connect to the serial console, if _vm_ is configured with one monitor _vm_ : Connect to the qemu monitor console, if _vm_ is configured with one log _vm_ : Show the _vm_'s log, if _vm_ is configured with one EXAMPLES ======== As a normal user, create a virtual machine named _bvm_ vms create bvm Edit **~/.vms/vms.conf**. See the example in **vms.conf(5)**. Additionaly, the **conf** option can be used like this vms conf bvm mem 2048 vms conf bvm smp 2 vms conf bvm disk0 ~/.vms/bvm/disk0.img vms conf bvm bootcd '"$VAR_IN_VMS_CONF/install-dvd.iso"' Any key can be deleted like this vms conf bvm bootcd -- Show information about _bvm_ and it's running status vms info bvm vms status bvm To start, stop or kill _bvm_ vms start bvm vms stop bvm vms kill bvm To connect to the qemu monitor or VNC server, if these are configured vms monitor bvm vms vnc bvm DEDICATION ========== Gb Z. gb lbh, zl ybir SEE ALSO ======== vms.conf(5), rc.vms(8), vms-tutorial(7) vms-0.2.1/doc/man/man1/vms.10000644000000000000000000000640113341764426014073 0ustar rootroot.\" Automatically generated by Pandoc 1.17.0.3 .\" .TH "VMS" "1" "28 August 2018" "vms 0.2.1" "vms command manual" .hy .SH NAME .PP \f[B]vms\f[] \- a command for managing and creating virtual machines .SH SYNOPSIS .PP \f[B]vms\f[] [\f[I]option\f[]] .SH DESCRIPTION .PP The \f[B]vms\f[] command is used for creating and managing qemu virtual machines. The configuration for all the user\[aq]s virtual machines is stored under the \f[B]~/.vms\f[] directory. There is a per user configuration file \f[B]~/.vms/vms.conf\f[] that stores the settings for all the user\[aq]s virtual machines. See \f[B]vms.conf(5)\f[] for more information about virtual machine configuration. .SH OPTIONS .TP .B list List the current user\[aq]s virtual machines .RS .RE .TP .B create \f[I]vm\f[] Create a virtual machine named \f[I]vm\f[] .RS .RE .TP .B info \f[I]vm\f[] Display the configuration of \f[I]vm\f[] as defined in ~/.vms/vms.conf .RS .RE .TP .B conf \f[I]vm\f[] \f[I]key\f[] \f[I]value\f[] Edit the configuration of \f[I]vm\f[] in ~/.vms/vms.conf. Add a new line or modify an existing line to this \f[I]vm[key]=value\f[]. Use this syntax `vms conf vm key \[aq]"value"\[aq]` to create this line \f[I]vm[key]="value"\f[]. The special \f[I]value\f[] \-\- can be used to delete the \f[I]key\f[] line. .RS .RE .TP .B status \f[I]vm\f[] Display the running status of \f[I]vm\f[] .RS .RE .TP .B start \f[I]vm\f[] Start the virtual machine named \f[I]vm\f[] .RS .RE .TP .B stop \f[I]vm\f[] [\f[I]timeout\f[]] Stop the \f[I]vm\f[] virtual machine by sending it an ACPI system shutdown event .RS .RE .TP .B restart \f[I]vm\f[] [\f[I]timeout\f[]] Restart \f[I]vm\f[] by calling \f[B]stop\f[] and \f[B]start\f[] .RS .RE .TP .B kill \f[I]vm\f[] Forcibly kill the qemu process for \f[I]vm\f[] .RS .RE .TP .B vnc \f[I]vm\f[] [\f[B]\-v\f[]] Connect to the VNC console, if \f[I]vm\f[] is configured with one. If \f[B]\-v\f[] is specified, the stdout of vncviewer is shown .RS .RE .TP .B serial \f[I]vm\f[] Connect to the serial console, if \f[I]vm\f[] is configured with one .RS .RE .TP .B monitor \f[I]vm\f[] Connect to the qemu monitor console, if \f[I]vm\f[] is configured with one .RS .RE .TP .B log \f[I]vm\f[] Show the \f[I]vm\f[]\[aq]s log, if \f[I]vm\f[] is configured with one .RS .RE .SH EXAMPLES .PP As a normal user, create a virtual machine named \f[I]bvm\f[] .IP .nf \f[C] vms\ create\ bvm \f[] .fi .PP Edit \f[B]~/.vms/vms.conf\f[]. See the example in \f[B]vms.conf(5)\f[]. Additionaly, the \f[B]conf\f[] option can be used like this .IP .nf \f[C] vms\ conf\ bvm\ mem\ 2048 vms\ conf\ bvm\ smp\ 2 vms\ conf\ bvm\ disk0\ ~/.vms/bvm/disk0.img vms\ conf\ bvm\ bootcd\ \[aq]"$VAR_IN_VMS_CONF/install\-dvd.iso"\[aq] \f[] .fi .PP Any key can be deleted like this .IP .nf \f[C] vms\ conf\ bvm\ bootcd\ \-\- \f[] .fi .PP Show information about \f[I]bvm\f[] and it\[aq]s running status .IP .nf \f[C] vms\ info\ bvm vms\ status\ bvm \f[] .fi .PP To start, stop or kill \f[I]bvm\f[] .IP .nf \f[C] vms\ start\ bvm vms\ stop\ bvm vms\ kill\ bvm \f[] .fi .PP To connect to the qemu monitor or VNC server, if these are configured .IP .nf \f[C] vms\ monitor\ bvm vms\ vnc\ bvm \f[] .fi .SH DEDICATION .IP .nf \f[C] Gb\ Z. gb\ lbh,\ zl\ ybir \f[] .fi .SH SEE ALSO .PP vms.conf(5), rc.vms(8), vms\-tutorial(7) .SH AUTHORS Nikos Giotis . vms-0.2.1/doc/man/man8/0000755000000000000000000000000013341764426013212 5ustar rootrootvms-0.2.1/doc/man/man8/rc.vms.80000644000000000000000000000445713341764426014525 0ustar rootroot.\" Automatically generated by Pandoc 1.17.0.3 .\" .TH "RC.VMS" "8" "28 August 2018" "vms 0.2.1" "rc.vms init script manual" .hy .SH NAME .PP \f[B]rc.vms\f[] \- an init script to use with \f[B]vms\f[] .SH SYNOPSIS .PP \f[B]rc.vms\f[] [\f[I]option\f[]] .SH DESCRIPTION .PP The \f[B]rc.vms\f[] script is to be used by the administrator. It can be used for controlling a set of virtual machines. This set is specified in \f[B]rc.vms.conf\f[] configuration file. It can also be used to start and stop this set during the host\[aq]s boot and shutdown sequence. The \f[B]cmd\f[] option can be used by the administrator to control any virtual machine on the host. .SH OPTIONS .TP .B status display the running status of all the virtual machines in the set .RS .RE .TP .B start start the virtual machine set, can be used during host\[aq]s boot sequence. The machines in the set are started in the order that they appear in \f[B]rc.vms.conf\f[] .RS .RE .TP .B stop Stop the virtual machine set, can be used during host\[aq]s shutdown sequence. The order the machines are stopped is the reverse of the order that they appear in \f[B]rc.vms.conf\f[] .RS .RE .TP .B restart Restart the virtual machine set .RS .RE .TP .B cmd \f[I]username\f[] \f[I]vms\-option\f[] [\f[I]vm\f[]] Call `\f[B]vms\f[] \f[I]vms\-option\f[] \f[I]vm\f[]` to control the virtual machine named \f[I]vm\f[] that belongs to the user \f[I]username\f[]. It can be used on any virtual machine on the host, even if the virtual machine is not included in the set define in \f[B]rc.vms.conf\f[]. .RS .RE .SH EXAMPLES .PP Enable .PP To display the status of the set and start it .IP .nf \f[C] rc.vms\ status rc.vms\ start \f[] .fi .PP To stop the set, use .IP .nf \f[C] rc.vms\ stop \f[] .fi .PP Assume user \f[I]sam\f[] has a virtual machine named \f[I]vm01\f[]. The administrator can display the information about \f[I]vm01\f[] like this .IP .nf \f[C] rc.vms\ cmd\ sam\ list rc.vms\ cmd\ sam\ info\ vm01 \f[] .fi .PP This results in calling /\f[C]vms\ info\ vm01/\f[] to the \f[I]vm01\f[] that \f[I]sam\f[] has defined in his \f[B]~/.vms/vms.conf\f[]. Likewise, all \f[B]vms\f[] options can be used, eg .IP .nf \f[C] rc.vms\ cmd\ sam\ status\ vm01 rc.cms\ cmd\ sam\ start\ vm01 \f[] .fi .SH SEE ALSO .PP \f[B]vms(1)\f[], \f[B]rc.vms.conf(5)\f[] .SH AUTHORS Nikos Giotis . vms-0.2.1/doc/man/man8/rc.vms.8.md0000644000000000000000000000367413341764426015124 0ustar rootroot% RC.VMS(8) vms 0.2.1 | rc.vms init script manual % Nikos Giotis % 28 August 2018 NAME ==== **rc.vms** - an init script to use with **vms** SYNOPSIS ======== **rc.vms** [_option_] DESCRIPTION =========== The **rc.vms** script is to be used by the administrator. It can be used for controlling a set of virtual machines. This set is specified in **rc.vms.conf** configuration file. It can also be used to start and stop this set during the host's boot and shutdown sequence. The **cmd** option can be used by the administrator to control any virtual machine on the host. OPTIONS ======= status : display the running status of all the virtual machines in the set start : start the virtual machine set, can be used during host's boot sequence. The machines in the set are started in the order that they appear in **rc.vms.conf** stop : Stop the virtual machine set, can be used during host's shutdown sequence. The order the machines are stopped is the reverse of the order that they appear in **rc.vms.conf** restart : Restart the virtual machine set cmd _username_ _vms-option_ [_vm_] : Call \`**vms** _vms-option_ _vm_\` to control the virtual machine named _vm_ that belongs to the user _username_. It can be used on any virtual machine on the host, even if the virtual machine is not included in the set define in **rc.vms.conf**. EXAMPLES ======== Enable To display the status of the set and start it rc.vms status rc.vms start To stop the set, use rc.vms stop Assume user _sam_ has a virtual machine named _vm01_. The administrator can display the information about _vm01_ like this rc.vms cmd sam list rc.vms cmd sam info vm01 This results in calling /`vms info vm01/` to the _vm01_ that _sam_ has defined in his **~/.vms/vms.conf**. Likewise, all **vms** options can be used, eg rc.vms cmd sam status vm01 rc.cms cmd sam start vm01 SEE ALSO ======== **vms(1)**, **rc.vms.conf(5)** vms-0.2.1/doc/man/man7/0000755000000000000000000000000013341764426013211 5ustar rootrootvms-0.2.1/doc/man/man7/vms-tutorial.70000644000000000000000000000406013341764426015747 0ustar rootroot.\" Automatically generated by Pandoc 1.17.0.3 .\" .TH "VMS\-TUTORIAL" "7" "28 August 2018" "vms 0.2.1" "vms tutorial" .hy .PP Create the virtual machine named vm1 .IP .nf \f[C] vms\ create\ vm1 vms\ list \f[] .fi .PP You can go ahead and test your vm .IP .nf \f[C] vms\ info\ vm1 vms\ start\ vm1 \f[] .fi .PP if you want to kill the qemu process, use .IP .nf \f[C] vms\ kill\ vm1 \f[] .fi .PP Use 2 cores, change the cpu type and enable kvm .IP .nf \f[C] vms\ conf\ vm1\ smp\ 2 vms\ conf\ vm1\ cpu\ host vms\ conf\ vm1\ kvm\ yes \f[] .fi .PP To delete a key use the following syntax .IP .nf \f[C] vms\ conf\ vm1\ cpu\ \-\- vms\ conf\ vm1\ kvm\ \-\- \f[] .fi .PP To use 2 GB of memory .IP .nf \f[C] vms\ conf\ vm1\ mem\ 2048 \f[] .fi .PP Now, let\[aq]s create a disk image file .IP .nf \f[C] qemu\-img\ create\ \-f\ qcow2\ ~/.vms/vm1/disk.img\ 20G \f[] .fi .PP And attach it to vm1 .IP .nf \f[C] vms\ conf\ vm1\ disk0\ \[aq]~/.vms/vm1/disk.img\[aq] \f[] .fi .PP If you want, set vm1 to run as a daemon and add a VNC console to it .IP .nf \f[C] vms\ conf\ vm1\ daemon\ yes vms\ conf\ vm1\ vnc\ 7 \f[] .fi .PP You can always edit the \f[B]~/.vms/vms.conf\f[] file with your favorite an editor. .PP Now, start vm1 .IP .nf \f[C] vms\ start\ vm1 \f[] .fi .PP If you started with vnc, connect to it like this .IP .nf \f[C] vms\ vnc\ vm1 \f[] .fi .PP If you try to stop vm1 now with .IP .nf \f[C] vms\ stop\ vm1 \f[] .fi .PP You will notice it will not stop, it needs a proper os installed handle the ACPI virtual button press and vm1[monitor]=yes You can always kill vm1 with .IP .nf \f[C] vms\ kill\ vm1 \f[] .fi .PP Now, attach a cdrom and insert an .iso disk image to boot from .IP .nf \f[C] vms\ conf\ vm1\ bootcd\ \[aq]~/.vms/os/slackware64\-14.2\-install\-dvd.iso\[aq] \f[] .fi .PP Start the vm and install the operating system .IP .nf \f[C] vms\ start\ vm1 \f[] .fi .PP Again, if you started with vnc, connect to it with .IP .nf \f[C] vms\ vnc\ vm1 \f[] .fi .PP Install the os :) .SH SEE ALSO .PP vms(1), vms.conf(5), rc.vms(8), rc.vms.conf(5) .SH AUTHORS Nikos Giotis . vms-0.2.1/doc/man/man7/vms-tutorial.7.md0000644000000000000000000000311413341764426016345 0ustar rootroot% VMS-TUTORIAL(7) vms 0.2.1 | vms tutorial % Nikos Giotis % 28 August 2018 Create the virtual machine named vm1 vms create vm1 vms list You can go ahead and test your vm vms info vm1 vms start vm1 if you want to kill the qemu process, use vms kill vm1 Use 2 cores, change the cpu type and enable kvm vms conf vm1 smp 2 vms conf vm1 cpu host vms conf vm1 kvm yes To delete a key use the following syntax vms conf vm1 cpu -- vms conf vm1 kvm -- To use 2 GB of memory vms conf vm1 mem 2048 Now, let's create a disk image file qemu-img create -f qcow2 ~/.vms/vm1/disk.img 20G And attach it to vm1 vms conf vm1 disk0 '~/.vms/vm1/disk.img' If you want, set vm1 to run as a daemon and add a VNC console to it vms conf vm1 daemon yes vms conf vm1 vnc 7 You can always edit the **~/.vms/vms.conf** file with your favorite an editor. Now, start vm1 vms start vm1 If you started with vnc, connect to it like this vms vnc vm1 If you try to stop vm1 now with vms stop vm1 You will notice it will not stop, it needs a proper os installed handle the ACPI virtual button press and vm1[monitor]=yes You can always kill vm1 with vms kill vm1 Now, attach a cdrom and insert an .iso disk image to boot from vms conf vm1 bootcd '~/.vms/os/slackware64-14.2-install-dvd.iso' Start the vm and install the operating system vms start vm1 Again, if you started with vnc, connect to it with vms vnc vm1 Install the os :) # SEE ALSO vms(1), vms.conf(5), rc.vms(8), rc.vms.conf(5)vms-0.2.1/README.md0000644000000000000000000001535113341764426012313 0ustar rootroot# vms A command for running and managing **qemu** virtual machines ## Description **vms** is a command that creates, edits and manages **qemu** virtual machines. It lists, starts, stops and configures them. It also provides shortcuts to vnc, serial and **qemu** monitor consoles. It is small and being written in **bash** makes it easily customizable. Each user has a configuration file **~/.vms/vms.conf**. All the user's virtual machines are configured in there, using a very simple format. By editing this file the user controls the options that are passed to **qemu**. It has minimal dependencies, **bash** and **qemu** are needed for most of the functionality. **vms stop** uses **socat**, **vms monitor** uses **unixterm**, **vms serial** uses **minicom** and **vms vnc** needs **vncviewer**. An init script **rc.vms** is also provided with a simple mechanism for managing all the system's virtual machines. It can also be used during the host's boot sequence to start the machines defined by the administrator in **rc.vms.conf**. As a bonus two scripts are provided, **pci-stub-bind** and **vfio-bind** to ease the pain when using pci passthrough. ## Prebuild packages slackware [vms-0.2.1-noarch-1did.tgz](https://bitbucket.org/yotis/vms/downloads/vms-0.2.1-noarch-1did.tgz) ## Latest source release [vms-0.2.1.tar.gz](https://bitbucket.org/yotis/vms/downloads/vms-0.2.1.tar.gz) ## Latest manuals (master) [vms(1)](https://bitbucket.org/yotis/vms/src/master/doc/man/man1/vms.1.md), [vms.conf(5)](https://bitbucket.org/yotis/vms/src/master/doc/man/man5/vms.conf.5.md), [rc.vms(8)](https://bitbucket.org/yotis/vms/src/master/doc/man/man8/rc.vms.8.md), [rc.vms.conf(5)](https://bitbucket.org/yotis/vms/src/master/doc/man/man5/rc.vms.conf.5.md), [vms-tutorial(7)](https://bitbucket.org/yotis/vms/src/master/doc/man/man7/vms-tutorial.7.md) ## Basic usage example Show vms usage summary vms Create a virtual machine named _vm1_ vms create vm1 qemu-img create -f qcow2 ~/.vms/vm1/disk.img 20G` Configure _vm1_ vms conf vm1 mem 1024 vms conf vm1 smp 2 vms conf vm1 disk0 '~/.vms/vm1/disk.img' vms conf vm1 bootcd '"$APATH/to/install-dvd-iso"' or, edit **~/.vms/vms.conf** to configure _vm1_ like this # See /usr/share/vms/vms.conf.example vm1[arch]=x86_64 vm1[mem]=1024 vm1[smp]=2 vm1[disk0]=~/.vms/vm1/disk.img vm1[bootcd]="$APATH/to/install-dvd.iso" List the user's virtual machines, start vm1 and display it's status vms list vms start vm1 vms status vm1 Stop vm1 (via ACPI command), optionally with a timeout of 10 seconds vms stop vm1 vms stop vm1 10 Kill vm1 virtual machine vms kill vm1 If _vm1_ is configured with monitor, serial, vnc or log, the following can be used to access them vms vnc vm1 vms monitor vm1 vms serial vm1 vms log vm1 ## Concepts The general idea is to have a directory with a bash script for each virtual machine. All these directories are stored per user inside **~/.vms** directory. For each user there is a **~/.vms/vms.conf** file that contains all the configuration for all the user's virtual machines. The configuration for each virtual machine is kept as one bash associative array, declared in the user's **vms.conf** file. The system has a very simple parser that matches keys of this array to generate the qemu command line options for most commonly used options, such as **cpu**, **disk#**, **nic#**, **mem**, etc. Raw command line options are also supported, as well as providing the option to totally bypass the parser and use a custom bash script that calls qemu bypassing the whole system. A typical **~/.vms** directory looks like this ~/.vms ~/.vms/vms.conf ~/.vms/vm1/vm1.sh ~/.vms/vm1/disk1.img ~/.vms/vm2/vm2.sh ~/.vms/vm2/.... For each virtual machine there is a directory under **~/.vms**, eg. for _vm1_ there is a directory named _~/.vms/vm1_. This can be used to store files such as disk image files and bios files related to _vm1_, although this is optional. The only required file is the script _~/vms/vm1/vm1.sh_. The actual **qemu** call is done in ~/.vms/vm1/vm1.sh. This file is copied from **/var/lib/vms/vm.sh** when creating _vm1_ with \`vms create vm1\`. This could be edited if needed or totally replaced by a custom script. The suggested way is to configure _vm1_ by editing the appropriate section in **vms.conf**, either by hand using your favorite editor or with **vms conf** commands. The section of _vm1_ in **~/.vms/vms.conf** looks like this. declare -A vm1 vm1[name]='vm1' vm1[uuid]='ffffffff-ffff-ffff-ffff-ffffffffffff' vm1[arch]='x86_64' vm1[kvm]=yes vm1[cpu]=host vm1[smp]=2 vm1[mem]=1024 vm1[... **name**, **uuid** and **arch** are needed by **vms** for each virtual machine. **vms** identifies the qemu process by the **uuid**, so no virtual machine can be started twice. This a **bash** associative array that holds all the configuration for _vm1_. See **/usr/share/vms/vms.conf.example** for all the available options. ## Administration An init script **rc.vms** is provided is used to launch a set of virtual machines during boot. Assuming the host keeps this init script in _/etc/rc.d/_, the root user can use the following line with the host's init system to start the virtual machines defined in **rc.vms.conf**. /etc/rc.d/rc.vms start Accordingly, one can use the following to restart and stop the machines in the set. /etc/rc.d/rc.vms restart /etc/rc.d/rc.vms stop The following diplays the status of the machines. /etc/rc.d/rc.vms status Also, **rc.vms** can be used to call any **vms** command as any user. Assuming the user _joe_ has a machine named _vm1_, the root user can use this script like this to display information about _vm1_ /etc/rc.d/rc.vms cmd joe info vm1 Accordingly root can start, stop and restart _vm1_ like this /etc/rc.d/rc.vms cmd joe start vm1 /etc/rc.d/rc.vms cmd joe stop vm1 /etc/rc.d/rc.vms cmd joe restart vm1 When launching the _vm1_ machine with the following line in **~/.vms/vms.conf** vm1[secure]=yes then only the root user can launch _vm1_, since root privileges are needed to chroot and run as nobody. If this is not set, **rc.vms** will start the **qemu** process as the normal user _joe_. /etc/rc.d/rc.vms cmd joe start vm1 ## Directories & files - user configuration `~/.vms/vms.conf` - user configuration example `/usr/share/vms/vms.conf.example` - template scripts for vm creation `/var/lib/vms/` `/var/lib/vms/vm.sh` - vms command and parser scripts `/usr/bin/vms` `/usr/bin/vms-parse` - helpers for pci passthrough `/usr/sbin/vfio-bind` `/usr/sbin/pci-stub-bind` - init script `/etc/rc.d/rc.vms` - init script configuration `/etc/rc.d/rc.vms.conf` vms-0.2.1/.gitignore0000644000000000000000000000012113341764426013011 0ustar rootroot*.directory packaging/slackware/*.tar.gz packaging/slackware/vms/vms-*.tar.gz *~