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
|
|
|
|
2018-12-27 13:26:08 +01:00
|
|
|
## Table of contents
|
2018-01-11 20:15:51 +01:00
|
|
|
|
|
|
|
[](TOC)
|
|
|
|
|
2019-02-24 19:17:05 +01:00
|
|
|
- [qvm](#qvm)
|
|
|
|
- [Table of contents](#table-of-contents)
|
2019-02-24 20:04:03 +01:00
|
|
|
- [Reasons](#reasons)
|
|
|
|
- [Version](#version)
|
2019-02-24 19:17:05 +01:00
|
|
|
- [What this script will do](#what-this-script-will-do)
|
|
|
|
- [Prerequisites](#prerequisites)
|
|
|
|
- [Dependencies](#dependencies)
|
|
|
|
- [Installation](#installation)
|
|
|
|
- [Arch Linux based distros](#arch-linux-based-distros)
|
|
|
|
- [Help](#help)
|
|
|
|
- [Setup information and usage](#setup-information-and-usage)
|
|
|
|
- [Actions and parameters](#actions-and-parameters)
|
|
|
|
- [Actions](#actions)
|
|
|
|
- [Places](#places)
|
|
|
|
- [Setup](#setup)
|
|
|
|
- [Connection to the machine](#connection-to-the-machine)
|
|
|
|
- [VNC options](#vnc-options)
|
|
|
|
- [Setup](#setup-1)
|
|
|
|
- [Examples](#examples)
|
|
|
|
- [Automatic remote startup](#automatic-remote-startup)
|
|
|
|
- [Interesting applications](#interesting-applications)
|
|
|
|
- [Virtual machine hard disk over a network protocol](#virtual-machine-hard-disk-over-a-network-protocol)
|
2019-02-25 17:34:52 +01:00
|
|
|
- [Bugs](#bugs)
|
2019-02-24 19:17:05 +01:00
|
|
|
- [License](#license)
|
|
|
|
|
|
|
|
[](TOC)
|
|
|
|
|
2019-02-24 19:27:42 +01:00
|
|
|
## Reasons
|
|
|
|
|
|
|
|
See https://frnmst.gitlab.io/notes/qemu-ssh-tunnel.html
|
|
|
|
|
|
|
|
## Version
|
|
|
|
|
|
|
|
1.0.0
|
|
|
|
|
|
|
|
See all [qvm releases](https://github.com/frnmst/qvm/releases).
|
|
|
|
|
2018-12-27 13:26:08 +01: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.
|
2018-12-27 17:37:29 +01:00
|
|
|
- Basic network management: three ports are exposed to the host
|
|
|
|
machine (but you can add as many as you want). One of these two ports is
|
|
|
|
SSH.
|
2016-10-08 18:30:05 +02:00
|
|
|
- Shared directory between host and guest.
|
2018-12-27 17:37:29 +01:00
|
|
|
- Running the virtual machine with a combination of the previous options.
|
2016-10-08 18:30:05 +02:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
## Prerequisites
|
2018-12-27 16:37:24 +01:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
- You need a 64 bit machine with virtualization technology and at least 4 GB
|
2016-11-14 18:02:47 +01:00
|
|
|
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.
|
2019-02-24 12:01:19 +01:00
|
|
|
|
|
|
|
## Dependencies
|
|
|
|
|
|
|
|
You need to install the following packages and the ones listed for
|
|
|
|
[fbopt](https://github.com/frnmst/fbopt#dependencies)
|
|
|
|
|
|
|
|
| Package | Executable | Version command | Package version |
|
|
|
|
|---------|------------|-----------------|-----------------|
|
|
|
|
| [QEMU](https://www.qemu.org/) | `/bin/qemu-system-x86_64` | `$ qemu-system-x86_64 --version` | `QEMU emulator version 3.1.0` |
|
|
|
|
| [TigerVNC](http://www.tigervnc.org) | `/bin/vncviewer` | `$ vncviewer --help` | `TigerVNC Viewer 64-bit v1.9.0` |
|
|
|
|
| [OpenSSH](https://www.openssh.com/portable.html) | `/bin/ssh` | `$ ssh -V` | `OpenSSH_7.9p1, OpenSSL 1.1.1a 20 Nov 2018`
|
2019-02-24 12:02:36 +01:00
|
|
|
| [GNU coreutils](https://www.gnu.org/software/coreutils/) | `/bin/mkdir`, `/bin/sleep`, `/bin/rm` | `$ ${Executable} --version` | `(GNU coreutils) 8.30` |
|
2019-02-24 12:01:19 +01:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
### Arch Linux based distros
|
|
|
|
|
|
|
|
# pacman -S coreutils openssh tigervnc qemu
|
|
|
|
|
2019-02-24 19:17:05 +01:00
|
|
|
## Help
|
|
|
|
|
2019-02-25 11:52:06 +01:00
|
|
|
```
|
|
|
|
Usage: qvm [OPTION]
|
|
|
|
Trivial management of 64 bit virtual machines with qemu.
|
|
|
|
|
|
|
|
Only a single option is accepted.
|
|
|
|
By default, the backup vhd is run.
|
|
|
|
Mandatory arguments to long options are mandatory for short options too.
|
|
|
|
Options:
|
|
|
|
-a, --attach connect via SSH
|
|
|
|
-b, --backup backup the vhd
|
|
|
|
-c, --create create a new vhd
|
|
|
|
-d, --delete delete the vhd backup
|
|
|
|
-h, --help print this help
|
|
|
|
-i, --install install the image on a vhd
|
|
|
|
-m, --mkdir-shared create a shared directory
|
|
|
|
-n, --nox run vm without graphical output
|
|
|
|
-o, --orig run from the original vhd
|
|
|
|
-r, --remote connect to a remote instance of QVM
|
|
|
|
-v, --vnc use VNC
|
|
|
|
-x, --run run the vm
|
|
|
|
|
|
|
|
Exit status:
|
|
|
|
0 if OK,
|
|
|
|
1 if an error occurred.
|
|
|
|
|
|
|
|
CC0 License
|
|
|
|
Written in 2018 by Franco Masotti/frnmst <franco.masotti@live.com>
|
|
|
|
```
|
2019-02-24 19:17:05 +01:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
## Setup information and usage
|
2018-12-27 16:37:24 +01:00
|
|
|
|
2019-01-04 12:02:39 +01:00
|
|
|
### Actions and parameters
|
|
|
|
|
2019-01-09 17:59:34 +01:00
|
|
|
You can make some combinations between actions and places. Both of these
|
|
|
|
elements are parameters.
|
2019-01-04 12:02:39 +01:00
|
|
|
|
|
|
|
#### Actions
|
|
|
|
|
|
|
|
- attach
|
|
|
|
- backup
|
|
|
|
- create
|
|
|
|
- delete
|
|
|
|
- install
|
|
|
|
- mkdir-shared
|
|
|
|
- run
|
|
|
|
|
2019-01-09 17:59:34 +01:00
|
|
|
#### Places
|
2019-01-04 12:02:39 +01:00
|
|
|
|
|
|
|
- nox
|
|
|
|
- origin
|
|
|
|
- remote
|
|
|
|
- vnc
|
|
|
|
|
2018-12-27 16:37:24 +01:00
|
|
|
### Setup
|
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
1. Create a new virtual hard disk and complete the OS installation which
|
|
|
|
can also be done via SSH.
|
2016-11-14 18:02:47 +01:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
$ ./qvm --create && ./qvm --install
|
2016-10-10 17:34:01 +02:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
2. Optionally enable the SSH daemon on the guest machine.
|
|
|
|
3. Optionally create a new backup VHD:
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
$ ./qvm --backup
|
2016-10-08 18:30:05 +02:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
4. Now you can run the virtual machine either using the original or the backup
|
2019-02-24 19:17:05 +01:00
|
|
|
virtual hard disk. If you run `./qvm --run` the virtual machine will run in
|
2019-02-24 12:01:19 +01:00
|
|
|
graphics mode using the backup hard disk.
|
|
|
|
5. Optionally add the following in the guest machine fstab file (`/etc/fstab`),
|
|
|
|
to enable the shared directory automatically. This avoids entering mount
|
|
|
|
commands by hand.
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2019-02-24 12:01:19 +01:00
|
|
|
host_share /home/vm/shared 9p noauto,x-systemd.automount,trans=virtio,version=9p2000.L 0 0
|
2016-11-15 15:00:14 +01:00
|
|
|
|
2018-12-28 19:35:40 +01:00
|
|
|
## Connection to the machine
|
|
|
|
|
2017-10-21 13:28:42 +02:00
|
|
|
- You can also access the virtual machine through SSH:
|
|
|
|
|
2018-12-28 19:19:38 +01:00
|
|
|
$ ./qvm --attach
|
2017-10-21 13:28:42 +02:00
|
|
|
|
|
|
|
or, if you are working on another computer,
|
|
|
|
|
2018-12-28 19:19:38 +01:00
|
|
|
$ ./qvm --attach --remote
|
2017-10-21 13:28:42 +02:00
|
|
|
|
2018-12-27 13:26:08 +01:00
|
|
|
## VNC options
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2017-10-18 11:52:14 +02:00
|
|
|
The VNC options in this script allow you to connect to a remote instance of
|
2019-01-10 13:03:33 +01:00
|
|
|
QEMU. This is particularly useful if, for example, your local machine
|
|
|
|
does not support virtualization.
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2019-02-25 17:49:29 +01:00
|
|
|
*Note: the VNC traffic goes through SSH TCP forwarding, so it is encrypted.*
|
|
|
|
|
2019-01-10 13:03:33 +01:00
|
|
|
### Setup
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2019-02-24 19:17:05 +01:00
|
|
|
For this to work, you must add the following lines in the SSH daemon
|
2019-01-09 18:53:53 +01:00
|
|
|
configuration of the host computer:
|
|
|
|
|
|
|
|
AllowTcpForwarding yes
|
|
|
|
AllowAgentForwarding yes
|
|
|
|
|
2019-01-10 13:03:33 +01:00
|
|
|
### Examples
|
|
|
|
|
|
|
|
You must 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.
|
|
|
|
|
2019-02-24 19:17:05 +01:00
|
|
|
To intall a virtual machine remotely, on the server side you must run:
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2019-02-25 17:49:29 +01:00
|
|
|
$ ./qvm --create && ./qvm --install --vnc
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2019-02-24 19:17:05 +01:00
|
|
|
and on the client side:
|
2017-10-18 11:41:15 +02:00
|
|
|
|
2018-12-28 19:19:38 +01:00
|
|
|
$ ./qvm --attach --remote --vnc
|
2017-10-18 11:41:15 +02:00
|
|
|
|
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
|
|
|
|
2018-12-28 19:35:40 +01:00
|
|
|
## Automatic remote startup
|
2018-01-11 20:15:51 +01:00
|
|
|
|
|
|
|
To automatically start the virtual machine from a non-host computer you can
|
2019-01-04 12:20:38 +01:00
|
|
|
use the `--remote` option. Make sure that both the local
|
|
|
|
(non-host) and the remote host computer have a copy of the QVM repository with
|
2018-01-11 20:15:51 +01:00
|
|
|
the variables correctly set in the `configrc` file.
|
|
|
|
|
|
|
|
This script will start the virtual machine if on the host computer no other
|
2019-01-09 17:59:34 +01:00
|
|
|
virtual machine is running. You can use either a VNC or headless
|
2018-01-11 20:15:51 +01:00
|
|
|
connection. Both of them require that SSH is configured correctly on the
|
2019-01-09 17:59:34 +01:00
|
|
|
computers, i.e. the host must be reachable from the client via SSH.
|
|
|
|
This can be verified by using the `--attach --remote` options while the
|
|
|
|
virtual machine is already running.
|
2018-01-11 20:15:51 +01:00
|
|
|
|
2018-01-12 00:45:06 +01:00
|
|
|
Once you have checked that everyting works, you can add a command alias in
|
|
|
|
your shell configuration file (e.g: `~/.bashrc`), something like:
|
|
|
|
|
2019-01-04 12:20:38 +01:00
|
|
|
alias vm='/home/user/scripts/qvm/qvm --run --remote --vnc'
|
|
|
|
|
2019-02-24 19:17:05 +01:00
|
|
|
because `--remote` implies `--nox` by default. If you don't need VNC:
|
2019-01-04 12:20:38 +01:00
|
|
|
|
|
|
|
alias vm='/home/user/scripts/qvm/qvm --run --remote'
|
2018-01-11 20:15:51 +01:00
|
|
|
|
2018-12-28 19:35:40 +01:00
|
|
|
## Interesting applications
|
|
|
|
|
|
|
|
### Virtual machine hard disk over a network protocol
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2019-02-25 17:34:52 +01:00
|
|
|
## Bugs
|
|
|
|
|
|
|
|
- If you want to use `--remote` and `--vnc` combined, you must first
|
|
|
|
disable any `ControlMaster` and `ControlPath` options associated to the user
|
|
|
|
and host in control of the virtual machine.
|
|
|
|
These options can be found in the client's SSH configuration file which is
|
|
|
|
usually `~/.ssh/config`.
|
|
|
|
|
2018-12-27 13:26:08 +01:00
|
|
|
## License
|
2016-11-06 22:08:59 +01:00
|
|
|
|
2018-12-27 13:05:08 +01:00
|
|
|
Creative Commons Zero (CC0).
|