Lima VM network

Author: Jase Batchelor

As mentioned in our previous article on Lima VM, it is possible to customise network configuration.

Specifically, we will install socket_vmnetcopy which is allows us an easy way to use the Apple vmnet.frameworkcopy virtualised networking framework

As per the documentation:

“Daemon to provide vmnet.framework support for rootless QEMU”

The socket_vmnetcopy application allows us to use sharedcopy networking in Lima VM configuration.

 


Sections

 


Installation

Install Lima socket_vmnetcopy

Install via homebrew

brew install socket_vmnet
copy

To view the files installed by socket_vmnetcopy

ls ${HOMEBREW_PREFIX}/opt/socket_vmnet/bin/*
# /opt/homebrew/opt/socket_vmnet/bin/socket_vmnet         
# /opt/homebrew/opt/socket_vmnet/bin/socket_vmnet_client
copy

 


Configuration

Configure Lima socket_vmnetcopy in networks.yamlcopy

Note that we must NOT use a symlinked path to the socket_vmnetcopy binary

Run the following and you will see that the socket_vmnetcopy directory is symlinked to ../Cellar/socket_vmnet/1.1.2copy

ls -al /opt/homebrew/opt/socket_vmnet
# ... /opt/homebrew/opt/socket_vmnet -> ../Cellar/socket_vmnet/1.1.2
copy

So in this case our actual path is

/opt/homebrew/Cellar/socket_vmnet/1.1.2/bin/socket_vmnet
copy

Edit ~/.lima/_config/networks.yamlcopy and amend the socketVMNetcopy property to use the path above

paths:
# socketVMNet requires Lima >= 0.12 .
# socketVMNet has precedence over vdeVMNet.
  #socketVMNet: "/opt/socket_vmnet/bin/socket_vmnet"
  # Use full path to `socket_vmnet` binary rather than symlink 
  # Eg. Don't use '${HOMEBREW_PREFIX}/opt/socket_vmnet/bin/socket_vmnet'
  socketVMNet: "/opt/homebrew/Cellar/socket_vmnet/1.1.2/bin/socket_vmnet"
# vdeSwitch and vdeVMNet are DEPRECATED.
  vdeSwitch: /opt/vde/bin/vde_switch
  vdeVMNet: /opt/vde/bin/vde_vmnet
  varRun: /private/var/run/lima
  sudoers: /private/etc/sudoers.d/lima

group: everyone

networks:
  shared:
    mode: shared
    gateway: 192.168.105.1
    dhcpEnd: 192.168.105.254
    netmask: 255.255.255.0
  bridged:
    mode: bridged
    interface: en0
    # bridged mode doesn't have a gateway; dhcp is managed by outside network
  host:
    mode: host
    gateway: 192.168.106.1
    dhcpEnd: 192.168.106.254
    netmask: 255.255.255.0
copy

 


Repeat the following step when ~/.lima/_config/networks.yamlcopy is edited.

Configure sudoers for launching socket_vmnetcopy

limactl sudoers > etc_sudoers.d_lima
sudo install -o root etc_sudoers.d_lima /etc/sudoers.d/lima
rm etc_sudoers.d_lima
copy

 


Basic usage

Based on a great article on baptistout.net I was able to create a Lima configuration that provides the following:

  • base Debian 11 (Bullseye) image
  • install the Docker daemon
  • configure sharedcopy networking
limactl --name debian-01 start ./vm/lima-debian-docker.yaml
copy

Sample output

# ? Creating an instance "debian-01"  [Use arrows to move, type to filter]
# > Proceed with the current configuration
#   Open an editor to review or modify the current configuration
#   Choose another example (docker, podman, archlinux, fedora, ...)
#   Exit

# ? Creating an instance "debian-01" Proceed with the current configuration
# INFO[0019] Starting socket_vmnet daemon for "shared-01" network 
# INFO[0019] Attempting to download the image              arch=aarch64 digest="sha512:97b888a2c59571494c628a1ef178c715914eac4de7e448fbc5d0673eae78336a37f0ac0c1d5a5ae8af201c67b84d6d2476cda6367cc5d00d2416f5e1ee9f912c" location="https://cloud.debian.org/images/cloud/bullseye/20230515-1381/debian-01-generic-arm64-20230515-1381.qcow2"
# INFO[0019] Using cache "/Users/jase/Library/Caches/lima/download/by-url-sha256/7c0eb03fa418b449d847f05df3703e4a172ad6b2231996e23c5d37c8451978ec/data" 
# INFO[0020] [hostagent] Starting QEMU (hint: to watch the boot progress, see "/Users/jase/.lima/debian-01/serial.log") 
# INFO[0020] SSH Local Port: 51706                        
# INFO[0020] [hostagent] Waiting for the essential requirement 1 of 5: "ssh" 
# INFO[0027] [hostagent] The essential requirement 1 of 5 is satisfied 
# INFO[0027] [hostagent] Waiting for the essential requirement 2 of 5: "user session is ready for ssh" 
# INFO[0027] [hostagent] The essential requirement 2 of 5 is satisfied 
# INFO[0027] [hostagent] Waiting for the essential requirement 3 of 5: "sshfs binary to be installed" 
# INFO[0033] [hostagent] The essential requirement 3 of 5 is satisfied 
# INFO[0033] [hostagent] Waiting for the essential requirement 4 of 5: "/etc/fuse.conf (/etc/fuse3.conf) to contain \"user_allow_other\"" 
# INFO[0039] [hostagent] The essential requirement 4 of 5 is satisfied 
# INFO[0039] [hostagent] Waiting for the essential requirement 5 of 5: "the guest agent to be running" 
# INFO[0039] [hostagent] The essential requirement 5 of 5 is satisfied 
# INFO[0039] [hostagent] Mounting "/Users/jase" on "/Users/jase" 
# INFO[0039] [hostagent] Mounting "/tmp/lima" on "/tmp/lima" 
# INFO[0039] [hostagent] Waiting for the optional requirement 1 of 1: "user probe 1/1" 
# INFO[0039] [hostagent] Forwarding "/run/user/501/docker.sock" (guest) to "/Users/jase/.lima/debian-01/sock/docker.sock" (host) 
# INFO[0039] [hostagent] Forwarding "/run/lima-guestagent.sock" (guest) to "/Users/jase/.lima/debian-01/ga.sock" (host) 
# INFO[0039] [hostagent] Not forwarding TCP 0.0.0.0:22    
# INFO[0039] [hostagent] Not forwarding TCP [::]:22       
# INFO[0060] [hostagent] The optional requirement 1 of 1 is satisfied 
# INFO[0060] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished" 
# INFO[0063] [hostagent] The final requirement 1 of 1 is satisfied 
# INFO[0063] READY. Run `limactl shell debian-01` to open the shell. 
# INFO[0063] Message from the instance "debian-01":       
# To run `docker` on the host (assumes docker-cli is installed), run the following commands:
# ------
# docker context create lima-debian-01 --docker "host=unix:///Users/jase/.lima/debian-01/sock/docker.sock"
# docker context use lima-debian-01
# docker run hello-world
# ------
copy

 


Docker on Lima VM

Test the Docker installation on the newly created Lima VM instance

Note that only the Docker CLI is required on the Mac host.
This does not require Docker Desktop.

To install just the Docker CLI

brew info docker
brew install docker
copy

image

docker context list

docker context create lima-debian-01 --docker "host=unix:///Users/jase/.lima/debian-01/sock/docker.sock"
docker context list

docker context use lima-debian-01
docker images
copy

 


Find IP address on Lima VM

limactl shell debian-01 -- ip -4 addr show lima0 | grep -oE 'inet\s[0-9]+(\.[0-9]+){3}' | cut -d ' ' -f2
copy

 


Advanced usage

todo ;)