Why do I get a permissions error when starting a KVM VM with a TAP interface? - virtualization

1st Post, thanks for the community.
Apologies if it is better suited in another forum
I am running Ubuntu 12.04 LTS Server as my host.
/etc/libvirt# kvm --version
QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice Bellard
I built out a VM running Ubuntu 13.10 just fine.
When I went into the XML to configure an ethernet tap0 interface for a static IP I have run into troubles.
I have scoured the net and tried several things, to no avail.
Here is the error I get.
Beneath the error is my config and my log.
Beneath that are the list of things I have tried and not had success with...
-# virsh start phabVM
error: Failed to start domain phabVM
error: internal error Process exited while reading console log output: char device redirected to /dev/pts/1
kvm: -netdev tap,ifname=tap0,id=hostnet0: could not open /dev/net/tun: Operation not permitted
kvm: -netdev tap,ifname=tap0,id=hostnet0: Device 'tap' could not be initialized
VM XML
# domain type='kvm'>
# name>phabVM
# uuid>26a54ab3-7c67-507b-f066-09015dd19942
# memory>4194304
# currentMemory>4194304
# vcpu>1
# os>
# type arch='x86_64' machine='pc-1.0'>hvm
# boot dev='hd'/>
# /os>
# features>
# acpi/>
# apic/>
# pae/>
# /features>
# clock offset='utc'/>
# on_poweroff>preserve
# on_reboot>restart
# on_crash>restart
# devices>
# emulator>/usr/bin/kvm
# disk type='file' device='disk'>
# driver name='qemu' type='raw'/>
# source file='/home/inevirt/images/PhabVM.img'/>
# target dev='sda' bus='sata'/>
# address type='drive' controller='0' bus='0' unit='0'/>
# /disk>
# disk type='block' device='cdrom'>
# driver name='qemu' type='raw'/>
# target dev='hdc' bus='ide'/>
# readonly/>
# address type='drive' controller='0' bus='1' unit='0'/>
# /disk>
# controller type='ide' index='0'>
# address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
# /controller>
# controller type='sata' index='0'>
# address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
# /controller>
# interface type='ethernet'>
# mac address='52:54:00:6d:ab:17'/>
# target dev='tap0'/>
# model type='virtio'/>
# address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
# /interface>
# serial type='pty'>
# target port='0'/>
# /serial>
# console type='pty'>
# target type='serial' port='0'/>
# /console>
# input type='mouse' bus='ps2'/>
# graphics type='vnc' port='-1' autoport='yes'/>
# sound model='ich6'>
# address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
# /sound>
# video>
# model type='cirrus' vram='9216' heads='1'/>
# address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
# /video>
# memballoon model='virtio'>
# address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
# /memballoon>
# /devices>
#/domain
LOG
2013-11-21 17:38:59.075+0000: starting up
LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin QEMU_AUDIO_DRV=none /usr/bin/kvm -S -M pc-1.0 -enable-kvm -m 4096 -smp 1,sockets=1,cores=1,threads=1 -name PhabVM -uuid 26a54ab3-7c67-507b-f066-09015dd19942 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/PhabVM.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -device ahci,id=ahci0,bus=pci.0,addr=0x5 -drive file=/home/inevirt/images/PhabVM.img,if=none,id=drive-sata0-0-0,format=raw -device ide-drive,bus=ahci0.0,drive=drive-sata0-0-0,id=sata0-0-0,bootindex=1 -drive if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,ifname=tap0,id=hostnet0 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:6d:ab:17,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb -vnc 127.0.0.1:0 -vga cirrus -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
char device redirected to /dev/pts/1
kvm: -netdev tap,ifname=tap0,id=hostnet0: could not open /dev/net/tun: Operation not permitted
kvm: -netdev tap,ifname=tap0,id=hostnet0: Device 'tap' could not be initialized
2013-11-21 17:38:59.205+0000: shutting down
2013-11-21 17:40:57.554+0000: starting up
LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin QEMU_AUDIO_DRV=none /usr/bin/kvm -S -M pc-1.0 -enable-kvm -m 4096 -smp 1,sockets=1,cores=1,threads=1 -name PhabVM -uuid 26a54ab3-7c67-507b-f066-09015dd19942 -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/PhabVM.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -device ahci,id=ahci0,bus=pci.0,addr=0x5 -drive file=/home/inevirt/images/PhabVM.img,if=none,id=drive-sata0-0-0,format=raw -device ide-drive,bus=ahci0.0,drive=drive-sata0-0-0,id=sata0-0-0,bootindex=1 -drive if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -netdev tap,ifname=tap0,id=hostnet0 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:6d:ab:17,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb -vnc 127.0.0.1:0 -vga cirrus -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
char device redirected to /dev/pts/1
kvm: -netdev tap,ifname=tap0,id=hostnet0: could not open /dev/net/tun: Operation not permitted
kvm: -netdev tap,ifname=tap0,id=hostnet0: Device 'tap' could not be initialized
2013-11-21 17:40:57.686+0000: shutting down
Things I have tried (from internet research) that have not worked.
Added user to group kvm
Config'ed libvirtd.conf and uncommented listen_tls and listen_tcp
Config'ed qemu.conf by setting root as user/group to run VMs & uncommented clear_emulator_capabilities = 0
Disabled apparmor
Ensured kvm binary was set to kvm group

Try not to use <interface type="ethernet">, there are many more various possibilities to use for network interfaces that are more secure, easily managed, etc. If you really need to use ethernet type of interface, then you can follow the libvirt wiki page exactly about that issue, but I must stress out I don't recommend that.

Related

How can I expose qemu-guest-agent QMP capabilities to the qmp tcp server in qemu?

I'm using qemu-system-x86_64 to run a vm exposing QMP commands via TCP connection in this way:
qemu-system-x86_64 \
-smp 4 -m 4096 \
-vga std \
-display vnc=:0 \
-netdev user,id=n0 \
-device e1000,netdev=n0 \
-usb -device usb-tablet \
-qmp tcp:localhost:8124,server,nowait \
-k en-us \
-boot d \
-hda /filesystem/filesystem.img
Everything is ok, because I can send QMP commands to qemu locally via TCP socket connection on port 8124.
Then I installed qemu-guest-agent on the vm (Ubuntu 21.04 desktop) and I created the virtio ports required by the quemu-guest-agent service in this way:
qemu-system-x86_64 \
-smp 4 -m 4096 \
-vga std \
-display vnc=:0 \
-netdev user,id=n0 \
-device e1000,netdev=n0 \
-chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-usb -device usb-tablet \
-qmp tcp:localhost:8124,server,nowait \
-k en-us \
-boot d \
-hda /filesystem/filesystem.img
quemu-guest-agent systemd service is up and running as expected (obviously on a local socket, not via TCP).
Now I want to see qemu-guest-agent QMP capabilities via TCP socket connection.
How can I achieve this?
Based on the official guide I have to change chardev in this way -chardev qga_proxy,id=qga0 \ but it's not working. It seems an obsolete info in that guide, because this command is not supported today. It throws error: qemu-system-x86_64: -chardev qga_proxy,id=qga0: 'qga_proxy' is not a valid char driver name
Which is the correct way to expose guest-agent QMP commands through TCP socket?
Thank you.
You simply need to associate the virtio serial device with a TCP chardev.
Iow, replace:
-chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 (unix socket) with
-chardev socket,id=qga0,host=localhost,port=9876,server=on (tcp socket).
Fwiw, qga_proxy never happened, it was just some sketchy ideas on the wiki.

Emulating Raspberry Pi 4 with QEMU?

I want to emulate Raspberry Pi 4 using QEMU, but I am not able to find any image for RPi4. I need a kernel with which QEMU can emulate a Cortex-A72.
QEMU does not have a model of the raspberry pi 4 at this time (only the 0, 1ap, 2b, 3ap and 3b). If some other machine type that QEMU does support would be good enough for you you could build a kernel for that machine type and use that. (For instance, for a lot of people all they really want is "boots a 64-bit Linux userspace" and they don't need it to really exactly match the Raspberry Pi board hardware; for those people the 'virt' board is usually a good choice.)
Whatever you do, you need to make sure that the machine type you ask QEMU to emulate matches the machine type you've built the kernel for -- if you try to boot a kernel on a board that it does not support it will not work.
I just boot raspios bullseye on a x86 ubuntu laptop, it can show the desktop, can be login in. But it's very slow.
qemu-system-aarch64 -M virt,highmem=off -smp 8 -m 2G -cpu cortex-a72 -kernel linux-stable/arch/arm64/boot/Image -append root=PARTUUID=d97f5830-02 rw console=ttyAMA0 -serial telnet:localhost:4321,server,nowait -monitor telnet:localhost:4322,server,nowait -device VGA,id=vga1 -device secondary-vga,id=vga2 -object iothread,id=io1 -device virtio-blk-pci,drive=disk0,iothread=io1 -drive data/images/2022-01-28-raspios-bullseye-arm64.img
I build the kernel image follow this guide.
https://github.com/anholt/linux/wiki/Raspberry-Pi-development-environment#building-the-Kernel
Of course, as the raspios is emulated on the x86 laptop, it's definitely slow. So, if you can virtualize it on an arm64 host, you can use the accelerator like kvm, hvf etc.
qemu-system-aarch64 \
-M virt,highmem=off,accel=hvf \
-cpu host \
-m 1G \
-smp 4 \
-kernel $KERNEL_IMAGE_PATH -append "root=/dev/vda2 rw console=ttyAMA0" \
-netdev user,id=n1,ipv6=off,hostfwd=tcp::5555-:22 -device e1000,netdev=n1 \
-hda data/images/2022-01-28-raspios-bullseye-arm64.img \
-serial telnet:localhost:4321,server,nowait \
-monitor telnet:localhost:4322,server,nowait \
-device VGA,id=vga2 \
-drive file=data/images/2021-10-30-raspios-bullseye-armhf.img,if=virtio
there is a patch here if you want.
You can compile qemu with raspi4b2g
(Patch not from me)
https://github.com/0xMirasio/qemu-patch-raspberry4.git
or try the following branch (2019), which may or maynot be patch equivalent to that already mentioned:
https://gitlab.com/philmd/qemu/-/tree/raspi4_wip

Enable Virt Machine Graphics in qemu-system-aarch64 running on Windows X86-64 Host

I am emulating an aarch64 platform using qemu. I have successfully installed ubuntu server for arm64 (16.04 LTS). I want to enable machine graphics for the 'virt' machine type. I have followed the instructions here. However, that does not work.
Apart from the graphics, all else works. Also, I have installed mint desktop on the Ubuntu installation. All I require is the graphics display, please.
Here's my code:
qemu-system-aarch64 -cpu cortex-a53 -M virt -m 2048 -device virtio-gpu-pci -device virtio-blk-device,drive=hd0 -drive if=pflash,format=raw,file=QEMU_EFI.img -drive if=pflash,file=varstore.img -drive if=none,file=ubuntu.img,id=hd0
When I run this, I get a virtio-gpu display but once the bios loads, it shows "Guest disabled display". Could you please point me to what's wrong? Thanks.
Same issue on Ubuntu 20.04 host with Ubuntu 20.04 image.
But there is no such issue with CentOS 8 image which can be find here https://cloud.centos.org/centos/8/aarch64/images/
So it can be related to image software or settings.
You can access running VM via virsh console vmName to try change something inside VM.
And also it can be a bug in QEMU :-) - https://bugzilla.redhat.com/show_bug.cgi?id=1661288
you can perhap's try multiple video devices, and after boot select them in the view menu
qemu-system-aarch64 -machine virt -smp 8 -m 4G -cpu cortex-a72 -serial stdio -bios /usr/share/edk2/aarch64/QEMU_EFI.fd -drive if=none,file=./Mageia-8-rpi-aarch64-noDE.img,format=raw,id=hd -device qemu-xhci -device usb-storage,drive=hd -boot menu=on -device qxl -display gtk,gl=on -device virtio-gpu-pci -writeconfig rpi4

How to attach a block device to qemu VM through qemu command line?

I want to configure the qemu to attach a specific block device to the VM?
Following is the command I am using now:
qemu-system-x86_64 -enable-kvm -machine type=pc,accel=kvm
-cpu host -nographic -k de -usb -m 2048
-net nic -net user,hostfwd=tcp::3388-:22
ubuntu16.04.qcow2
I know that following is the virsh command to do this:
virsh attach-disk ubuntuVM /dev/vdb
But I want to specify this in the above command line (Don't want to use virsh). Does anyone know how to do this?
Kind Regards
Simply add the following option to your command:
-drive file=/dev/sdd,format=raw,if=virtio
This will add a drive, the file parameter can also point to block devices, be sure to set the format parameter to "raw".
Additionally you can set the if parameter to "virtio" if the guest supports it (via module or driver) for better performance.

How to make sure a xen DomU is HVM or PV

i used virt-install to create a DomU image, but i cannot make sure the DomU created is a HVM or a PV.....anyone has any ideas?
On Citrix XenServer 6.2, looking at all the parameters of the VM you'll see refferences to PV or HVM:
# xe vm-list name-label=myVM params=all|grep PV-[kd]
PV-kernel ( RW):
PV-drivers-version (MRO): major: 6; minor: 2; micro: 0; build: 70442
PV-drivers-up-to-date ( RO): true
It turns out, in case of a linux VM, you can see if its PV:
[myVM]$ dmesg | egrep "Booting|Xen ver"
Booting paravirtualized kernel on Xen
Xen version: 4.1.5 (preserve-AD)
I'm not quite sure why PV-kernel does not reflect this. For more details see
determine-which-guest-is-running-on-xen-hvm-or-pv-guest and
is-there-an-os-command-i-can-run-to-determine-if-running-inside-a-xen-based-virt.
Run
virsh edit VM_NAME
Then look for the element inside the element. If the value is linux is PVM.
If your Dom0 is a linux machine , can you please check the output of command "ps -eaf | grep qemu" ? It should state the type of guest running on it (in case it is xen hypervisor that is being used).
The output corresponding to pv guest machine will end with "-M xenpv" and output corresponding to hvm/pvhvm guest machines should end with "-M xenfv". This is what i find in my case.
# ps -eaf | grep qemu
/usr/lib/xen/bin/qemu-dm -d 419 -serial pty -domain-name pvm_guest -videoram 4 -vnc 0.0.0.0:0 -vncunused -M xenpv
/usr/lib/xen/bin/qemu-dm -d 429 -domain-name hvm_guest -videoram 4 -k en-us -vnc 0.0.0.0:0 -vncunused -vcpus 1 -vcpu_avail 0x1 -boot c -serial pty -acpi -net nic,vlan=1,macaddr=00:16:3e:40:94:4f,model=rtl8139 -net tap,vlan=1,ifname=tap429.0,bridge=br0 -M xenfv