User virtual machines on VLAB servers

From techdocs
Revision as of 10:25, 8 Haziran 2023 by Plinich (talk | contribs) (→‎vmexec)
Jump to navigation Jump to search

Proposed user-defined virtual machine setup for VLAB servers. Not operational.

Implement and run user-defined virtual machines (VM).

TL;DR

  • VMs run as X86_64 Kernel Virtual Machines (KVM) under qemu.
  • Virtual hard disk files and and CD/ISO image files *must* be in user subdirectories somewhere under the directory listed below.
  • Virtual hard disk files must be in qcow2 format.
  • qemu-img is used to create virtual hard disk files.
  • vmexecmkdir is used to create a user subdirectory on a host if one doesn't already exist.
  • vmexec VMs on a host.

CD/ISO files and virtual hard disk files location

The CD/ISO files and virtual hard disk files used by the user-created virtual machines must actually be located somewhere under:

  • /usr/local/uservms

on the host where the VMs will be run. If not, vmexec will give an error when trying to run the VM. Symlink-ing to locations outside of this directory will cause the same error.

Typically, users will have their own subdirectories under this directory.

Programs

Program name Description
qemu-img Create a virtual hard disk (file). Can use a pre-existing disk file, say from a class account, as a starting point.
vmexecmkdir Create a user subdirectory for VM disk images and ISO files.
vmexec Run a virtual machines, booting either from a supplied CD/ISO image or from virtual hard disk.

qemu-img

See the man page, but...

qemu-img -f qcow2 <disk_file_path> 20G

will create an empty 20G QCOW2 disk.

And:

qemu-img -f qcow2 -b <base_file_path> <disk_file_path>

creates a disk whose initial contents are based on the given base disk image (such as in a class account). The size of the created disk will be that specified when the base file was created.

vmexecmkdir

Create a user subdirectory for ISO files and virtual hard disk files (see location above).

Usage: vmexecmkdir [options]

-h  Display this help
-c  Create user directory in <see above>

vmexec

Usage: vmexec [options] [<disk0> [<disk1> ...]]

-h           Display this help
-m <n>       RAM megabytes (128/2048 - default 1024)
-n <n>       Number of virtual CPUs (1/2 - default 1)
-i <isopath> CD/ISO file path
-d           Boot from CD/ISO

<diskn>      Virtual hard disk path

vmexec runs a user-defined virtual machine using qemu/KVM.

  • The machine will be configured for "user" networking, meaning it will be on its own private subnetwork. It will be able to connect externally using Network Address Translation (NAT) but will not be reachable itself from external hosts, including from the host the virtual machine is running on. The VM will see the network interfaces as an Intel E1000 card.
  • It will have a graphical console.
  • The [virtual] CPU will be Intel. There can be a maximum of TWO per VM.
  • Disk and ISO paths can be absolute, or relative to the location given above.

Scribbles

Installing qemu-system-x86_64 package on nw-syd-armvx1:

Start-Date: 2023-06-01  14:04:59
Commandline: apt-get install qemu-system-x86
Install: qemu-system-x86:arm64 (1:5.2+dfsg-11+deb11u2), ovmf:arm64 (2020.11-2+deb11u1, automatic), libcapstone4:arm64 (4.0.2-3, automatic), libvdeplug2:arm64 (4.0.1-2, automatic), libbrlapi0.8:arm64 (6.3+dfsg-1+deb11u1, automatic), libexecs0:arm64 (1.3-1, automatic), libspice-server1:arm64 (0.14.3-2.1, automatic), ipxe-qemu:arm64 (1.0.0+git-20190125.36a4c85-5.1, automatic), libusbredirparser1:arm64 (0.8.0-1+b1, automatic), seabios:arm64 (1.14.0-2, automatic), libcacard0:arm64 (1:2.8.0-3, automatic), qemu-system-common:arm64 (1:5.2+dfsg-11+deb11u2, automatic), libvirglrenderer1:arm64 (0.8.2-5+deb11u1, automatic), qemu-system-data:arm64 (1:5.2+dfsg-11+deb11u2, automatic), qemu-system-gui:arm64 (1:5.2+dfsg-11+deb11u2, automatic)
End-Date: 2023-06-01  14:05:04