frnmst-archives
/
qvm
Archived
1
0
Fork 0
Browse Source

Added more options. Updated readme.

dev
frnmst/Franco Masotti 6 years ago
parent
commit
23f06fce74
  1. 55
      README.md
  2. 71
      qvm

55
README.md

@ -17,27 +17,64 @@ It can handle:
## Setup information and usage
- You need a 64 bit machine.
- You need a 64 bit machine with virtualization technology and more than 4 GB
of RAM.
- Modify `configvmrc` based on your needs.
Variables are self-explanatory and I have kept mine
as an example.
- Install qemu:
# pacman -S qemu
$ . ./configvmrc
$ mkdir -p "$shared_data_path"
- Create a new VHD and complete the OS installation:
$ ./qvm -c
$ ./qvm -i
$ ./qvm -b
- Now you can run the virtual machine:
- Optionally enable SSHD on the guest machine.
- Optionally create a new backup VHD:
$ ./qvm -r
$ ./qvm -b
- On your guest machine add the following in `/etc/fstab`:
- Now you can run the virtual machine either using the original or the backup
VHD. By deault if you run `./qvm` the virtual machine will run in graphics
mode using the backup hard disk.
- Optionally add the following in the gues machine's `/etc/fstab`, to enable
the shared directory automatically (no mount commands of any
sort).
host_share /home/vm/shared 9p trans=virtio,version=9p2000.L 0 0
This will enable the shared directory automatically (no mount commands of any
sort).
## Help
Usage: qvm [OPTION]
Trivial management of 64 bit virtual machines with qemu.
Options:
-a, --attach connect via SSH
-b, --backup backup vhd
-c, --create create new vhd
-d, --delete delete vhd backup
--delete-orig delete original vhd
-h, --help print this help
-i, --install install img on vhd
-n, --run-nox run vm without opening a graphical window
(useful for background jobs like SSH)
--run-nox-orig run-orig and run-nox combined
-s, --mkdir-shared create shared directory
-x, --run run vm
--run-orig run from original vhd
Only a single option is accepted.
By default, the backup vhd is run.
CC0
Written in 2016 by Franco Masotti/frnmst <franco.masotti@student.unife.it>
## License

71
qvm

@ -23,15 +23,19 @@ Options:
-b, --backup backup vhd
-c, --create create new vhd
-d, --delete delete vhd backup
--delete-original delete original vhd
--delete-orig 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
-n, --run-nox run vm without opening a graphical window
(useful for background jobs like SSH)
--run-nox-orig run-orig and run-nox combined
-s, --mkdir-shared create shared directory
-x, --run run vm
--run-orig run from original vhd
Only a single option is accepted.
Before running any virtual machine you must create a backup first.
By default, the backup vhd is run.
CC0
Written in 2016 by Franco Masotti/frnmst <franco.masotti@student.unife.it>
@ -64,12 +68,16 @@ create()
delete()
{
rm "$vhd_name".mod
}
local argc="$1"
local vhd=""
delete_original()
{
rm "$vhd_name"
if [ "$argc" = "orig" ]; then
vhd="$vhd_name"
else
vhd=""$vhd_name".mod"
fi
rm "$vhd"
}
installs()
@ -81,11 +89,31 @@ installs()
"$vhd_name" &
}
shared()
{
mkdir -p "$shared_data_path"
}
run()
{
argc="$1"
local argc1="$1"
local argc2="$2"
local vhd=""
local display=""
if [ "$argc2" = "orig" ]; then
vhd="$vhd_name"
else
vhd=""$vhd_name".mod"
fi
if [ "$argc1" = "none" ]; then
display="none"
else
display="gtk"
fi
if [ -f "$vhd_name".mod ]; then
if [ -f "$vhd" ]; then
qemu-system-x86_64 \
-m "$vm_memory" \
-enable-kvm \
@ -95,10 +123,10 @@ 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" \
-display "$argc" \
"$vhd_name".mod &
-display "$display" \
"$vhd" &
else
printf "Make a backup and an installation first.\n"
printf "VHD file \""$vhd"\" is missing.\n"
exit 1
fi
}
@ -107,12 +135,12 @@ main()
{
local argc="$1"
local options="abcdhir"
local long_options="attach,backup,create,delete,delete-original\
,help,install,run,run-nox"
local long_options="attach,backup,create,delete,delete-orig\
,help,install,run,run-orig,run-nox,run-nox-orig"
local opts
local opt
[ -z "$argc" ] && argc="-r"
[ -z "$argc" ] && argc="-x"
opts="$(getopt --options $options --longoptions $long_options -- $argc)"
@ -130,11 +158,14 @@ main()
-b | --backup ) backup ;;
-c | --create ) create ;;
-d | --delete ) delete ;;
--delete-original ) delete_original ;;
--delete-orig ) delete orig ;;
-h | --help ) help ;;
-i | --install ) installs ;;
-r | --run ) run gtk ;;
--run-nox ) run none ;;
-n | --run-nox ) run none ;;
--run-nox-orig ) run none orig ;;
-s | --mkdir-shared ) shared ;;
-x | --run ) run gtk ;;
--run-orig ) run gtk orig ;;
esac
done
}