2010-07-16 11:19:03 +02:00
|
|
|
#!/bin/sh
|
|
|
|
if [ $# != 1 -a $# != 2 ] ; then
|
2011-07-26 17:09:59 +02:00
|
|
|
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
|
2011-07-26 17:09:59 +02:00
|
|
|
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
|
2012-02-07 03:07:43 +01:00
|
|
|
TEMPLATENAME=$(qubes-prefs --get default-template)
|
2010-09-21 18:40:15 +02:00
|
|
|
if [ "X"$TEMPLATENAME = "X" ] ; then
|
|
|
|
echo No default template ?
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "X""$2" = "X""--default-script" ] ; then
|
2012-07-12 14:21:59 +02:00
|
|
|
SCRIPTNAME="vm-default"
|
2010-09-21 18:40:15 +02:00
|
|
|
else
|
2012-07-12 14:21:59 +02:00
|
|
|
SCRIPTNAME=$2
|
2010-09-21 18:40:15 +02:00
|
|
|
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
|
2010-09-21 18:40:15 +02:00
|
|
|
DVMTMPL="$TEMPLATENAME"-dvm
|
2011-03-23 09:36:30 +01:00
|
|
|
DVMTMPLDIR="/var/lib/qubes/appvms/$DVMTMPL"
|
|
|
|
if ! [ -d "$DVMTMPLDIR" ] ; then
|
2011-03-24 16:53:40 +01:00
|
|
|
# unfortunately, currently there are reliability issues with save of a domain
|
2012-12-16 03:56:42 +01:00
|
|
|
# with multiple CPUs and/or more than 4000M RAM
|
2011-04-08 11:03:00 +02:00
|
|
|
if ! qvm-create --force-root --vcpus=1 --internal -t "$TEMPLATENAME" -l gray "$DVMTMPL" ; then exit 1 ; fi
|
2013-01-27 00:01:56 +01:00
|
|
|
MAXMEM=`qvm-prefs --force-root $DVMTMPL|grep ^maxmem|awk 'print $3'`
|
2012-12-16 03:56:42 +01:00
|
|
|
if [ "$MAXMEM" -ge 4000 ]; then
|
|
|
|
qvm-prefs --force-root -s $DVMTMPL maxmem 4000
|
|
|
|
fi
|
2010-07-16 11:19:03 +02:00
|
|
|
fi
|
|
|
|
if ! /usr/lib/qubes/qubes_prepare_saved_domain.sh \
|
2010-09-21 18:40:15 +02:00
|
|
|
"$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
|
2011-06-08 03:36:02 +02:00
|
|
|
DEFAULTCONF=/var/lib/qubes/dvmdata/default_dvm.conf
|
2010-07-16 11:19:03 +02:00
|
|
|
CURRENT=/var/run/qubes/current_savefile
|
2011-06-08 03:36:02 +02:00
|
|
|
CURRENTCONF=/var/run/qubes/current_dvm.conf
|
2010-07-16 11:19:03 +02:00
|
|
|
SHMDIR=/dev/shm/qubes
|
|
|
|
SHMCOPY=$SHMDIR/current_savefile
|
2011-06-08 03:36:02 +02:00
|
|
|
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
|
2010-09-21 18:40:15 +02:00
|
|
|
ln -s "/var/lib/qubes/vm-templates/$TEMPLATENAME/root.img" $ROOT
|
2011-06-08 03:36:02 +02:00
|
|
|
ln -s $DVMTMPLDIR/dvm.conf $DEFAULTCONF
|
|
|
|
ln -s $DVMTMPLDIR/dvm.conf $CURRENTCONF
|
2010-07-16 11:19:03 +02:00
|
|
|
if [ -f /var/lib/qubes/dvmdata/dont_use_shm ] ; then
|
|
|
|
ln -s $DEFAULT $CURRENT
|
|
|
|
else
|
|
|
|
mkdir -m 770 $SHMDIR 2>/dev/null
|
|
|
|
chgrp qubes $SHMDIR 2>/dev/null
|
|
|
|
cp $DEFAULT $SHMCOPY || exit 1
|
|
|
|
chgrp qubes $SHMCOPY
|
|
|
|
chmod 660 $SHMCOPY
|
|
|
|
ln -s $SHMCOPY $CURRENT
|
|
|
|
fi
|
2011-03-23 13:40:28 +01:00
|
|
|
|
2011-03-24 16:57:43 +01:00
|
|
|
if [ $(whoami) = "root" ] ; then
|
|
|
|
chgrp qubes "$DVMTMPLDIR" "$DVMTMPLDIR"/*
|
|
|
|
chmod 660 "$DVMTMPLDIR"/*
|
|
|
|
chmod 770 "$DVMTMPLDIR"
|
|
|
|
fi
|
|
|
|
|