frnmst-archives
/
qvm
Archived
1
0
Fork 0
Trivial management of 64 bit virtual machines with qemu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

265 lines
8.4 KiB

6 years ago
# qvm
6 years ago
Trivial management of 64 bit virtual machines with qemu.
6 years ago
4 years ago
## Table of contents
[](TOC)
4 years ago
- [qvm](#qvm)
- [Table of contents](#table-of-contents)
4 years ago
- [Reasons](#reasons)
- [Version](#version)
4 years ago
- [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)
- [Bugs](#bugs)
4 years ago
- [License](#license)
[](TOC)
## Reasons
See https://frnmst.gitlab.io/notes/qemu-ssh-tunnel.html
## Version
See all [qvm releases](https://github.com/frnmst/qvm/releases).
4 years ago
## What this script will do
6 years ago
It can handle:
6 years ago
- Virtual hard disk creation, backup and deletion.
4 years ago
- 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.
6 years ago
- Shared directory between host and guest.
4 years ago
- Running the virtual machine with a combination of the previous options.
6 years ago
## Prerequisites
4 years ago
- You need a 64 bit machine with virtualization technology and at least 4 GB
of RAM.
6 years ago
- Modify `configvmrc` based on your needs.
Variables are self-explanatory and I have kept mine
as an example.
## 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 |
|---------|------------|-----------------|-----------------|
2 years ago
| [GNU Bash](https://www.gnu.org/software/bash/bash.html) | `/bin/bash` | `$ bash --version` | `GNU bash, version 5.0.16(1)-release` |
| [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`
| [GNU Coreutils](https://www.gnu.org/software/coreutils/) | `/bin/mkdir`, `/bin/sleep`, `/bin/rm` | `$ ${Executable} --version` | `(GNU coreutils) 8.30` |
## Installation
### Arch Linux based distros
# pacman -S coreutils openssh tigervnc qemu
4 years ago
## Help
```
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>
```
4 years ago
## Setup information and usage
4 years ago
### Actions and parameters
4 years ago
You can make some combinations between actions and places. Both of these
elements are parameters.
#### Actions
- attach
- backup
- create
- delete
- install
- mkdir-shared
- run
4 years ago
#### Places
- nox
- origin
- remote
- vnc
4 years ago
### Setup
1. Create a new virtual hard disk and complete the OS installation which
can also be done via SSH.
$ ./qvm --create && ./qvm --install
2. Optionally enable the SSH daemon on the guest machine.
3. Optionally create a new backup VHD:
$ ./qvm --backup
6 years ago
4. Now you can run the virtual machine either using the original or the backup
4 years ago
virtual hard disk. If you run `./qvm --run` the virtual machine will run in
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.
host_share /home/vm/shared 9p noauto,x-systemd.automount,trans=virtio,version=9p2000.L 0 0
Note: to be able to access the shared directory the user and group ids must
be the same for the host and guest machines. If needed, change those ids within
the guest machine:
1. connect via VNC
2. login as root
3. run: ``# usermod -u ${new_user_id} "${user_name}" && groupmod -g ${new_group_id} "{group_name}"``
4. run: ``# chown -R "${user_name}":"{group_name}" /home/"${user_name}"``
5. reboot
4 years ago
## Connection to the machine
- You can also access the virtual machine through SSH:
4 years ago
$ ./qvm --attach
or, if you are working on another computer,
4 years ago
$ ./qvm --attach --remote
4 years ago
## VNC options
5 years ago
The VNC options in this script allow you to connect to a remote instance of
4 years ago
QEMU. This is particularly useful if, for example, your local machine
does not support virtualization.
4 years ago
*Note: the VNC traffic goes through SSH TCP forwarding, so it is encrypted.*
4 years ago
### Setup
4 years ago
For this to work, you must add the following lines in the SSH daemon
4 years ago
configuration of the host computer:
AllowTcpForwarding yes
AllowAgentForwarding yes
4 years ago
### 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.
4 years ago
To intall a virtual machine remotely, on the server side you must run:
4 years ago
$ ./qvm --create && ./qvm --install --vnc
4 years ago
and on the client side:
4 years ago
$ ./qvm --attach --remote --vnc
5 years ago
At this point you should see your virtual machine running in a TigerVNC window.
4 years ago
## Automatic remote startup
To automatically start the virtual machine from a non-host computer you can
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
the variables correctly set in the `configrc` file.
This script will start the virtual machine if on the host computer no other
4 years ago
virtual machine is running. You can use either a VNC or headless
connection. Both of them require that SSH is configured correctly on the
4 years ago
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.
Once you have checked that everyting works, you can add a command alias in
your shell configuration file (e.g: `~/.bashrc`), something like:
alias vm='/home/user/scripts/qvm/qvm --run --remote --vnc'
4 years ago
because `--remote` implies `--nox` by default. If you don't need VNC:
alias vm='/home/user/scripts/qvm/qvm --run --remote'
4 years ago
## 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.
## 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`.
4 years ago
## License
Creative Commons Zero (CC0).