Git Product home page Git Product logo

virter's Introduction

Virter

Virter is a command line tool for simple creation and cloning of virtual machines.

Virter supports VMs running standard general purpose distributions such as CentOS and Ubuntu. It is especially useful for development and testing of projects which cannot use containers due to kernel dependencies, such as DRBD and LINSTOR.

Quick Start

First install and set up libvirt. Then download one of the releases. Virter is packaged as a single binary, so just put that into /usr/local/bin and you are ready to use Virter:

virter image pull alma-8 # also would be auto-pulled in next step
virter vm run --name alma-8-hello --id 100 --wait-ssh alma-8
virter vm ssh alma-8-hello
virter vm rm alma-8-hello

In the above example, the virter "ID" is the index into the possible IPs within the IP range of the network definition. For a typical 192.x.y.z/24 net definition, the virter "ID" would be z, or 100 in this case.

Depending on your host distribution and libvirt installation, you may need to:

Usage

For usage just run virter help.

Additional options that may be helpful when using virter vm run:

  • List all available images: virter image ls --available

  • Using a provisioning file: --provision /root/alma8.toml

  • Adding additional disk(s): --disk "name=disk1,size=20GiB,format=qcow2,bus=virtio"

  • Adding a bridged interface --nic "type=bridge,source=br0,mac=1a:2b:3c:4d:5e:01"

  • Adding a NAT'ed interface: --nic "type=network,source=default,mac=1a:2b:3c:4d:5e:01"

Other examples are provided in the examples directory. See the README files for the individual examples.

There is also additional documentation for the provisioning feature. This is useful for defining new images. These images can be used to start clusters of cloned VMs.

Installation Details

Virter requires:

  • A running libvirt daemon on the host where it is run
  • When container provisioning is used: A container runtime. Currently, Virter supports docker and podman.

Configuration is read by default from ~/.config/virter/virter.toml.

When starting Virter for the first time, a default configuration file will be generated, including documentation about the various flags.

Container runtime

Select the container runtime by setting container.provider to either docker or podman.

podman

Virter communicates with podman via it's REST-API. Make sure the API socket is available.

This may be done by:

  • Starting podman via systemd: systemctl --user start podman.socket (use systemctl --user enable --now podman.socket to make this permanent)
  • Start podman manually: podman system service

Network domain

If you require DNS resolution from your VMs to return correct FQDNs, add the domain to your libvirt network definition:

<network>
  ...
  <domain name='test'/>
  ...
</network>

By default, Virter uses the libvirt network named default.

Check out doc/networks.md for more details on VM networking.

Connecting with ssh

SSH can be configured for convenient access to virtual machines created by Virter. See doc/ssh.md for details.

DHCP Leases

Libvirt produces some weird behavior when MAC or IP addresses are reused while there is still an active DHCP lease for them. This can result in a new VM getting assigned a random IP instead of the IP corresponding to its ID.

To work around this, Virter tries to execute the dhcp_release utility in order to release the DHCP lease from libvirt's DHCP server when a VM is removed. This utility has to be run by the root user, so Virter executes it using sudo.

If execution fails (for example because the utility is not installed or the sudo rules are not set up correctly), the error is ignored by Virter.

So, to make Virter work more reliably, especially when you are running lots of VMs in a short amount of time, you should install the dhcp_release utility (usually packaged as dnsmasq-utils). Additionally, you should make sure that your user can run dhcp_release as root, for example by using a sudo rule like this:

%libvirt ALL=(ALL) NOPASSWD: /usr/bin/dhcp_release

This allows all users in the group libvirt to run the dhcp_release utility without being prompted for a password.

Console logs

The --console argument to virter vm run causes serial output from the VM to be saved to a file. This file is created with the current user as the owner. However, it is written to by libvirt, so it needs to located on a filesystem to which libvirt can write. NFS mounts generally cannot be used due to root_squash.

In addition, when the VM generates a lot of output, this can trigger virtlogd to roll the log file over, which creates a file owned by root (assuming virtlogd is running as root). To prevent this, increase max_size in /etc/libvirt/virtlogd.conf.

libvirt storage pool

Virter requires a libvirt storage pool for its images and VM volumes. By default, it expects a pool named default. Some libvirt distributions configure this pool automatically. Some, such as the standard packages on Ubuntu Focal, do not. If the pool does not exist, create it like this:

virsh pool-define-as --name default --type dir --target /var/lib/libvirt/images
virsh pool-autostart default
virsh pool-start default

AppArmor

On some distributions, AppArmor denies access to /var/lib/libvirt/images by default. This leads to messages in dmesg along the lines of:

[ 4274.237593] audit: type=1400 audit(1598348576.161:102): apparmor="DENIED" operation="open" profile="libvirt-d84ef9d7-a7ad-4388-bd5d-cfc3a3db28a6" name="/var/lib/libvirt/images/centos-8" pid=14918 comm="qemu-system-x86" requested_mask="r" denied_mask="r" fsuid=64055 ouid=64055

This can be circumvented by overriding the AppArmor abstraction for that directory:

cat <<EOF >> /etc/apparmor.d/local/abstractions/libvirt-qemu
/var/lib/libvirt/images/* rwk,
# required for QEMU accessing UEFI nvram variables
/usr/share/OVMF/* rk,
owner /var/lib/libvirt/qemu/nvram/*_VARS.fd rwk,
owner /var/lib/libvirt/qemu/nvram/*_VARS.ms.fd rwk,
EOF
systemctl restart apparmor.service
systemctl restart libvirtd.service

Architecture

Virter connects to the libvirt daemon for all the heavy lifting. It supplies bootstrap configuration to the VMs using cloud-init volumes, so that the hostname is set and SSH access is possible.

Building from source

If you want to test the latest unstable version of Virter, you can build the git version from sources:

git clone https://github.com/LINBIT/virter
cd virter
go build .

Comparison to other tools

virsh

Virter is good for starting and cloning cloud-init based VMs. virsh is useful for more detailed libvirt management. They work well together.

virt-install

virt-install is built for images that use conventional installers. Virter uses cloud-init, making it simpler to use and quicker to start a fresh VM.

Running VMs in AWS/GCP/OpenNebula

Virter is local to a single host making snapshot/restore/clone operations very efficient. Virter could be thought of as cloud provisioning for your local machine.

Vagrant

Virter and Vagrant have essentially the same goal. Virter is more tightly integrated with the Linux virtualization stack, resulting in better snapshot/restore/clone support.

Multipass

Virter and Multipass have similar goals, but Multipass is Ubuntu specific.

Docker

Virter is like Docker for VMs. The user experience of the tools is generally similar. Docker containers share the host kernel, whereas Virter starts VMs with their own kernel.

Kata Containers

Virter starts VMs running a variety of Linux distributions, whereas Kata Containers uses a specific guest that then runs containers.

Weave Ignite

Ignite has very strong requirements on the guest, so it cannot be used for running standard distributions.

Development

Virter is a standard go project using modules. Go 1.13+ is supported.

virter's People

Contributors

joelcolledge avatar chrboe avatar wanzenbug avatar rck avatar johannesthoma avatar rp- avatar brhellman avatar folliehiyuki avatar alrs avatar bashfulrobot avatar

Stargazers

kisun avatar Peter Nagy avatar Vlad Petrov avatar  avatar  avatar  avatar Ildar Manzhikov avatar Mert Sayın avatar  avatar Michael Troutman avatar mingming.zhou avatar Seth Grover avatar  avatar Sergei Lukianov avatar Shayon avatar Ernad Husremović avatar 羡鱼 avatar Andrei Kvapil avatar 9r0k avatar Vicente Maroto Garzón avatar Will Gorman avatar Christopher Jones avatar Ole Kristian Skramstad avatar Dv Lv avatar Curious avatar  avatar peroksid5 avatar Sandalots avatar nodiscc avatar Bryan A. S. avatar Valentin Hăloiu avatar Duminda Kaviranga Gunawardhana avatar Giacomo Venturini avatar Mattia Nicolella avatar BlauFx avatar  avatar Arvid Gerstmann avatar Lukas M avatar Zhao Xiaohong avatar  avatar Nikita avatar Guillaume Gelin avatar Oz Tiram avatar Pranav Dave avatar Remy avatar  avatar adam kaminski avatar Ian Trudel avatar kohane27 avatar Patryk avatar Jonathan Scherrer avatar  avatar Tony Franzese avatar Kareem H avatar Ananth avatar ghosti3 avatar  avatar Aws Ismail avatar Przemek Grondek avatar Hovakim Grabski avatar Sam James avatar Mandy Schoep avatar Leroy van Logchem avatar Daniel Barnes avatar John Holowczak avatar  avatar Tobias Gruetzmacher avatar  avatar Solvik avatar Matias Mortara avatar  avatar Tim Sogard avatar  avatar  avatar Mikael avatar Denys Zheliezniak avatar  avatar  avatar Ethan Larkham avatar Ilya guterman avatar Mohammed Besar avatar Dawid Dziurla avatar Bryce Torcello avatar Benjamin Vujnovac avatar Alexandra avatar Mohamad Safadieh avatar OneFreemanWill avatar Diego Veralli avatar Alex A. avatar Nicolas Vincent avatar  avatar Ian Eyberg avatar Elias Roa avatar Andrew Brown avatar John Adams avatar Michael Lohrer avatar Ian Mustafa avatar Albert Fung avatar Hasan Hakkaev avatar  avatar

Watchers

Lars Ellenberg avatar James Cloos avatar  avatar  avatar  avatar Matt Kereczman avatar Kostas Georgiou avatar  avatar

virter's Issues

virter vm cp only works when ssh is located at /usr/bin/ssh

Hi there, I am not sure what I am doing wrong.

λ virter vm cp --help
Copy files and directories from and to VM

Usage:
  virter vm cp [HOST:]SRC... [HOST:]DEST [flags]

Flags:
  -h, --help   help for cp

Global Flags:
      --config string      config file (default is /home/dustin/.config/virter/virter.toml)
      --logformat string   Log format, current options: short (default "default")
  -l, --loglevel string    Log level, default may be set with environment variable "VIRTER_LOG_LEVEL" (default "info")

So looking at this help output, I assume it is VM to VM copying.

So I tried:

λ virter vm cp r1:~/config.yaml r2:/root
FATA[0000] error executing rsync: exit status 1

and

λ virter vm cp r1:/root/config.yaml r2:/root
FATA[0000] error executing rsync: exit status 1

The file exists, so I am not sure what I am missing here, and I could not find anything on your page.

Thank you.

EDIT - Clarifying, host to vm, and vm to host do not work either. More info in this comment.

Change size of the primary disk

Looking at the readme, there does not seem to be a way to change the primary disk size. The only disk-related command was --disk "name=disk1,size=20GiB,format=qcow2,bus=virtio" which seems to add a secondary disk. Can you specify the disk size when you provision a VM?

SELinux permissions errors in container provisioner

Using containers which read any mounted volume fails if SELinux is in enforcing mode.
This could be fixed by using the Z flag for container volumes but it may not be the perfect solution since it relabels the SELinux files/directories of the workspace. This is supported by both docker and podman. Another option could be disabling labels entirely using --security-opt label=disable, which is something other tools which wrap around a container engine like distrobox do.

Add SSH wait

Add vm run option to wait until SSH in the VM is ready. Probably just try to open TCP connection to port 22. On by default?

removing an image name with "--" issue

Hi there. Dumb moves on my part.

When I was playing with images, before finding the default image names, I ran virter image pull https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img not specifying a name. This resulted in an image named "--cloud-images.ubuntu.com--jammy--current--jammy-server-cloudimg-amd64-disk-kvm.img-latest".

Now when I tried to remove it (virter image rm --cloud-images.ubuntu.com--jammy--current--jammy-server-cloudimg-amd64-disk-kvm.img-latest), my shell (tried both fish and bash) complains about the flag not found. Ok. Expected. I tried quoting the name (' & ") and escaping as well. Same result.

So then I tried to remove the files in /var/lib/libvirt/images. That causes its own issues (failed to get the top layer). So I recreated them.

What is the best way to get around this? Or to manually clear out these entries (deleting in images does not do it completely).

A small suggestion might be to enforce either specifying the name or creating a more sane default without -- (or special characters) at the beginning. TBH, I am stumped why quoting is not working.

Thank you.

vm run results in a non bootable device

Hi there. I launched a vm with virter vm run --name tester --vcpus 4 --memory 4096 --bootcapacity 100G --id 100 --vnc ubuntu-jammy, but for some reason, when I check the console, it shows the device as not being bootable?

image

listing deployed VMS

Hi there. Is there a way to list deployed VMs and their running state? I would have expected a virter vm ls (for running), and a virter vm ls --available (for all deployed - including powered off, or error state) following the pattern of your virter image ls.

I also had a look at virter VM exists [name]. But it seems to need a specific VM name entered. Oddly enough it did not return any feedback when run against a VM I created in virter.

Is there a preferred way to ask questions for things like this that I do not see in the docs? I did not notice any discussions enabled on this repo, etc. I also want to be respectful of your issues and not clog it all up.

Thanks for the awesome tool.

help please, error start vm: invalid argument: could not find capabilities for arch=x86_64 domaintype=kvm

error with centos7 bare-metal:

[root@host23-69 ~]# uname -a
Linux host23-69 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

[root@cent7-23-191 virter]# virter vm run --name alma-8-hello --id 100 --wait-ssh alma-8
INFO[0000] Create host key                              
INFO[0000] Define VM                                    
FATA[0000] Failed to start VM 100: could not define domain: invalid argument: could not find capabilities for arch=x86_64 domaintype=kvm 

How to view valid image names?

Hi there. In your readme you have the command virter image pull alma-8. How can you see the valid images to use? I know I can do something like ./virter image pull ubuntu2204 https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img. Is that the intended way? Populate our own?

Thank you.

Make graphics requirement configurable in image registry

A video device is currently included in the VM template, because the Debian 9 OpenStack image doesn't start without it. However, startup should be slightly faster without graphics. So we should turn off graphics unless indicated otherwise in the image registry.

Add image build command

This combines vm run (with SSH wait #1), some provisioning, and vm commit (with shutdown #2). There are various options for the provisioning stage. Running a docker container on the host is a very powerful and generic option, so start with that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.