Skip to content

Commit b3067dc

Browse files
authored
Merge pull request #1951 from AkihiroSuda/vz-default
Use VZ by default for new instances on macOS >= 13.5
2 parents 74e2fda + df05b81 commit b3067dc

File tree

12 files changed

+126
-23
lines changed

12 files changed

+126
-23
lines changed

Diff for: .github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ jobs:
148148

149149
integration:
150150
name: Integration tests
151+
# on macOS 12, the default vmType is QEMU
151152
runs-on: macos-12
152153
timeout-minutes: 120
153154
steps:
@@ -405,13 +406,14 @@ jobs:
405406

406407
vz:
407408
name: "vz"
409+
# on macOS 13, the default vmType is VZ
408410
runs-on: macos-13
409411
timeout-minutes: 120
410412
strategy:
411413
fail-fast: false
412414
matrix:
413415
template:
414-
- experimental/vz.yaml
416+
- default.yaml
415417
- fedora.yaml
416418
steps:
417419
- uses: actions/checkout@v4
@@ -438,8 +440,6 @@ jobs:
438440
- name: Uninstall qemu
439441
run: brew uninstall --ignore-dependencies --force qemu
440442
- name: Test
441-
env:
442-
LIMACTL_CREATE_ARGS: "--vm-type vz --mount-type virtiofs --rosetta --network vzNAT"
443443
run: ./hack/test-templates.sh templates/${{ matrix.template }}
444444
- if: failure()
445445
uses: ./.github/actions/upload_failure_logs_if_exists

Diff for: cmd/limactl/editflags/editflags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
196196
return fmt.Sprintf(".rosetta.enabled = %v | .rosetta.binfmt = %v", b, b), nil
197197
},
198198
false,
199-
true,
199+
false,
200200
},
201201
{"set", d("%s"), false, false},
202202
{

Diff for: examples/default.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# Default values in this YAML file are specified by `null` instead of Lima's "builtin default" values,
66
# so they can be overridden by the $LIMA_HOME/_config/default.yaml mechanism documented at the end of this file.
77

8-
# VM type: "qemu" or "vz" (on macOS 13 and later).
8+
# VM type: "qemu", "vz" (on macOS 13 and later), or "default".
99
# The vmType can be specified only on creating the instance.
1010
# The vmType of existing instances cannot be changed.
11-
# 🟢 Builtin default: "qemu"
11+
# 🟢 Builtin default: "vz" (on macOS 13.5 and later), "qemu" (on others)
1212
vmType: null
1313

1414
# OS: "Linux".
@@ -99,7 +99,7 @@ mounts:
9999
writable: true
100100

101101
# Mount type for above mounts, such as "reverse-sshfs" (from sshocker), "9p" (EXPERIMENTAL, from QEMU’s virtio-9p-pci, aka virtfs),
102-
# or "virtiofs" (EXPERIMENTAL, needs `vmType: vz`)
102+
# or "virtiofs" (EXPERIMENTAL, needs `vmType: vz`; will graduate from experimental in Lima v1.0)
103103
# 🟢 Builtin default: "reverse-sshfs" (for QEMU), "virtiofs" (for vz)
104104
mountType: null
105105

@@ -267,7 +267,7 @@ cpuType:
267267
# x86_64: "qemu64" # (or "host,-pdpe1gb" when running on x86_64 host)
268268

269269
rosetta:
270-
# Enable Rosetta for Linux (EXPERIMENTAL).
270+
# Enable Rosetta for Linux (EXPERIMENTAL; will graduate from experimental in Lima v1.0).
271271
# Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
272272
# 🟢 Builtin default: false
273273
enabled: null
@@ -281,7 +281,7 @@ rosetta:
281281
timezone: null
282282

283283
firmware:
284-
# Use legacy BIOS instead of UEFI. Ignored for aarch64.
284+
# Use legacy BIOS instead of UEFI. Ignored for aarch64 and vz.
285285
# 🟢 Builtin default: false
286286
legacyBIOS: null
287287
# # Override UEFI images
@@ -343,7 +343,7 @@ networks:
343343

344344

345345
# The "vzNAT" IP address is accessible from the host, but not from other guests.
346-
# Needs `vmType: vz` (EXPERIMENTAL).
346+
# Needs `vmType: vz` (EXPERIMENTAL; will graduate from experimental in Lima v1.0).
347347
# - vzNAT: true
348348

349349
# Port forwarding rules. Forwarding between ports 22 and ssh.localPort cannot be overridden.

Diff for: examples/experimental/vz.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# ⚠️ ⚠️ ⚠️ `template://experimental/vz` will be removed in Lima v1.0,
2+
# as vz will graduate from experimental and will be the default vmType.
3+
#
4+
# For Lima v1.0 and later, use the following command instead:
5+
# ```
6+
# limactl create template://default
7+
# ```
8+
19
# A template to run ubuntu using vmType: vz instead of qemu (Default)
210
# This template requires Lima v0.14.0 or later and macOS 13.
311
vmType: "vz"

Diff for: pkg/limayaml/defaults.go

+91-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package limayaml
33
import (
44
"bytes"
55
"crypto/sha256"
6+
"errors"
67
"fmt"
78
"net"
89
"os"
@@ -13,6 +14,7 @@ import (
1314
"strings"
1415
"text/template"
1516

17+
"github.com/coreos/go-semver/semver"
1618
"github.com/docker/go-units"
1719
"github.com/pbnjay/memory"
1820
"github.com/sirupsen/logrus"
@@ -178,7 +180,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
178180
if o.VMType != nil {
179181
y.VMType = o.VMType
180182
}
181-
y.VMType = ptr.Of(ResolveVMType(y.VMType))
183+
y.VMType = ptr.Of(ResolveVMType(y, d, o, filePath))
182184
if y.OS == nil {
183185
y.OS = d.OS
184186
}
@@ -924,11 +926,96 @@ func NewVMType(driver string) VMType {
924926
}
925927
}
926928

927-
func ResolveVMType(s *string) VMType {
928-
if s == nil || *s == "" || *s == "default" {
929+
func isExistingInstanceDir(dir string) bool {
930+
// existence of "lima.yaml" does not signify existence of the instance,
931+
// because the file is created during the initialization of the instance.
932+
for _, f := range []string{
933+
filenames.HostAgentStdoutLog, filenames.HostAgentStderrLog,
934+
filenames.VzIdentifier, filenames.BaseDisk, filenames.DiffDisk, filenames.CIDataISO,
935+
} {
936+
file := filepath.Join(dir, f)
937+
if _, err := os.Lstat(file); !errors.Is(err, os.ErrNotExist) {
938+
return true
939+
}
940+
}
941+
return false
942+
}
943+
944+
func ResolveVMType(y, d, o *LimaYAML, filePath string) VMType {
945+
// Check if the VMType is explicitly specified
946+
for i, f := range []*LimaYAML{o, y, d} {
947+
if f.VMType != nil && *f.VMType != "" && *f.VMType != "default" {
948+
logrus.Debugf("ResolveVMType: resolved VMType %q (explicitly specified in []*LimaYAML{o,y,d}[%d])", *f.VMType, i)
949+
return NewVMType(*f.VMType)
950+
}
951+
}
952+
953+
// If this is an existing instance, guess the VMType from the contents of the instance directory.
954+
if dir, basename := filepath.Split(filePath); dir != "" && basename == filenames.LimaYAML && isExistingInstanceDir(dir) {
955+
vzIdentifier := filepath.Join(dir, filenames.VzIdentifier) // since Lima v0.14
956+
if _, err := os.Lstat(vzIdentifier); !errors.Is(err, os.ErrNotExist) {
957+
logrus.Debugf("ResolveVMType: resolved VMType %q (existing instance, with %q)", VZ, vzIdentifier)
958+
return VZ
959+
}
960+
logrus.Debugf("ResolveVMType: resolved VMType %q (existing instance, without %q)", QEMU, vzIdentifier)
961+
return QEMU
962+
}
963+
964+
// Resolve the best type, depending on GOOS
965+
switch runtime.GOOS {
966+
case "darwin":
967+
macOSProductVersion, err := osutil.ProductVersion()
968+
if err != nil {
969+
logrus.WithError(err).Warn("Failed to get macOS product version")
970+
logrus.Debugf("ResolveVMType: resolved VMType %q (default for unknown version of macOS)", QEMU)
971+
return QEMU
972+
}
973+
// Virtualization.framework in macOS prior to 13.5 could not boot Linux kernel v6.2 on Intel
974+
// https://github.com/lima-vm/lima/issues/1577
975+
if macOSProductVersion.LessThan(*semver.New("13.5.0")) {
976+
logrus.Debugf("ResolveVMType: resolved VMType %q (default for macOS prior to 13.5)", QEMU)
977+
return QEMU
978+
}
979+
// Use QEMU if the config depends on QEMU
980+
for i, f := range []*LimaYAML{o, y, d} {
981+
if f.Arch != nil && !IsNativeArch(*f.Arch) {
982+
logrus.Debugf("ResolveVMType: resolved VMType %q (non-native arch=%q is specified in []*LimaYAML{o,y,d}[%d])", QEMU, *f.Arch, i)
983+
return QEMU
984+
}
985+
if f.Firmware.LegacyBIOS != nil && *f.Firmware.LegacyBIOS {
986+
logrus.Debugf("ResolveVMType: resolved VMType %q (firmware.legacyBIOS is specified in []*LimaYAML{o,y,d}[%d])", QEMU, i)
987+
return QEMU
988+
}
989+
if f.MountType != nil && *f.MountType == NINEP {
990+
logrus.Debugf("ResolveVMType: resolved VMType %q (mountType=%q is specified in []*LimaYAML{o,y,d}[%d])", QEMU, NINEP, i)
991+
return QEMU
992+
}
993+
if f.Audio.Device != nil {
994+
switch *f.Audio.Device {
995+
case "", "none", "default", "vz":
996+
// NOP
997+
default:
998+
logrus.Debugf("ResolveVMType: resolved VMType %q (audio.device=%q is specified in []*LimaYAML{o,y,d}[%d])", QEMU, *f.Audio.Device, i)
999+
return QEMU
1000+
}
1001+
}
1002+
if f.Video.Display != nil {
1003+
switch *f.Video.Display {
1004+
case "", "none", "default", "vz":
1005+
// NOP
1006+
default:
1007+
logrus.Debugf("ResolveVMType: resolved VMType %q (video.display=%q is specified in []*LimaYAML{o,y,d}[%d])", QEMU, *f.Video.Display, i)
1008+
return QEMU
1009+
}
1010+
}
1011+
}
1012+
// Use VZ if the config is compatible with VZ
1013+
logrus.Debugf("ResolveVMType: resolved VMType %q (default for macOS 13.5 and later)", VZ)
1014+
return VZ
1015+
default:
1016+
logrus.Debugf("ResolveVMType: resolved VMType %q (default for GOOS=%q)", QEMU, runtime.GOOS)
9291017
return QEMU
9301018
}
931-
return NewVMType(*s)
9321019
}
9331020

9341021
func ResolveOS(s *string) OS {

Diff for: pkg/limayaml/defaults_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import (
1414
"github.com/lima-vm/lima/pkg/ptr"
1515
"github.com/lima-vm/lima/pkg/store/dirnames"
1616
"github.com/lima-vm/lima/pkg/store/filenames"
17+
"github.com/sirupsen/logrus"
1718
"gotest.tools/v3/assert"
1819
)
1920

2021
func TestFillDefault(t *testing.T) {
22+
logrus.SetLevel(logrus.DebugLevel)
2123
var d, y, o LimaYAML
2224

25+
defaultVMType := ResolveVMType(&y, &d, &o, "")
26+
2327
opts := []cmp.Option{
2428
// Consider nil slices and empty slices to be identical
2529
cmpopts.EquateEmpty(),
@@ -59,7 +63,7 @@ func TestFillDefault(t *testing.T) {
5963

6064
// Builtin default values
6165
builtin := LimaYAML{
62-
VMType: ptr.Of("qemu"),
66+
VMType: &defaultVMType,
6367
OS: ptr.Of(LINUX),
6468
Arch: ptr.Of(arch),
6569
CPUType: defaultCPUType(),
@@ -192,6 +196,7 @@ func TestFillDefault(t *testing.T) {
192196
}
193197

194198
expect := builtin
199+
expect.VMType = ptr.Of(QEMU) // due to NINEP
195200
expect.HostResolver.Hosts = map[string]string{
196201
"MY.Host": "host.lima.internal",
197202
}
@@ -472,6 +477,8 @@ func TestFillDefault(t *testing.T) {
472477

473478
expect.Param["TWO"] = d.Param["TWO"]
474479

480+
t.Logf("d.vmType=%q, y.vmType=%q, expect.vmType=%q", *d.VMType, *y.VMType, *expect.VMType)
481+
475482
FillDefault(&y, &d, &LimaYAML{}, filePath)
476483
assert.DeepEqual(t, &y, &expect, opts...)
477484

Diff for: pkg/limayaml/validate.go

-3
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,6 @@ func warnExperimental(y *LimaYAML) {
447447
if *y.MountType == VIRTIOFS && runtime.GOOS == "linux" {
448448
logrus.Warn("`mountType: virtiofs` on Linux is experimental")
449449
}
450-
if *y.VMType == VZ {
451-
logrus.Warn("`vmType: vz` is experimental")
452-
}
453450
if *y.Arch == RISCV64 {
454451
logrus.Warn("`arch: riscv64` is experimental")
455452
}

Diff for: pkg/vz/vz_driver_darwin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (l *LimaVzDriver) Validate() error {
8080
return fmt.Errorf("field `mountType` must be %q or %q for VZ driver , got %q", limayaml.REVSSHFS, limayaml.VIRTIOFS, *l.Yaml.MountType)
8181
}
8282
if *l.Yaml.Firmware.LegacyBIOS {
83-
return fmt.Errorf("`firmware.legacyBIOS` configuration is not supported for VZ driver")
83+
logrus.Warnf("vmType %s: ignoring `firmware.legacyBIOS`", *l.Yaml.VMType)
8484
}
8585
for _, f := range l.Yaml.Firmware.Images {
8686
switch f.VMType {

Diff for: website/content/en/docs/config/multi-arch/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ See also https://github.com/containerd/nerdctl/blob/master/docs/multi-platform.m
6363
## [Fast mode 2 (Rosetta): Intel containers on ARM VM on ARM Host](#fast-mode-2)
6464

6565
> **Warning**
66-
> "vz" mode, including support for Rosetta, is experimental
66+
> "vz" mode, including support for Rosetta, is experimental (will graduate from experimental in Lima v1.0)
6767
6868
| ⚡ Requirement | Lima >= 0.14, macOS >= 13.0, ARM |
6969
|-------------------|----------------------------------|

Diff for: website/content/en/docs/config/network/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ networks:
180180
### vzNAT
181181

182182
> **Warning**
183-
> "vz" mode is experimental
183+
> "vz" mode is experimental (will graduate from experimental in Lima v1.0)
184184
185185
| ⚡ Requirement | Lima >= 0.14, macOS >= 13.0 |
186186
|-------------------|-----------------------------|

Diff for: website/content/en/docs/config/vmtype/_index.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ flowchart
2222
intel_on_arm -- "No" --> vz["VZ"]
2323
```
2424

25+
The default vmType is QEMU in Lima prior to v1.0.
26+
Starting with Lima v1.0, Lima will use VZ by default on macOS (>= 13.5) for new instances,
27+
unless the config is incompatible with VZ. (e.g., legacyBIOS or 9p is enabled)
28+
2529
## QEMU
2630
"qemu" option makes use of QEMU to run guest operating system.
27-
This option is used by default if "vmType" is not set.
2831

2932
## VZ
3033
> **Warning**
31-
> "vz" mode is experimental
34+
> "vz" mode is experimental (will graduate from experimental in Lima v1.0)
3235
3336
| ⚡ Requirement | Lima >= 0.14, macOS >= 13.0 |
3437
|-------------------|-----------------------------|

Diff for: website/content/en/docs/releases/experimental/_index.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following features are experimental and subject to change:
99
- `mountType: 9p`
1010
- `mountType: virtiofs` on Linux
1111
- `vmType: vz` and relevant configurations (`mountType: virtiofs`, `rosetta`, `[]networks.vzNAT`)
12+
(will graduate from experimental in Lima v1.0)
1213
- `vmType: wsl2` and relevant configurations (`mountType: wsl2`)
1314
- `arch: riscv64`
1415
- `video.display: vnc` and relevant configuration (`video.vnc.display`)

0 commit comments

Comments
 (0)