Skip to content

Commit df05b81

Browse files
committed
Use VZ by default for new instances on macOS >= 13.5
VZ is now the default type for new instances >= 13.5, unless the config is incompatible with vz (e.g., `firmware.legacyBIOS=true`, `mountType=9p`). Existing instances will continue to use QEMU by default, unless `vz-identifier` is present in the instance directory. Run `limactl start` with `--debug` to see how the vmType is resolved. Signed-off-by: Akihiro Suda <[email protected]>
1 parent 6ca4fb3 commit df05b81

File tree

5 files changed

+107
-10
lines changed

5 files changed

+107
-10
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: examples/default.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# 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".

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: website/content/en/docs/config/vmtype/_index.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ 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**

0 commit comments

Comments
 (0)