Lima Advanced: x86_64 VMs, Nested Virtualization, and Clones on a Mac

A default Lima VM is arm64, the same as the Mac, and it cannot run VMs inside it. To verify changes for amd64 systems, or to test QEMU/KVM inside a VM, you need more settings. With more VMs, you must also manage SSH ports and disk space. This post covers x86_64 VMs, nested virtualization, clones, VMs on an external disk, and recovery of VMs that do not respond.

For installation and basic use, see the Lima documentation. The test environment is an Apple M4 Mac mini, macOS 27, and Lima 2.3.0.

Connect with ssh directly

Lima makes an ssh.config file for each VM. The host name is lima-<VM name>. The port changes each time the VM starts.

$ cat ~/.lima/demo/ssh.config
# This SSH config file can be passed to 'ssh -F'.
# This file is created by Lima, but not used by Lima itself currently.
# Modifications to this file will be lost on restarting the Lima instance.
Host lima-demo
  IdentityFile "/Volumes/Data/lima/_config/user"
...
  ControlMaster auto
  ControlPath "/Volumes/Data/lima/demo/ssh.sock"
  ControlPersist yes
  Hostname 127.0.0.1
  Port 62580

Add Include for these files to ~/.ssh/config. Then ssh lima-<name> connects without the port number. scp, rsync, and VS Code Remote-SSH use the same name.

Include ~/.lima/*/ssh.config
$ ssh lima-demo hostname
lima-demo

Because of ControlPersist yes, ssh reuses the first connection. After a change that needs a new session, such as a new group, close the connection with ssh -O exit lima-<name>.

Keep VMs on an external disk

VM disks are in LIMA_HOME (default ~/.lima). If the internal SSD is full, move this directory to an external disk. There are two methods.

MethodSettingEffect
Symbolic linkln -s /Volumes/Data/lima ~/.limaSettings that use the ~/.lima path (such as Include) do not change
Environment variableexport LIMA_HOME=/Volumes/Data/limaYou must set it in each shell, and separately in launchd jobs
$ readlink ~/.lima
/Volumes/Data/lima

$ limactl info | jq -r .limaHome
/Volumes/Data/lima

An external HDD makes package installs and builds slow. The test disk for this article is a USB HDD. Random 4K reads from the VM disk took 8 ms on average.

Make an x86_64 VM

With --arch=x86_64, Lima uses QEMU instead of vz. On Apple Silicon, QEMU emulates the x86_64 guest with TCG, without hardware acceleration.

$ limactl start --name=demo-x86 --arch=x86_64 --cpus=2 --memory=2 --disk=20 --tty=false template:ubuntu-26.04
...
time="2026-12-05T23:18:24+09:00" level=info msg="READY. Run `limactl shell demo-x86` to open the shell."
real 351.07

$ limactl list demo-x86
NAME        STATUS     SSH                VMTYPE    ARCH      CPUS    MEMORY    DISK     DIR
demo-x86    Running    127.0.0.1:63412    qemu      x86_64    2       2GiB      20GiB    /Volumes/Data/lima/demo-x86

The first creation took about 6 minutes, with the download of the amd64 image. In the guest, the machine architecture, the package architecture, and the archive URL are all amd64.

$ ssh lima-demo-x86 'uname -m; dpkg --print-architecture; grep -m1 "model name" /proc/cpuinfo'
x86_64
amd64
model name	: QEMU TCG CPU version 2.5+

$ ssh lima-demo-x86 'apt-get -qq --print-uris download hello | cut -d" " -f1'
'http://archive.ubuntu.com/ubuntu/pool/main/h/hello/hello_2.10-5build1_amd64.deb'

In an arm64 VM, this URL is ports.ubuntu.com. Output for an amd64 target must not show this URL.

Speed difference

I ran the same command in the arm64 VM (demo, vz) and the x86_64 VM (demo-x86, TCG). Both VMs have 2 CPUs and 2GiB.

$ ssh lima-demo 'uname -m; time (seq 1 2000000 | gzip -9 > /dev/null)'
aarch64

real	0m0.501s
user	0m0.282s
sys	0m0.089s

$ ssh lima-demo-x86 'uname -m; time (seq 1 2000000 | gzip -9 > /dev/null)'
x86_64

real	0m2.230s
user	0m2.266s
sys	0m0.113s
Measurementarm64 (vz)x86_64 (QEMU TCG)Difference
seq | gzip -90.50 s2.23 sAbout 4.5 times
Restart after stop (limactl start)23.7 s81.5 sAbout 3.4 times

Use the x86_64 VM only when you need amd64 output. Do long tasks, such as kernel builds, in the arm64 VM.

Use KVM inside a VM with nested virtualization

By default, a vz VM has no /dev/kvm. With --nested-virt (configuration key nestedVirtualization: true), the guest can use KVM. The Lima default template gives the vz requirements as Apple M3 or later and macOS 15 or later.

$ limactl start --name=demo --cpus=2 --memory=2 --disk=20 --nested-virt --tty=false template:ubuntu-26.04
...
time="2026-12-05T23:01:22+09:00" level=info msg="READY. Run `limactl shell demo` to open the shell."
real 100.75

$ ssh lima-demo 'uname -m; ls -l /dev/kvm'
aarch64
crw-rw---- 1 root kvm 10, 232 Dec  5 23:00 /dev/kvm

$ ssh lima-demo 'sudo dmesg | grep -i kvm | head -5'
[    0.038840] kvm [1]: nv: 570 coarse grained trap handlers
[    0.038890] kvm [1]: nv: 664 fine grained trap handlers
[    0.038936] kvm [1]: IPA Size Limit: 40 bits
[    0.039335] kvm [1]: GICv3: no GICV resource entry
[    0.039338] kvm [1]: disabling GICv2 emulation

The nv: lines show that the guest kernel initialized nested virtualization support. Add your user to the kvm group and connect again. Then check acceleration with info kvm in the QEMU monitor.

sudo apt-get install -y qemu-system-arm
sudo usermod -aG kvm $USER
# To apply the group, run ssh -O exit lima-demo on the Mac and connect again
$ printf "info kvm\nquit\n" | qemu-system-aarch64 -M virt,accel=kvm -cpu host -m 256 -display none -S -monitor stdio -serial none
QEMU 10.2.1 monitor - type 'help' for more information
kvm support: enabled

Give -cpu host to QEMU for the nested guest. The Lima template comment says that without it, QEMU can fail at kvm_init_vcpu with Invalid argument.

Clones and snapshots

Snapshots do not work on vz VMs. The Lima documentation lists QEMU and krunkit for snapshots.

$ limactl snapshot create demo --tag clean
time="2026-12-05T23:12:33+09:00" level=warning msg="`limactl snapshot` is experimental"
time="2026-12-05T23:12:33+09:00" level=fatal msg=unimplemented

Instead, copy a stopped VM with limactl clone. The clone gets a new name and a new ssh.config.

$ limactl stop demo
$ time limactl clone demo demo-test --tty=false

real	0m0.043s
user	0m0.034s
sys	0m0.014s

$ limactl list
NAME         STATUS     SSH                VMTYPE    ARCH       CPUS    MEMORY    DISK      DIR
demo         Stopped    127.0.0.1:62580    vz        aarch64    2       2GiB      20GiB     /Volumes/Data/lima/demo
demo-test    Stopped    127.0.0.1:62580    vz        aarch64    2       2GiB      20GiB     /Volumes/Data/lima/demo-test
...

Keep one base VM. For each task, make a clone and delete it after the task. The base VM then stays clean. Verify commands and configuration changes in a Lima VM shows this procedure.

Recover a VM that does not respond

If the hostagent stops abnormally, files such as ha.pid and ha.sock stay. The next limactl start finds them, removes them, and starts the VM again.

$ limactl start linux
time="2026-12-05T20:43:39+09:00" level=error msg="Instance \"linux\" has configuration errors" error="failed to get Info from `/Volumes/Data/lima/linux/ha.sock`: host agent is unreachable: Get \"http://lima-hostagent/v1/info\": dial unix /Volumes/Data/lima/linux/ha.sock: connect: connection refused"
time="2026-12-05T20:43:39+09:00" level=info msg="Using the existing instance `linux`"
time="2026-12-05T20:43:39+09:00" level=warning msg="Instance \"linux\" has a stale host agent socket; removing stale host agent files to recover"
time="2026-12-05T20:43:39+09:00" level=info msg="Removing stale file \"/Volumes/Data/lima/linux/ha.pid\""
time="2026-12-05T20:43:39+09:00" level=info msg="Removing stale file \"/Volumes/Data/lima/linux/ha.sock\""
time="2026-12-05T20:43:39+09:00" level=info msg="Removing stale file \"/Volumes/Data/lima/linux/vz.pid\""
time="2026-12-05T20:43:39+09:00" level=info msg="Starting the instance `linux` with internal VM driver `vz`"

If limactl stop does not finish, use -f. It stops the hostagent and the VM driver process with SIGKILL and removes the remaining files.

$ limactl stop -f demo
time="2026-12-05T23:16:49+09:00" level=info msg="Sending SIGKILL to the vz driver process 77053"
time="2026-12-05T23:16:49+09:00" level=info msg="Sending SIGKILL to the host agent process 77053"
time="2026-12-05T23:16:49+09:00" level=info msg="Removing *.pid *.sock *.tmp under `/Volumes/Data/lima/demo`"
...
time="2026-12-05T23:16:49+09:00" level=info msg="Removing `/Volumes/Data/lima/demo/ha.pid`"
time="2026-12-05T23:16:49+09:00" level=info msg="Removing `/Volumes/Data/lima/demo/ha.sock`"
time="2026-12-05T23:16:49+09:00" level=info msg="Removing `/Volumes/Data/lima/demo/vz.pid`"

stop -f stops only the processes in the pid files. To find a limactl hostagent process without a pid file, use pgrep -fl "limactl hostagent" and stop it. In automation scripts, run limactl list and limactl start with timeout to prevent an endless wait.

timeout 60 limactl list linux --format '{{.Status}}'
timeout 600 limactl start linux

Boot panic in x86_64 VMs

A TCG x86_64 VM can panic early in boot, at the timer check (check_timer). The kernel messages are in serial.log in the VM directory. This panic occurred on a 4-CPU x86_64 VM.

$ grep -n -E "TIMER|IO-APIC|panic" ~/.lima/linux-x86/serial.log
154:[    0.002000] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
155:[    0.004000] ..MP-BIOS bug: 8254 timer not connected to IO-APIC
...
163:[    0.013000] Kernel panic - not syncing: IO-APIC + timer doesn't work!  Boot with apic=debug and send a report.  Then try booting with the 'noapic' option.

When emulation is slow, the kernel does not get the timer interrupt in the expected time. The kernel parameter no_timer_check skips this check. After the VM boots once, add the parameter to the GRUB settings. Ubuntu cloud images use /etc/default/grub.d/50-cloudimg-settings.cfg, so use a file name that sorts after it.

echo 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT no_timer_check"' | sudo tee /etc/default/grub.d/99-no-timer-check.cfg
sudo update-grub

Restart the VM and make sure that the kernel command line has the parameter.

$ ssh lima-demo-x86 'cat /proc/cmdline'
BOOT_IMAGE=/vmlinuz-7.0.0-38-generic root=UUID=a9c87573-c170-44a0-8c14-09fcc03a56a9 ro console=tty1 console=ttyS0 no_timer_check

Command summary

TaskCommand
Connect by ssh nameInclude ~/.lima/*/ssh.config in ~/.ssh/config
Change the VM locationLIMA_HOME or a ~/.lima symbolic link
x86_64 VMlimactl start --arch=x86_64 ...
Nested virtualizationlimactl start --nested-virt ... (M3 or later, macOS 15 or later)
Copy a VMlimactl clone <source> <new name> (stop the source first)
Force stoplimactl stop -f <name>
Boot log~/.lima/<name>/serial.log

Cautions

  • Do not plan on snapshots for vz VMs. In Lima 2.3.0, they fail with unimplemented. Use clones.
  • Do not clone a running VM. Stop the source first.
  • Do not expect --nested-virt on M1 or M2 Macs. Nested virtualization with vz needs M3 or later and macOS 15 or later.
  • Do not use the x86_64 VM as your default VM. In this test, CPU work was about 4.5 times slower.
  • Do not call limactl without a time limit in automation. If a stale hostagent does not respond, the command does not finish.

Summary

Start the x86_64 VM only when you need amd64 output. Nested virtualization lets you test QEMU/KVM inside a VM on M3 or later Macs. Use a base VM and clones, so that test changes do not stay in the base VM.

This is a referral link. I may receive credit if you sign up, at no extra cost to you.

Try it on a cloud server — Deploy Ubuntu on Vultr

References

Leave a Reply