John Siu Blog

Tech - Business Tool, Personal Toys

Alpine KVM

☰ Table of Content

Setup libvirt/KVM on a remote Alpine Linux server and connect virsh/virt-manager from remote.

Alpine server is assumed to have no GUI capability. All steps are done through remote connection.


Install KVM

Note:

  • This part is a streamline version of Alpine KVM wiki page.
  • No virt-manager on remote Alpine server. You only need it on your local machine.
  • Assume VMs bridge-mode using macvtap. bridge package not required.
  • Use root or sudo for all commands in this section.

Add KVM packages:

1
2
apk add libvirt-daemon qemu-img qemu-system-x86_64 polkit
rc-update add libvirtd

Add user to group libvirt:

1
addgroup <user> libvirt

Allow libvirt group to access /var/run/libvirt/libvirt-sock:

1
mkdir -p /etc/polkit-1/localauthority/50-local.d

Create /etc/polkit-1/localauthority/50-local.d/50-libvirt-ssh-remote-access-policy.pkla with following content:

1
2
3
4
5
6
[Remote libvirt SSH access]
 Identity=unix-group:libvirt
 Action=org.libvirt.unix.manage
 ResultAny=yes
 ResultInactive=yes
 ResultActive=yes

At this point virt-manager and virsh can connect from remote and takeover completely.

Remote Management

virsh and virt-manager can be used to manage KVM remotely.

virsh is the command line tool that can manage libvirt/KVM directly on the host or from remote.

virt-manager is the GUI interface.

Local connection (on Alpine server)

From libvirt group user:

Interactive mode:

1
virsh -c qemu:///system

Command line / batch mode

1
virsh -c qemu:///system net-list --all

Remote connection

NOTE: user@hostname will be the same string for ssh to the libvirt group user on Alpine host. SSH key should be setup already.

Linux
1
2
3
4
5
virt-manager -c qemu+ssh://user@hostname/system

virsh -c qemu+ssh://user@hostname/system

virsh -c qemu+ssh://user@hostname/system net-list --all
MacOS

Check out MacOS Connect to KVM Client Desktop for running virt-manager to remote manage and connect KVM on MacOS.

John Siu

Update: 2022-05-12
comments powered by Disqus