lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
15.37k stars 602 forks source link

Support nested virtualization #477

Closed kopiczko closed 2 years ago

kopiczko commented 2 years ago

I'd like to ask if there is a chance to have nested virtualization? I tried steps from https://docs.fedoraproject.org/en-US/quick-docs/using-nested-virtualization-in-kvm/ but TBH I have no idea what I'm doing. I need kvm in particular to be able to build capi images.

afbjorklund commented 2 years ago

It should be doable, but might need some special flags:

$ sudo modprobe -r kvm_intel
$ sudo modprobe kvm_intel nested=1
$ cat /sys/module/kvm_intel/parameters/nested 
Y

Running the lima VM, on Ubuntu:

anders@lima-default:/home/anders$ sudo apt install cpu-checker
...
anders@lima-default:/home/anders$ kvm-ok 
INFO: /dev/kvm exists
KVM acceleration can be used
kopiczko commented 2 years ago

I'm on macOS Monterey and with default ubuntu /dev/kvm doesn't exist. It's the same with fedora 35.

afbjorklund commented 2 years ago

Sorry, I thought you were on real Ubuntu. So you want three levels of Inception, when it hits the water ?

afbjorklund commented 2 years ago

I think the commercial options (VMware and Parallels) do it, but I don't think QEMU supports it (on Mac)

jandubois commented 2 years ago

I'm not sure, but I don't think qemu supports nested virtualization like that on macOS.

I know it works with VMware Fusion, but it is a commercial product. I.e. you can run Ubuntu on Fusion, and then run Lima inside the Ubuntu VM (you need to enable nested virtualization, and possibly virtualized performance counters).

afbjorklund commented 2 years ago

I didn't understand where Lima entered the picture, instead of running the image builder with HVF instead of KVM ?

The supporting scripts probably don't work on macOS, or something. Theoretically they could be translated, instead.

https://github.com/kubernetes-sigs/image-builder/tree/master/images/capi

But most likely the easiest is doing it on a real remote (or local) Linux server.

AkihiroSuda commented 2 years ago

Duplicate of https://github.com/lima-vm/lima/issues/22