core-admin/qvm-tools/qvm-create-default-dvm

82 lines
2.6 KiB
Plaintext
Raw Normal View History

2010-07-16 11:19:03 +02:00
#!/bin/sh
if [ $# != 1 -a $# != 2 ] ; then
echo 'Usage: qvm-create-default-dvm templatename|--default-template|--used-template [script-name|--default-script]'
2010-07-16 11:19:03 +02:00
exit 1
fi
export ROOT=/var/lib/qubes/dvmdata/savefile-root
TEMPLATENAME=$1
if [ "$TEMPLATENAME" = --used-template ] ; then
if [ -e $ROOT ] ; then
TEMPLATENAME=$(readlink $ROOT | sed -e 's/.root.img//' -e 's/.*\///')
else
TEMPLATENAME=--default-template
fi
fi
if [ "$TEMPLATENAME" = --default-template ] ; then
TEMPLATENAME=$(qubes-prefs --get default-template)
if [ "X"$TEMPLATENAME = "X" ] ; then
echo No default template ?
exit 1
fi
fi
if [ "X""$2" = "X""--default-script" ] ; then
SCRIPTNAME="vm-default"
else
SCRIPTNAME=$2
fi
if ! [ -d "/var/lib/qubes/vm-templates/$TEMPLATENAME" ] ; then
echo /var/lib/qubes/vm-templates/$TEMPLATENAME is not a directory
2010-07-16 11:19:03 +02:00
exit 1
fi
DVMTMPL="$TEMPLATENAME"-dvm
DVMTMPLDIR="/var/lib/qubes/appvms/$DVMTMPL"
if ! [ -d "$DVMTMPLDIR" ] ; then
# unfortunately, currently there are reliability issues with save of a domain
# with multiple CPUs and/or more than 4000M RAM
if ! qvm-create --force-root --vcpus=1 --internal -t "$TEMPLATENAME" -l gray "$DVMTMPL" ; then exit 1 ; fi
MAXMEM=`qvm-prefs --force-root $DVMTMPL|grep ^maxmem|awk '{print $3}'`
if [ "$MAXMEM" -ge 4000 ]; then
qvm-prefs --force-root -s $DVMTMPL maxmem 4000
fi
# balloon driver do not work with save/restore in 3.12+ kernels, so if possible, use older one
kver=`ls /var/lib/qubes/vm-kernels | sort -t. -k 2 -nr | awk -F. '$2 < 12 { print; exit; }'`
if [ -n "$kver" ]; then
qvm-prefs --force-root -s $DVMTMPL kernel $kver
fi
2010-07-16 11:19:03 +02:00
fi
2013-03-14 15:06:19 +01:00
if ! /usr/lib/qubes/qubes-prepare-saved-domain.sh \
"$DVMTMPL" "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $SCRIPTNAME ; then
2010-07-16 11:19:03 +02:00
exit 1
fi
DEFAULT=/var/lib/qubes/dvmdata/default-savefile
DEFAULTCONF=/var/lib/qubes/dvmdata/default-dvm.conf
CURRENT=/var/run/qubes/current-savefile
CURRENTCONF=/var/run/qubes/current-dvm.conf
2010-07-16 11:19:03 +02:00
SHMDIR=/dev/shm/qubes
SHMCOPY=$SHMDIR/current-savefile
rm -f $ROOT $DEFAULT $CURRENT $DEFAULTCONF $CURRENTCONF
2010-07-16 11:19:03 +02:00
ln -s "/var/lib/qubes/appvms/$DVMTMPL/dvm-savefile" $DEFAULT
ln -s "/var/lib/qubes/vm-templates/$TEMPLATENAME/root.img" $ROOT
ln -s $DVMTMPLDIR/dvm.conf $DEFAULTCONF
ln -s $DVMTMPLDIR/dvm.conf $CURRENTCONF
if [ -f /var/lib/qubes/dvmdata/dont-use-shm ] ; then
2010-07-16 11:19:03 +02:00
ln -s $DEFAULT $CURRENT
else
mkdir -m 770 $SHMDIR 2>/dev/null
chgrp qubes $SHMDIR 2>/dev/null
rm -f $SHMCOPY
2010-07-16 11:19:03 +02:00
cp $DEFAULT $SHMCOPY || exit 1
chgrp qubes $SHMCOPY
chmod 660 $SHMCOPY
ln -s $SHMCOPY $CURRENT
fi
if [ $(whoami) = "root" ] ; then
chgrp qubes "$DVMTMPLDIR" "$DVMTMPLDIR"/*
chmod 660 "$DVMTMPLDIR"/*
chmod 770 "$DVMTMPLDIR"
fi