dom0: create volatile.img if not exists (StandaloneVM case)

StandaloneVM have no template to get clean volatile.img. Normally it is copied
from template during VM creation, but it can happen that image would not extx
(e.g. after backup restore). So create it from scratch.

Stay with original approach (restoring from clean image of template) for other
cases as it is much simpler (and perhaps faster).
This commit is contained in:
Marek Marczykowski 2013-02-27 05:29:27 +01:00
parent 1b05978ec6
commit d89bdac58c
3 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#!/bin/sh
if [ "`id -u`" != "0" ]; then
exec sudo $0 $*
fi
set -e
FILENAME=$1
ROOT_SIZE=$2
SWAP_SIZE=$[ 1024 ]
if [ -z "$ROOT_SIZE" -o -z "$FILENAME" ]; then
echo "Usage: $0 <filename> <root.img size in MB>"
exit 1
fi
if [ -e "$FILENAME" ]; then
echo "$FILENAME already exists, not overriding"
exit 1
fi
TOTAL_SIZE=$[ $ROOT_SIZE + $SWAP_SIZE + 512 ]
truncate -s ${TOTAL_SIZE}M "$FILENAME"
sfdisk --no-reread -u M "$FILENAME" > /dev/null 2> /dev/null <<EOF
0,${SWAP_SIZE},S
,${ROOT_SIZE},L
EOF
kpartx -s -a "$FILENAME"
loopdev=`losetup -j "$FILENAME"|tail -n 1 |cut -d: -f1`
looppart=`echo $loopdev|sed 's:dev:dev/mapper:'`
mkswap -f ${looppart}p1 > /dev/null
kpartx -s -d ${loopdev}
losetup -d ${loopdev} || :
chown --reference `dirname "$FILENAME"` "$FILENAME"

View File

@ -106,6 +106,7 @@ dom0_vm = None
qubes_appmenu_create_cmd = "/usr/lib/qubes/create_apps_for_appvm.sh"
qubes_appmenu_remove_cmd = "/usr/lib/qubes/remove_appvm_appmenus.sh"
qubes_pciback_cmd = '/usr/lib/qubes/unbind_pci_device.sh'
prepare_volatile_img_cmd = '/usr/lib/qubes/prepare_volatile_img.sh'
yum_proxy_ip = '10.137.255.254'
yum_proxy_port = '8082'
@ -1238,6 +1239,15 @@ class QubesVm(object):
# Only makes sense on template based VM
if source_template is None:
# For StandaloneVM create it only if not already exists (eg after backup-restore)
if not os.path.exists(self.volatile_img):
if verbose:
print >> sys.stderr, "--> Creating volatile image: {0}...".format (self.volatile_img)
f_root = open (self.root_img, "r")
f_root.seek(0, os.SEEK_END)
root_size = f_root.tell()
f_root.close()
subprocess.check_call([prepare_volatile_img_cmd, self.volatile_img, str(root_size / 1024 / 1024)])
return
if verbose:

View File

@ -145,6 +145,7 @@ cp aux-tools/remove_appvm_appmenus.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/cleanup_dispvms $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/startup-dvm.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/startup-misc.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp aux-tools/prepare_volatile_img.sh $RPM_BUILD_ROOT/usr/lib/qubes
cp qmemman/server.py $RPM_BUILD_ROOT/usr/lib/qubes/qmemman_daemon.py
cp ../misc/meminfo-writer $RPM_BUILD_ROOT/usr/lib/qubes/
cp ../qrexec/qrexec_daemon $RPM_BUILD_ROOT/usr/lib/qubes/
@ -440,6 +441,7 @@ fi
/usr/lib/qubes/fix_dir_perms.sh
/usr/lib/qubes/startup-dvm.sh
/usr/lib/qubes/startup-misc.sh
/usr/lib/qubes/prepare_volatile_img.sh
%attr(4750,root,qubes) /usr/lib/qubes/qfile-dom0-unpacker
%if %{use_systemd}
%{_unitdir}/qubes-block-cleaner.service