How to build snap package without lxd and multipass

Hi
I have a LXD container for building my projects and snaps packages. in this container a have installed snapcraft from the snap-store.
but when i try build snap package a have errors because my KVM system already used and LXD is running because i try deploy LXD containers in LXD container O_o ))

So the only way to build a snap is to use a build without virtualization or containers.

How to build snap package without multipass and lxd ?

I’m sorry. my KVM was not busy it was just not available in the LXD container.
I added this with the command

lxc config device add linuxHostBuilders kvm unix-char path = / dev / kvm

and now I get this weird error:

root@crack-gnu:~/worker/Linux/LinuxBuilder/QuasarApp/CQtDeployer# snapcraft
Launching a VM.
Build environment is in unknown state, cleaning first.
Name:           snapcraft-app
State:          Stopped
IPv4:           --
Release:        --
Image hash:     7c5c8f24046c (Ubuntu Snapcraft builder for Core 18)
Load:           --
Disk usage:     --
Memory usage:   --
launch failed: The following errors occurred:                                   
kvm version too old
qemu-system-x86_64: failed to initialize KVM: Inappropriate ioctl for device
snapcraft-app: shutdown called while starting
An error occurred with the instance when trying to launch with 'multipass': returned exit code 2.
Ensure that 'multipass' is setup correctly and try again.

Why are you starting a container and running snapcraft inside that, rather than letting snapcraft handle the container spawning?

If you really want to not use snapcraft’s lxd or multipass support then you can use --destructive-mode, but be aware that this will install all the build-packages onto the system that is executing snapcraft (in your case the container).

Why are you starting a container and running snapcraft inside that, rather than letting snapcraft handle the container spawning?

Because sometimes I have situations when I need to transfer my build machine to other servers. In addition, the use of a container solves the issue of backup. This helps to save time since I do not need to set up everything in case of relocation or technical failure.

If you really want to not use snapcraft’s lxd or multipass support then you can use --destructive-mode, but be aware that this will install all the build-packages onto the system that is executing snapcraft (in your case the container).

in truth, now I’m more interested in how to solve the question that multipass arises when trying to use KVM. What else is this error and why is the KVM version provided by the digitalokean service too old?

kvm version too old
qemu-system-x86_64: failed to initialize KVM: Inappropriate ioctl for device

Apr 18 20:19:07 crack-gnu multipassd[355]: [57897] started: qemu-img snapshot -l /var/snap/multipass/common/data/multipassd/vault/instan
Apr 18 20:19:07 crack-gnu multipassd[355]: process working dir '/snap/multipass/3531/qemu'
Apr 18 20:19:07 crack-gnu multipassd[355]: process program 'qemu-system-x86_64'
Apr 18 20:19:07 crack-gnu multipassd[355]: process arguments '--enable-kvm, -device, virtio-scsi-pci,id=scsi0, -drive, file=/var/snap/mu
Apr 18 20:19:07 crack-gnu multipassd[355]: [57902] started: qemu-system-x86_64 -nographic -dump-vmstate /tmp/multipassd.yJH355
Apr 18 20:19:07 crack-gnu multipassd[355]: qemu-system-x86_64: warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
Apr 18 20:19:07 crack-gnu multipassd[57905]: Applying AppArmor policy: multipass.snapcraft-cqtdeployer.qemu-system-x86_64
Apr 18 20:19:07 crack-gnu multipassd[355]: [57905] started: v --enable-kvm -device virtio-scsi-pci,id=scsi0 -drive file=/var/snap/multip
Apr 18 20:19:07 crack-gnu multipassd[355]: process started
Apr 18 20:19:07 crack-gnu multipassd[355]: kvm version too old
                                           qemu-system-x86_64: failed to initialize KVM: Inappropriate ioctl for device

This is log of the starting multipass.
This is looks like a bug, but the virtualbox works fine.

And I don’t use Red Hat Linux systems.
@lucyllewy maybe you have any ideas how to fix it.

It looks like there are spaces that shouldn’t be there in this command. It should be exactly:

sudo lxc config device add linuxHostBuilders kvm unix-char path=/dev/kvm

sudo is required to succeed. You also need to restart your container for the device change to take effect:

lxc restart linuxHostBuilders

Once you’re sure the device is correctly exposed, run kvm-ok inside your container to verify whether kvm support is functional (ideally you’d also run this on your host to verify there as well because if it doesn’t work on your host then no amount of forwarding into containers will work).

kvm-ok is in the package cpu-checker:

sudo apt install cpu-checker
1 Like

Although, thinking on this… if you’re using LXD via the Snap Package (I suspect this is the only way to get it these days) then the kvm device is likely prevented from being accessed by the cgroups and apparmor rules that snapd puts the LXD processes under.

hmm. I check your suggestion later and leave feedback in this topic

2 Likes