From 8504e748cb87781edfbd640a0533c85e0778bc5e Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Tue, 3 Jan 2023 08:45:43 +0100 Subject: [PATCH 1/2] vm: make rosetta emulation configurable --- cmd/start.go | 8 ++++++++ config/config.go | 5 +++-- embedded/defaults/colima.yaml | 4 ++++ environment/vm/lima/yaml.go | 4 ++-- util/util.go | 5 +++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index 9c2d47a69..1b4ec4c12 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -146,6 +146,9 @@ func init() { } if util.MacOS13OrNewer() { startCmd.Flags().StringVarP(&startCmdArgs.VMType, "vm-type", "t", defaultVMType, "virtual machine type ("+types+")") + if util.MacOS13OrNewerOnM1() { + startCmd.Flags().BoolVar(&startCmdArgs.VZRosetta, "vz-rosetta", false, "enable Rosetta for amd64 emulation") + } } // config @@ -364,6 +367,11 @@ func prepareConfig(cmd *cobra.Command) { startCmdArgs.VMType = current.VMType } } + if util.MacOS13OrNewerOnM1() { + if !cmd.Flag("vz-rosetta").Changed { + startCmdArgs.VZRosetta = current.VZRosetta + } + } } } diff --git a/config/config.go b/config/config.go index a4387bfac..993045aa9 100644 --- a/config/config.go +++ b/config/config.go @@ -79,8 +79,9 @@ type Config struct { Network Network `yaml:"network,omitempty"` Env map[string]string `yaml:"env,omitempty"` // environment variables - // VM VMType - VMType string `yaml:"vmType,omitempty"` + // VM + VMType string `yaml:"vmType,omitempty"` + VZRosetta bool `yaml:"rosetta,omitempty"` // volume mounts Mounts []Mount `yaml:"mounts,omitempty"` diff --git a/embedded/defaults/colima.yaml b/embedded/defaults/colima.yaml index 1f0c3a3cb..0fcfea66d 100644 --- a/embedded/defaults/colima.yaml +++ b/embedded/defaults/colima.yaml @@ -113,6 +113,10 @@ docker: {} # Default: qemu vmType: qemu +# Utilise rosetta for amd64 emulation (requires m1 mac and vmType `vz`) +# Default: false +rosetta: false + # Volume mount driver for the virtual machine (virtiofs, 9p, sshfs). # # virtiofs is limited to macOS and vmType `vz`. It is the fastest of the options. diff --git a/environment/vm/lima/yaml.go b/environment/vm/lima/yaml.go index 7feb22570..dcc881862 100644 --- a/environment/vm/lima/yaml.go +++ b/environment/vm/lima/yaml.go @@ -35,12 +35,12 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) { l.VMType = VZ // Rosetta is only available on M1 - if l.Arch == environment.AARCH64 { + if conf.VZRosetta && util.MacOS13OrNewerOnM1() { if util.RosettaRunning() { l.Rosetta.Enabled = true l.Rosetta.BinFmt = true } else { - logrus.Warnln("Rosetta2 is not installed, linux/amd64 containers will run much slower") + logrus.Warnln("Unable to enable Rosetta: Rosetta2 is not installed") logrus.Warnln("Run 'softwareupdate --install-rosetta' to install Rosetta2") } } diff --git a/util/util.go b/util/util.go index 309b91043..c8b51d199 100644 --- a/util/util.go +++ b/util/util.go @@ -30,6 +30,11 @@ func MacOS() bool { return runtime.GOOS == "darwin" } +// MacOS13OrNewer returns if the current OS is macOS 13 or newer. +func MacOS13OrNewerOnM1() bool { + return runtime.GOARCH == "arm64" && MacOS13OrNewer() +} + // MacOS13OrNewer returns if the current OS is macOS 13 or newer. func MacOS13OrNewer() bool { if !MacOS() { From 3ea2e6fbe1aeae36cfccf5f93736e9819dd02b14 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Tue, 3 Jan 2023 08:46:22 +0100 Subject: [PATCH 2/2] vm: fix regression, qemu vmType always used --- cmd/start.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/start.go b/cmd/start.go index 1b4ec4c12..6305c2dee 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -224,7 +224,10 @@ func mountsFromFlag(mounts []string) []config.Mount { } func setDefaults(cmd *cobra.Command) { - startCmdArgs.VMType = "qemu" + if startCmdArgs.VMType == "" { + startCmdArgs.VMType = "qemu" + } + if util.MacOS13OrNewer() { // changing to vz implies changing mount type to virtiofs if cmd.Flag("vm-type").Changed && startCmdArgs.VMType == "vz" && !cmd.Flag("mount-type").Changed {