diff --git a/docs/vmtype.md b/docs/vmtype.md index d3db89186e5..1512bda5cc7 100644 --- a/docs/vmtype.md +++ b/docs/vmtype.md @@ -4,6 +4,9 @@ Lima supports two ways of running guest machines: - [qemu](#qemu) - [vz](#vz) +The vmType can be specified only on creating the instance. +The vmType of existing instances cannot be changed. + ## QEMU "qemu" option makes use of QEMU to run guest operating system. This option is used by default if "vmType" is not set. diff --git a/examples/default.yaml b/examples/default.yaml index c7b63976d80..e321dc9c929 100644 --- a/examples/default.yaml +++ b/examples/default.yaml @@ -6,6 +6,8 @@ # so they can be overridden by the $LIMA_HOME/_config/default.yaml mechanism documented at the end of this file. # VM type: "qemu" or "vz" (on macOS 13 and later). +# The vmType can be specified only on creating the instance. +# The vmType of existing instances cannot be changed. # 🟢 Builtin default: "qemu" vmType: null diff --git a/pkg/vz/vm_darwin.go b/pkg/vz/vm_darwin.go index 286ca1cb3dc..247195aebe2 100644 --- a/pkg/vz/vm_darwin.go +++ b/pkg/vz/vm_darwin.go @@ -20,6 +20,7 @@ import ( "github.com/lima-vm/lima/pkg/limayaml" "github.com/lima-vm/lima/pkg/localpathutil" "github.com/lima-vm/lima/pkg/networks" + "github.com/lima-vm/lima/pkg/qemu/imgutil" "github.com/lima-vm/lima/pkg/store/filenames" "github.com/sirupsen/logrus" ) @@ -242,6 +243,18 @@ func attachNetwork(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfigu return nil } +func validateDiskFormat(diskPath string) error { + format, err := imgutil.DetectFormat(diskPath) + if err != nil { + return fmt.Errorf("failed to detect the format of %q: %w", diskPath, err) + } + if format != "raw" { + return fmt.Errorf("expected the format of %q to be \"raw\", got %q", diskPath, format) + } + // TODO: ensure that the disk is formatted with GPT or ISO9660 + return nil +} + func attachDisks(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfiguration) error { baseDiskPath := filepath.Join(driver.Instance.Dir, filenames.BaseDisk) diffDiskPath := filepath.Join(driver.Instance.Dir, filenames.DiffDisk) @@ -253,6 +266,9 @@ func attachDisks(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfigura var configurations []vz.StorageDeviceConfiguration if isBaseDiskCDROM { + if err = validateDiskFormat(baseDiskPath); err != nil { + return err + } baseDiskAttachment, err := vz.NewDiskImageStorageDeviceAttachment(baseDiskPath, true) if err != nil { return err @@ -263,6 +279,9 @@ func attachDisks(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfigura } configurations = append(configurations, baseDisk) } + if err = validateDiskFormat(diffDiskPath); err != nil { + return err + } diffDiskAttachment, err := vz.NewDiskImageStorageDeviceAttachment(diffDiskPath, false) if err != nil { return err @@ -273,6 +292,9 @@ func attachDisks(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfigura } configurations = append(configurations, diffDisk) + if err = validateDiskFormat(ciDataPath); err != nil { + return err + } ciDataAttachment, err := vz.NewDiskImageStorageDeviceAttachment(ciDataPath, true) if err != nil { return err @@ -335,7 +357,7 @@ func attachConsole(_ *driver.BaseDriver, vmConfig *vz.VirtualMachineConfiguratio } func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfiguration) error { - mounts := make([]vz.DirectorySharingDeviceConfiguration, len(driver.Yaml.Mounts)) + var mounts []vz.DirectorySharingDeviceConfiguration if *driver.Yaml.MountType == limayaml.VIRTIOFS { for i, mount := range driver.Yaml.Mounts { expandedPath, err := localpathutil.Expand(mount.Location) @@ -364,7 +386,7 @@ func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineCo return err } config.SetDirectoryShare(share) - mounts[i] = config + mounts = append(mounts, config) } } @@ -378,7 +400,9 @@ func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineCo } } - vmConfig.SetDirectorySharingDevicesVirtualMachineConfiguration(mounts) + if len(mounts) > 0 { + vmConfig.SetDirectorySharingDevicesVirtualMachineConfiguration(mounts) + } return nil }