Thanks to Jetchisel, Malcomlewis, Tsu2 and many others.
- General thoughts
For opensuse and all other distributions if you use qemu/kvm they assume that only an admin with root privileges manage vms with virt-manager and virsh. They don’t supply any doc about how to manage a vm as a user.
I want to use qemu/kvm and to manage my vm as a user.
I just want to manage vms as I manage them with Virtualbox.
I just want to manage a sole vm in my desktop not a farm of vms.
It is an android-x86 7.1-r5 installed in a vm. see https://android-x86.org
This doc assumes that with yast virtualization manager you have already installed kvm.
I use android-x86 7.1-r5 as an example. You must interpret this tuto for your own OS you installed in a vm.
- Creating a vm disk
use this script create a vm disk somewhere in your home.
#!/bin/bash qemu-img create -f qcow2 android_x86_7.1-r5.img 16G
“android_x86_7.1-r5” is the name I decided for the disk
“16G” is the size of the disk, here 16 GB
- Create a vm and install android-x86 7.1-r5
Use this script (I adapted the script supplied by malcom lewis. Perhaps there is some garbage to delete). This script launches the installation iso.
#!/bin/bash qemu-system-x86_64 \ -enable-kvm \ -m 2048 \ -smp 2 \ -cpu host \ -device virtio-tablet-pci \ -device virtio-keyboard-pci \ -serial mon:stdio \ -boot menu=on \ -net nic \ -net user,hostfwd=tcp::5555-:22 \ -vga qxl \ -hda ~/<path to>/android_x86_7.1-r5.img \ -cdrom ~/<path to>/android_x86/android-x86-7.1-r5.iso \
My adaptations :
“-vga qxl” instead of “-device virtio-vga,virgl=on”. Without this I get a black screen after the grub menu.
"-device virtio-tablet-pci " instead of “-device virtio-mouse-pci”. With this I get a seamless capture of the mouse cursor by the vm or the PC.
- Start a vm
use this script
#!/bin/bash qemu-system-x86_64 \ -enable-kvm \ -m 2048 \ -smp 2 \ -cpu host \ -device virtio-tablet-pci \ -device virtio-keyboard-pci \ -serial mon:stdio \ -boot menu=on \ -net nic \ -net user,hostfwd=tcp::5555-:22 \ -vga qxl \ -hda ~/<path to>/android_x86_7.1-r5.img \
- Some notes
At this step we get a working vm.
This vm uses nat networking and there is no problem to use internet.
The vm is not a member of the LAN. It is masked inside the host. The IP address is something as 10.0.2.15. This is a problem for some app as kdeconnect. This app needs the vm is a member of the LAN or at least not masked.
- Create a vm using bridge networking (thus creating a bridge).
Importing the vm is a good thing because you will be able to make tests with your vm and understand all the components of your vm. This help to find the good settings for using your vm with qemu-kvm.
Import in virt-manager environment the vm.
For this in virt-manager add a new vm doing:
choose to import the existing image “~//android_x86_7.1-r5.img”. You need to add the folder containing the .img.
as OS indicate “android 7.1” then choose “Generic”
2048 MB memory
choose a name for the vm
check “custom settings”
choose for the network “:macvtap”, automatically “bridge” is set. Don’t touch this.
for example “eth0”
check your settings (memory, cpus, nic)
click on “begin the installation”
- Enabling the bridge
in main window of virt-manager
- select the vm
- in “edition” menu select “connection details”
then “virtual networks”
check “autostart” “at boot”
check that “virbr0” the bridge is enabled. If not click on the arrow at the bottom left.
quit “connection details”
go to networkmanager. Ask for it to show virtual connections then you’ll see the “virbr0” connection.
in virt-manager select the vm and launch it.
you get now a vm using bridge networking and getting some IP address as 192.168.0.x
Now execute in a host console “ping 192.168.0.x”. You get some answers.
go to networkmanager. Ask for it to show virtual connections then you’ll see the “macvtap0” virtual connection.
The vm gets 192.168.0.x and your PC 192.168.0.y as IP address. It is the same LAN.
To establish an in-going connection to the host from the vm, perhaps you need to open a port in your host firewall.
Close the vm and quit virt-manager.
- using bridge networking with qemu-kvm (in our case qemu-system-x86_64)
At this step we get a bridge “virbr0” and we know it works well.
How to use it with qemu-kvm ?
sudo zypper in tunctl bridge-utils
Give all the accesses for using the bridge to users:
- in /etc/qemu/bridge.conf add the statement
- change the acl of bridge.conf
sudo chown root:kvm /etc/qemu/bridge.conf
sudo chmod 0660 /etc/qemu/bridge.conf
- change the acl of qemu-bridge-helper
sudo chmod u+s /usr/lib/qemu-bridge-helper
- i also read this somewhere but i don’t tried it because i found a solution and i am fed up with this problem:
sudo chown qemu:kvm /etc/qemu/bridge.conf
sudo chmod 0640 /etc/qemu/bridge.conf
- with yast user manager
put your user-id to kvm group
- launching a vm using a bridge with qemu-kvm
use this script
#!/bin/bash qemu-system-x86_64 \ -enable-kvm \ -m 2048 \ -smp 2 \ -cpu host \ -device virtio-tablet-pci \ -device virtio-keyboard-pci \ -serial mon:stdio \ -boot menu=on \ -net nic \ -net bridge,br=virbr0 \ -vga qxl \ -hda ~/<path to>/android_x86_7.1-r5.img \
You can check that the vm get 192.168.122.x and your PC 192.168.0.y as IP address. It is not the same LAN, but it is sufficient to establish connections. Again perhaps you need to open port at your host.
You can check in networkmanager there is a new virtual connection “tap0”.
I did not find a way for the vm to use the same dhcp server as the host one according to get an IP address as 192.168.0.x.