2016-10-08 17:56:17 +02:00
|
|
|
# qvm
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-10-08 17:56:17 +02:00
|
|
|
Trivial management of 64 bit virtual machines with qemu.
|
2016-10-08 18:30:05 +02:00
|
|
|
|
2016-10-10 18:31:13 +02:00
|
|
|
## What this script will do
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-10-08 18:30:05 +02:00
|
|
|
It can handle:
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-10-08 18:30:05 +02:00
|
|
|
- Virtual hard disk creation, backup and deletion.
|
|
|
|
- Basic network management: two ports are exposed to the host
|
|
|
|
machine (but you can add as many as you want). One of these
|
|
|
|
two ports is SSH (so admin gets simpler).
|
2016-11-07 16:10:40 +01:00
|
|
|
- Connection via SSH.
|
2016-10-08 18:30:05 +02:00
|
|
|
- Shared directory between host and guest.
|
2018-01-01 16:14:25 +01:00
|
|
|
- Last, but not least, running the virtual machine with a
|
|
|
|
combination of the previous options.
|
2016-10-08 18:30:05 +02:00
|
|
|
|
2016-10-10 18:31:13 +02:00
|
|
|
## Setup information and usage
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-11-14 18:02:47 +01:00
|
|
|
- You need a 64 bit machine with virtualization technology and more than 4 GB
|
|
|
|
of RAM.
|
|
|
|
|
2016-10-08 18:30:05 +02:00
|
|
|
- Modify `configvmrc` based on your needs.
|
|
|
|
Variables are self-explanatory and I have kept mine
|
|
|
|
as an example.
|
|
|
|
|
2017-10-05 09:53:04 +02:00
|
|
|
- Install the following dependencies
|
|
|
|
- [GNU Bash](http://www.gnu.org/software/bash/bash.html)
|
|
|
|
- Scipting language interpreter
|
|
|
|
- [GNU Core Utilities](https://www.gnu.org/software/coreutils/)
|
|
|
|
- Basic software like `ls`, `cat`, etc...
|
|
|
|
- [QEMU](https://www.qemu.org/)
|
|
|
|
- The machine emulator
|
2017-10-18 11:41:15 +02:00
|
|
|
- [TigerVNC](http://www.tigervnc.org)
|
|
|
|
- If you need to use the vm remotely from a coumputer which does not
|
|
|
|
support virtualization.
|
2016-11-14 18:02:47 +01:00
|
|
|
|
|
|
|
- Create a new VHD and complete the OS installation:
|
|
|
|
|
|
|
|
$ ./qvm -c
|
2016-11-06 22:14:36 +01:00
|
|
|
$ ./qvm -i
|
2016-10-10 17:34:01 +02:00
|
|
|
|
2016-11-15 01:08:23 +01:00
|
|
|
- Optionally enable the SSH daemon on the guest machine.
|
2016-11-14 18:02:47 +01:00
|
|
|
|
|
|
|
- Optionally create a new backup VHD:
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-11-14 18:02:47 +01:00
|
|
|
$ ./qvm -b
|
2016-10-08 18:30:05 +02:00
|
|
|
|
2016-11-14 18:02:47 +01:00
|
|
|
- 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).
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-11-15 15:00:14 +01:00
|
|
|
host_share /home/vm/shared 9p noauto,x-systemd.automount,trans=virtio,version=9p2000.L 0 0
|
|
|
|
|
2017-10-21 13:28:42 +02:00
|
|
|
- You can also access the virtual machine through SSH:
|
|
|
|
|
|
|
|
$ ./qvm -a
|
|
|
|
|
|
|
|
or, if you are working on another computer,
|
|
|
|
|
|
|
|
$ ./qvm --attach-remote
|
|
|
|
|
2017-10-18 11:41:15 +02:00
|
|
|
## VNC options
|
|
|
|
|
2017-10-18 11:52:14 +02:00
|
|
|
The VNC options in this script allow you to connect to a remote instance of
|
|
|
|
QEMU. This is particularly useful, for example, if your local machine
|
|
|
|
processor does not support virtualization. The only thing to do is to make
|
|
|
|
the server's port (`5900`) reachable from the clients.
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2017-10-18 11:52:14 +02:00
|
|
|
You must then run QVM with one of the VNC options on the server side.
|
|
|
|
On the client side you must simply edit the `host_ip_address` and
|
|
|
|
`host_username` variables in the configuration file.
|
2017-10-18 11:41:15 +02:00
|
|
|
|
|
|
|
For example, on the server side we could install the virtual machine remotely
|
|
|
|
like this:
|
|
|
|
|
|
|
|
$ ./qvm --install-vnc
|
|
|
|
|
|
|
|
And on the client side:
|
|
|
|
|
|
|
|
$ ./qvm -r
|
|
|
|
|
2017-10-18 11:52:14 +02:00
|
|
|
At this point you should see your virtual machine running in a TigerVNC window.
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2017-10-18 12:00:06 +02:00
|
|
|
Note: the VNC traffic goes through SSH TCP forwarding, so it is encrypted.
|
2017-10-18 11:59:20 +02:00
|
|
|
|
2018-01-01 16:14:25 +01:00
|
|
|
## Interesting applications
|
|
|
|
|
|
|
|
If you happen to use a form of network filesystem, such as
|
|
|
|
[GlusterFS](http://docs.gluster.org/en/latest/),
|
|
|
|
you can keep the machine hard disk off the host and put it on another computer.
|
|
|
|
There might be a some form of lag depending on the hardware, protocol and
|
|
|
|
network connections.
|
|
|
|
|
|
|
|
An example with GlusterFS might be:
|
|
|
|
|
|
|
|
vhd_name="gluster+tcp://server-address/gluster-volume/"$img_name"."$vhd_type""
|
|
|
|
|
|
|
|
This will work provided that you install the QEMU GlusterFS block module
|
|
|
|
package (if it's not already present in the QEMU package itself).
|
|
|
|
|
|
|
|
You should consult the QEMU's manual to learn about all possible compatible
|
|
|
|
network filesystems.
|
|
|
|
|
2016-11-14 18:02:47 +01:00
|
|
|
## Help
|
|
|
|
|
|
|
|
Usage: qvm [OPTION]
|
|
|
|
Trivial management of 64 bit virtual machines with qemu.
|
|
|
|
|
|
|
|
Options:
|
2017-10-21 13:28:42 +02:00
|
|
|
-a, --attach connect to SSH locally
|
|
|
|
--attach-remote connect to SSH remotely
|
2016-11-14 18:02:47 +01:00
|
|
|
-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
|
2017-10-18 11:41:15 +02:00
|
|
|
--install-vnc install img on vhd via vnc
|
2016-11-14 18:02:47 +01:00
|
|
|
-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
|
2017-10-18 11:41:15 +02:00
|
|
|
-r, --remote connect to a vnc instance via ssh
|
2016-11-14 18:02:47 +01:00
|
|
|
-x, --run run vm
|
2017-10-18 11:41:15 +02:00
|
|
|
--run-vnc run vm with vnc
|
2016-11-14 18:02:47 +01:00
|
|
|
--run-orig run from original vhd
|
2017-10-18 11:41:15 +02:00
|
|
|
--run-orig-vnc run from original vhd with vnc
|
2016-11-14 18:02:47 +01:00
|
|
|
|
|
|
|
|
2017-10-21 13:28:42 +02:00
|
|
|
Only a single option is accepted.
|
|
|
|
By default, the backup vhd is run.
|
2016-11-14 18:02:47 +01:00
|
|
|
|
2017-10-21 13:28:42 +02:00
|
|
|
CC0
|
|
|
|
Written in 2016 by Franco Masotti/frnmst <franco.masotti@student.unife.it>
|
2016-10-08 18:30:05 +02:00
|
|
|
|
2016-10-10 18:31:13 +02:00
|
|
|
## License
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2016-10-08 18:30:05 +02:00
|
|
|
CC0.
|