|
|
|
@ -12,21 +12,22 @@
|
|
|
|
|
# with this software. If not, see |
|
|
|
|
# <http://creativecommons.org/publicdomain/zero/1.0/>. |
|
|
|
|
|
|
|
|
|
. ./configvmrc |
|
|
|
|
|
|
|
|
|
input="$1" |
|
|
|
|
if [ -z "$input" ] || [ "$input" = "-h" ]; then |
|
|
|
|
help() |
|
|
|
|
{ |
|
|
|
|
cat <<-EOF |
|
|
|
|
Usage: qvm [OPTION] |
|
|
|
|
Trivial management of 64 bit virtual machines with qemu. |
|
|
|
|
|
|
|
|
|
Options: |
|
|
|
|
-b backup vhd |
|
|
|
|
-c create new vhd |
|
|
|
|
-d delete vhd backup |
|
|
|
|
-h print this help |
|
|
|
|
-i install img on vhd |
|
|
|
|
-r run vm |
|
|
|
|
-b, --backup backup vhd |
|
|
|
|
-c, --create create new vhd |
|
|
|
|
-d, --delete delete vhd backup |
|
|
|
|
--delete-original delete original vhd |
|
|
|
|
-h, --help print this help |
|
|
|
|
-i, --install install img on vhd |
|
|
|
|
-r, --run run vm |
|
|
|
|
--run-nox run vm without opening a graphical window |
|
|
|
|
(useful fir background jobs like SSH) |
|
|
|
|
|
|
|
|
|
Only a single option is accepted. |
|
|
|
|
Before running any virtual machine you must create a backup first. |
|
|
|
@ -34,30 +35,52 @@ Before running any virtual machine you must create a backup first.
|
|
|
|
|
CC0 |
|
|
|
|
Written in 2016 by Franco Masotti/frnmst <franco.masotti@student.unife.it> |
|
|
|
|
EOF |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unrecognized_option() |
|
|
|
|
{ |
|
|
|
|
printf "%s\n" "Try 'qvm --help' for more information" |
|
|
|
|
} 1>&2- |
|
|
|
|
|
|
|
|
|
[ "$input" = "-b" ] \ |
|
|
|
|
&& qemu-img create -f "$vhd_type" \ |
|
|
|
|
backup() |
|
|
|
|
{ |
|
|
|
|
qemu-img create -f "$vhd_type" \ |
|
|
|
|
-b "$vhd_name" \ |
|
|
|
|
"$vhd_name".mod |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
create() |
|
|
|
|
{ |
|
|
|
|
qemu-img create -f "$vhd_type" \ |
|
|
|
|
"$vhd_name" \ |
|
|
|
|
"$vhd_size" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[ "$input" = "-d" ] \ |
|
|
|
|
&& rm "$vhd_name".mod |
|
|
|
|
delete() |
|
|
|
|
{ |
|
|
|
|
rm "$vhd_name".mod |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[ "$input" = "-c" ] \ |
|
|
|
|
&& qemu-img create -f "$vhd_type" "$vhd_name" "$vhd_size" |
|
|
|
|
delete_original() |
|
|
|
|
{ |
|
|
|
|
rm "$vhd_name" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[ "$input" = "-i" ] \ |
|
|
|
|
&& qemu-system-x86_64 -m "$vm_memory" \ |
|
|
|
|
-enable-kvm -cdrom "$img_name" \ |
|
|
|
|
-boot order=d "$vhd_name" |
|
|
|
|
installs() |
|
|
|
|
{ |
|
|
|
|
qemu-system-x86_64 -m "$vm_memory" \ |
|
|
|
|
-enable-kvm \ |
|
|
|
|
-cdrom "$img_name" \ |
|
|
|
|
-boot order=d \ |
|
|
|
|
"$vhd_name" & |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[ "$input" = "-r" ] \ |
|
|
|
|
&& [ -f "$vhd_name".mod ] \ |
|
|
|
|
&& qemu-system-x86_64 \ |
|
|
|
|
run() |
|
|
|
|
{ |
|
|
|
|
argc="$1" |
|
|
|
|
|
|
|
|
|
if [ -f "$vhd_name".mod ]; then |
|
|
|
|
qemu-system-x86_64 \ |
|
|
|
|
-m "$vm_memory" \ |
|
|
|
|
-enable-kvm \ |
|
|
|
|
-device e1000,netdev=user.0 \ |
|
|
|
@ -66,7 +89,47 @@ id=user.0,hostfwd=tcp::"$host_port"-:"$guest_port",\
|
|
|
|
|
hostfwd=tcp::"$ssh_host_port"-:"$ssh_guest_port" \ |
|
|
|
|
-virtfs local,path="$shared_data_path",\ |
|
|
|
|
security_model=none,mount_tag="$mount_tag" \ |
|
|
|
|
"$vhd_name".mod \ |
|
|
|
|
|| { printf "Make a backup first.\n"; exit 1; } |
|
|
|
|
-display "$argc" \ |
|
|
|
|
"$vhd_name".mod & |
|
|
|
|
else |
|
|
|
|
printf "Make a backup and an installation first.\n" |
|
|
|
|
exit 1 |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
main() |
|
|
|
|
{ |
|
|
|
|
local argc="$1" |
|
|
|
|
local options="bcdhir" |
|
|
|
|
local long_options="backup,create,delete,delete-original\ |
|
|
|
|
,help,install,run,run-nox" |
|
|
|
|
local opts |
|
|
|
|
local opt |
|
|
|
|
|
|
|
|
|
[ -z "$argc" ] && argc="-r" |
|
|
|
|
|
|
|
|
|
opts="$(getopt --options $options --longoptions $long_options -- $argc)" |
|
|
|
|
|
|
|
|
|
[ $? -ne 0 ] && unrecognized_option && return 1 |
|
|
|
|
|
|
|
|
|
eval set -- "$opts" |
|
|
|
|
|
|
|
|
|
# Source variables globally. |
|
|
|
|
. ./configvmrc |
|
|
|
|
|
|
|
|
|
for opt in $opts; do |
|
|
|
|
case "$opt" in |
|
|
|
|
-- ) ;; |
|
|
|
|
-b | --backup ) backup ;; |
|
|
|
|
-c | --create ) create ;; |
|
|
|
|
-d | --delete ) delete ;; |
|
|
|
|
--delete-original ) delete_original ;; |
|
|
|
|
-h | --help ) help ;; |
|
|
|
|
-i | --install ) installs ;; |
|
|
|
|
-r | --run ) run gtk ;; |
|
|
|
|
--run-nox ) run none ;; |
|
|
|
|
esac |
|
|
|
|
done |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} & |
|
|
|
|
main "$*" |
|
|
|
|