Running virtual machines with LXD 4.0

What is the default limits.memory setting for VMs?

It seems to be 1GB (because that’s what my VM seems to have available to it, and I haven’t configured it explicitly)

But the documentation suggests that the default setting is “-”, which means “all”, right?. Instances | LXD.

“all” seems an unlikely setting for a VM, so I’m guessing the documentation is wrong, but just wanted to check.

Looks like we need to improve the doc a tiny bit to cover the defaults for virtual machines.

For containers, it’s correct that no limit means you get to see whatever the host has to offer. For VMs it’s not something we can do, so it defaults to 1 vCPU and 1GB of RAM.

I just started a VM and it failed with this error message:
~$ Lxc start win2 --console
Error: Failed to run: forklimits limit=memlock :unlimited :unlimited … /snap/lxd
/ 21545/bin/qemu-system-x86_ 64 -S -name win2 -uuid 8ee5118C- 7e6e -4a18- 9e59 - 36b1e2275dd1 - daemonize -cpu host - nogr aphic -serial chardev:console -nodefaults - no user-config -sandbox on,obsolete=deny,elevateprivileges=allow,spawn=deny,resourcecontrol=deny - readconfig /var /snap/lxd/ common/lxd/logs /win2/qemu. conf - spiceunix=ON,disable- ticketing=on,addr= /var / snap/lxd/ common/lxd/logs /win2/qemu . spice -pidfile /var /snap/lxd/ common/lxd/ Logs /win2/qemu.pid -D /var /snap/lxd/ common/Lxd/Logs /win2/qemu. log - smbios type=2 ,manufacturer=Canonical Ltd. ,product=LXD runas lxd: char device redirected to /dev/pts/0 (label console )
: Process exited with non-zero value 1
Try ‘lxc info --show-log win2’ for more info

~$ lxc info --show-log win2
Name: win2
Location: none
Remote: unix://
Architecture: x86_ 64
Created: 2021/10/04 07:30 UTC
Status: Stopped
Type: virtual-machine
Profiles: default
Log:
qemu-system-x86_ 64: error: failed to set MSR 0x48f to 0x7ffff f00036dfb
qemu-system-x86_ 64: . ./target/i386 /kvm/kvm.c:2833: kvm buf_ set_ msrs: Assertion
ret == cpu->kvm_ msr_ buf->nmsrs’ failed.

Hmm, that smells like a potential hardware issue.
Can you show:

  • uname -a
  • dmesg | grep -i kvm

Also what kind of environment is this, is it a physical system, a virtual machine, … ?

$ uname -a
Linux fhm- ubuntu 5. 11.0-37-generic #41~20. 04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021 x86_ 64 x86_ 64 x86_ 64 GNU/Linux

$ dmesg | grep -i kvm
I typed the above command, but nothing output.

It is a virtual machine, and the environment is Ubuntu 20.04 LTS

What VM platform is used? I suspect it’s something like VirtualBox or VMWare and that nested VMs don’t work properly.

VMware.

Suggests that perhaps our qemu capability detection isn’t as thorough as it could be:

Do you have a file /dev/kvm?

In contrast with native KVM, VMware Workstation/ESXi doesn’t enable nested virtualization by default, you need to check the Virtualize Intel VT-x/EPT or AMD-V/RVI (Workstation) or Expose hardware-assisted virtualization to the guest OS (ESXi) option in VM settings to ensure you have the required kvm module loaded and therefore use nested VM. But be conscious that nested virtualization is not really reliable and may not work correctly even for testing use-cases.

Yes, I do.

Hmm, thank you I know.

Yes so thats why LXD thinks you can create KVM VMs, but apparently its not quite capable of it.

How can I include a script/list of QEMU options when creating a VM with LXD?

raw.qemu

Are there any tutorials that specifically cover raw.qemu? It isn’t clear to me how to use it. Is it a flag or something in the profile? Or is this something I set after creating the VM?

Can I supply a path to an sh script containing my desired QEMU command? If I have a working qemu-system-x86_64 command, is it certain to work with LXD/C?

I tried lxc config set $vmname raw.qemu but:

~$ lxc config set $vmname raw.qemu
Error: cannot set 'ubuntu' to 'raw.qemu': unknown key

Also I tried:

~$ lxc config set ubuntu raw.qemu "-name lubuntuvm,process=lubuntuvm -machine type=pc,accel=kvm -cpu host -smp 4,sockets=1,cores=4,threads=1 -m 8G -vga qxl -spice port=5930,disable-ticketing=on -rtc clock=host,base=localtime -serial none -parallel none -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd -drive if=pflash,format=raw,file=/tmp/my_vars.fd -drive id=disk0,if=virtio,cache=none,format=raw,file=/home/boss/VMs/lubuntu.img -drive file=/home/boss/ISOs/ubuntu-20.04.3-desktop-amd64.iso,index=1,media=cdrom -net tap -net nic"
Error: unknown shorthand flag: 'n' in -name lubuntuvm,process=lubuntuvm -machine type=pc,accel=kvm -cpu host -smp 4,sockets=1,cores=4,threads=1 -m 8G -vga qxl -spice port=5930,disable-ticketing=on -rtc clock=host,base=localtime -serial none -parallel none -drive if=pflash,format=raw,readonly,file=/usr/share/OVMF/OVMF_CODE.fd -drive if=pflash,format=raw,file=/tmp/my_vars.fd -drive id=disk0,if=virtio,cache=none,format=raw,file=/home/boss/VMs/lubuntu.img -drive file=/home/boss/ISOs/ubuntu-20.04.3-desktop-amd64.iso,index=1,media=cdrom -net tap -net nic

raw.qemu only works on VMs, the first error you’re showing suggests that ubuntu is a container in this case.

The second error happens because the command line is a bit annoying with dashes in values. You can edit use lxc config edit to set it through the YAML config or you can do something like:

echo “-name …” | lxc config set NAME raw.qemu -

Note however that raw.qemu is appended to what LXD config you normally get, I suspect many of what you put in there will conflict and cause the VM to just fail.

1 Like

Ok, it is a VM according to lxc list

~$ lxc list
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
|    NAME     |  STATE  |        IPV4         |                     IPV6                      |      TYPE       | SNAPSHOTS |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
| lubuntu-1   | STOPPED |                     |                                               | CONTAINER       | 0         |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
| mycontainer | RUNNING | 10.61.65.28 (eth0)  | fd42:240c:548b:325c:216:3eff:feb0:6d1d (eth0) | CONTAINER       | 0         |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
| steam       | STOPPED |                     |                                               | CONTAINER       | 0         |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
| ubuntu      | STOPPED |                     |                                               | VIRTUAL-MACHINE | 0         |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
| ubuntu-gui  | STOPPED |                     |                                               | CONTAINER       | 0         |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+
| x2go-test   | RUNNING | 10.61.65.155 (eth0) | fd42:240c:548b:325c:216:3eff:fec9:2b26 (eth0) | CONTAINER       | 0         |
+-------------+---------+---------------------+-----------------------------------------------+-----------------+-----------+

Are you saying that my desired commands are more likely to work if I use a YAML or that either one is likely to run into problems?

In any case, following your advice (also I now notice I had forgotten the -) I got past the previous error,

~$ echo "-machine type=pc,accel=kvm -cpu host -smp 4,sockets=1,cores=4,threads=1 -m 8G -vga qxl -spice port=5930,disable-ticketing=on -rtc clock=host,base=localtime -serial none -parallel none -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd -drive if=pflash,format=raw,file=/tmp/my_vars.fd -drive id=disk0,if=virtio,cache=none,format=raw,file=/home/boss/VMs/lubuntu.img -drive file=/home/boss/ISOs/ubuntu-20.04.3-desktop-amd64.iso,index=1,media=cdrom -net tap -net nic" | lxc config set ubuntu raw.qemu -
~$ lxc start ubuntu                  
Error: Failed to run: forklimits limit=memlock:unlimited:unlimited -- /snap/lxd/21902/bin/qemu-system-x86_64 -S -name ubuntu -uuid 2890
aa72-6929-41db-853d-0599580c2f18 -daemonize -cpu host -nographic -serial chardev:console -nodefaults -no-user-config -sandbox on,obsole
te=deny,elevateprivileges=allow,spawn=deny,resourcecontrol=deny -readconfig /var/snap/lxd/common/lxd/logs/ubuntu/qemu.conf -spice unix=
on,disable-ticketing=on,addr=/var/snap/lxd/common/lxd/logs/ubuntu/qemu.spice -pidfile /var/snap/lxd/common/lxd/logs/ubuntu/qemu.pid -D
/var/snap/lxd/common/lxd/logs/ubuntu/qemu.log -smbios type=2,manufacturer=Canonical Ltd.,product=LXD -runas lxd -machine type=pc,accel=
kvm -cpu host -smp 4,sockets=1,cores=4,threads=1 -m 8G -vga qxl -spice port=5930,disable-ticketing=on -rtc clock=host,base=localtime -s
erial none -parallel none -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd -drive if=pflash,format=raw,file=/t
mp/my_vars.fd -drive id=disk0,if=virtio,cache=none,format=raw,file=/home/boss/VMs/lubuntu.img -drive file=/home/boss/ISOs/ubuntu-20.04.
3-desktop-amd64.iso,index=1,media=cdrom -net tap -net nic: char device redirected to /dev/pts/0 (label console)
: Process exited with non-zero value 1
Try `lxc info --show-log ubuntu` for more info

The log complains about a file not existing that in fact does exist:

~$ lxc info --show-log ubuntu
Name: ubuntu
Status: STOPPED
Type: virtual-machine
Architecture: x86_64
Created: 2021/11/27 16:25 EST
Last Used: 2021/11/27 16:26 EST

Log:

qemu-system-x86_64: -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd: Could not open '/usr/share/OVMF/OVMF_CODE.fd': No such file or directory

Edit: I still get this error if I create the VM with

lxc launch images:ubuntu/focal ubuntu1 --vm -c security.secureboot=false

Edit2: since this seems like a separate issue now, I created a new thread: Permissions issues with creating a VM through LXD, but not `qemu-system`

I must be missing something pretty basic because trying to start a Virtual Machine dies:

mcon@ikea:~$ lxc launch images:centos/8-Stream centos --vm
Creating centos
Error: Failed instance creation: Failed creating instance record: Instance type "virtual-machine" is not supported on this server: QEMU command not available for CPU architecture

which is a bit strange because I can manually start QEMU (with a warning, is it relevant?):

mcon@ikea:~$ qemu-system-x86_64
qemu-system-x86_64: warning: dbind: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

It can’t really boot because it has no disk/cdrom/whatever, but it surely tries (I can see the VGA window).
What am I missing?