razzi.abuissa.net

Razzi's guide to Lima

Lima is a virtual machine manager. It uses qemu but it’s much more user friendly.

The basic functionality revolves around the “default” machine.

If you run:

$ limactl start

it’ll give you a terminal interactive menu for creating a machine.

The defaults work fine for me so I just use:

$ limactl start --tty=false

Once the machine is running you can connect to it simply with:

$ lima
razzi@lima-default:/Users/razzi$

I have a lima-ssh function that does all of this in 1 command.

niceties of lima

The default machine is the latest Ubuntu:

razzi@lima-default:/Users/razzi$ cat /etc/issue
Ubuntu 24.10 \n \l

The directory lima starts with is a readonly copy of the host filesystem:

razzi@lima-default:/Users/razzi$ ls .config/fish/
LICENSE  README.md  completions  conf.d  fish_variables  functions  test
razzi@lima-default:/Users/razzi$ touch testfile
touch: cannot touch 'testfile': Read-only file system

Going to the lima home directory gives access to a read/write filesystem:

razzi@lima-default:/Users/razzi$ cd
razzi@lima-default:~$ pwd
/home/razzi.linux
razzi@lima-default:~$ touch file.txt
razzi@lima-default:~$

Ports are automatically forwarded from the guest to the host:

razzi@lima-default:~$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

Then from the host, you can access the server:

$ curl -I localhost:8000
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.12.7

You can navigate to http://localhost:8000 in a browser from the host to do simple file copying.

You can access the host machine by its ip address from the virtual machine:

$ ifconfig en0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=400<CHANNEL_IO>
	ether 80:e6:50:0c:b4:0c
	inet6 fe80::14f4:9898:457f:6a07%en0 prefixlen 64 secured scopeid 0x4
	inet 192.168.50.250 netmask 0xffffff00 broadcast 192.168.50.255
	nd6 options=201<PERFORMNUD,DAD>
	media: autoselect
	status: active

From the virtual machine:

razzi@lima-default:~$ curl -I 192.168.50.250:8000
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.13.2

To access any files on the host, you can use the readonly filesystem.

If you’d like to modify any of the files, you can copy them to the guest home directory:

razzi@lima-default:~$ cp /Users/razzi/.profile ~

cleaning up

Before I create more exotic virtual machines, note that you can see your machines with:

$ limactl list
NAME       STATUS     SSH                VMTYPE    ARCH      CPUS    MEMORY    DISK      DIR
default    Running    127.0.0.1:60022    qemu      x86_64    4       4GiB      100GiB    ~/.lima/default

And stop them with:

$ limactl stop

podman

Lima comes with config to act as a podman host.

Helpfully you can see the command needed to create a podman host if you run podman.lima:

$ podman.lima
instance "podman" does not exist, run `limactl create --name=podman template://podman` to create a new instance

Running that gives further instructions:

$ limactl create --name=podman template://podman
? Creating an instance "podman" Proceed with the current configuration
...
INFO[0002] Run `limactl start podman` to start the instance.
$ limactl start podman
INFO[0000] Using the existing instance "podman"
INFO[0000] Starting the instance "podman" with VM driver "qemu"
...
INFO[0142] READY. Run `limactl shell podman` to open the shell.
INFO[0142] Message from the instance "podman":
To run `podman` on the host (assumes podman-remote is installed), run the following commands:
------
podman system connection add lima-podman "unix:///Users/razzi/.lima/podman/sock/podman.sock"
podman system connection default lima-podman
podman run quay.io/podman/hello
------

Run those commands and they’ll persist the config to ~/.config/containers/podman-connections.json.

Now you can run commands from the podman executable:

$ podman run quay.io/podman/hello
!... Hello Podman World ...!
...

You can use this to for example run a debian virtual machine:

$ podman run -it debian
root@d9424543fca4:/# cat /etc/issue
Debian GNU/Linux 12 \n \l

vnc

Lima comes with an “experimental” config for connecting to a virtual machine graphically over VNC.

It’s worked fine for me.

$ limactl start /usr/local/share/lima/templates/experimental/vnc.yaml
? Creating an instance "vnc" Proceed with the current configuration
WARN[0004] `video.display: vnc` is experimental
INFO[0004] Starting the instance "vnc" with VM driver "qemu"
...
INFO[0189] READY. Run `limactl shell vnc` to open the shell.
INFO[0189] Message from the instance "vnc":
Use a VNC viewer or noVNC, to connect to the display:

* VNC Display:    see <file:///Users/razzi/.lima/vnc/vncdisplay>
* VNC Password:   see <file:///Users/razzi/.lima/vnc/vncpassword>

If you’re running macOS as the host OS, it comes with a built-in VNC viewer called Screen Sharing.

It’ll use that if you use the open command with a vnc:// link:

$ open vnc://:(cat ~/.lima/vnc/vncpassword)@127.0.0.1:5900

I have a fish function for this as well: lima-vnc.

At the top of the window you can see a toggle between Control and Observe.

If it’s in Control mode, even commands line command+tab will be captured by the virtual machine.

So switch to Observe mode if you’re going back and forth between the virtual machine and the host machine.

Even though it’s providing a VNC view, you can connect to the machine over ssh as usual:

lima $ limactl shell vnc
razzi@lima-vnc:/Users/razzi/forks/lima$

source code

https://github.com/lima-vm/lima

depends on