Error while creating snap in LXD

I was trying to create snap in LXD. I installed snap, snapd, and snapcraft and also check that my machine is support virtualization and it is enabled.

But after running command, sudo snapcraft , i am getting following error,

root@station1:~/test-snap# sudo snapcraft
Running with 'sudo' may cause permission errors and is discouraged. Use 'sudo' when cleaning.
Launching a VM.
Build environment is in unknown state, cleaning first.
info failed: The following errors occurred:
instance "snapcraft-my-snap-name" does not exist
launch failed: Cannot check BIOS for determining KVM extensions support.        
Unable to load KVM support. Please ensure KVM is installed on your machine.
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.

Here, output of kvm-ok command in LXD bash,

root@station1:~/test-snap# kvm-ok
INFO: /dev/kvm does not exist
HINT:   sudo modprobe kvm_intel
modprobe: FATAL: Module msr not found in directory /lib/modules/5.8.0-59-generic

And output of kvm-ok command in Host system,

âžś kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be use

I do not know what is the issue here. can anyone help me?

There’s a few things. 1) You’re root, you don’t need sudo if you’re already root. 2) snapcraft doesn’t need sudo / root anyway. 3) if you’re inside a lxd container (which is what you’re suggesting) then you could use snapcraft --destructive-mode rather than launch a multipass vm inside a lxd container.

Alternatively install snapcraft on the host, and use snapcraft --use-lxd which will launch a container, build the snap inside it and then make the snap available to the host.

Can I ask what documentation you’re following? Because if we have some incorrect docs recommending the path you’re on, then we should fix it.

1 Like

Thanks for reply @popey.

snapcraft --destructive-mode was worked just fine. Saved my day.

Another thing, in host system snapcraft --use-lxd has not working. it gives this output,

badmatrix@exellar:~/SnapStation/test-rust-snap/test-rust$ snapcraft --use-lxd
Error: no such option: --use-lxd

In addition, i don’t know why, but snapcraft is not working without sudo in lxd.
See this snippet(In LXD),

root@station1:~/test-snap/trust# snapcraft init
bash: snapcraft: command not found

root@station1:~/test-snap/trust# sudo snapcraft init
Created snap/snapcraft.yaml.
Go to https://docs.snapcraft.io/the-snapcraft-format/8337 for more information about the snapcraft.yaml format.

Maybe i have to sharpen my knowledge on LXD.

Lastly, I did not find any documentation so just hopping on different solutions on google based on error. But if is there any documentation on this topic then please mention it. It would really help me out and clear my doubts on this topic.

The --use-lxd option will only work if you have a base specified in your snapcraft.yaml. Snapcraft confusingly launches the legacy code path if you don’t specify base and that code pre-dates the --use-lxd option.

Another option would be if you’re using an old version of snapcraft. Are you using the snap of snapcraft, or the deb? If the deb, switch to the snap.