forked from crc-org/vfkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for `--device rosetta,mountTag=something` on the commandline. This is only available on system with Apple CPUs, vfkit will error out if this option is used on Intel CPUs. Once the VM is running and the rosetta share is mounted, rosetta support can be enabled by creating this file: $ cat /etc/binfmt.d/rosetta.conf :rosetta:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/mnt/rosetta:F and then running `systemctl restart systemd-binfmt` See these links for more details: https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta?language=objc https://docs.kernel.org/admin-guide/binfmt-misc.html https://www.man7.org/linux/man-pages/man5/binfmt.d.5.html This fixes crc-org#23
- Loading branch information
Showing
8 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package vf | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func (dev *RosettaShare) AddToVirtualMachineConfig(_ *vzVirtualMachineConfiguration) error { | ||
return fmt.Errorf("rosetta is unsupported on non-arm64 platforms") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package vf | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Code-Hex/vz/v3" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func checkRosettaAvailability(install bool) error { | ||
availability := vz.LinuxRosettaDirectoryShareAvailability() | ||
switch availability { | ||
case vz.LinuxRosettaAvailabilityNotSupported: | ||
return fmt.Errorf("rosetta is not supported") | ||
case vz.LinuxRosettaAvailabilityNotInstalled: | ||
if !install { | ||
return fmt.Errorf("rosetta is not installed") | ||
} | ||
log.Debugf("installing rosetta") | ||
if err := vz.LinuxRosettaDirectoryShareInstallRosetta(); err != nil { | ||
return fmt.Errorf("failed to install rosetta: %w", err) | ||
} | ||
log.Debugf("rosetta installed") | ||
case vz.LinuxRosettaAvailabilityInstalled: | ||
// nothing to do | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (dev *RosettaShare) toVz() (vz.DirectorySharingDeviceConfiguration, error) { | ||
if dev.MountTag == "" { | ||
return nil, fmt.Errorf("missing mandatory 'mountTage' option for rosetta share") | ||
} | ||
if err := checkRosettaAvailability(dev.InstallRosetta); err != nil { | ||
return nil, err | ||
} | ||
|
||
rosettaShare, err := vz.NewLinuxRosettaDirectoryShare() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create a new rosetta directory share: %w", err) | ||
} | ||
config, err := vz.NewVirtioFileSystemDeviceConfiguration(dev.MountTag) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create a new virtio file system configuration for rosetta: %w", err) | ||
} | ||
|
||
config.SetDirectoryShare(rosettaShare) | ||
|
||
return config, nil | ||
} | ||
|
||
func (dev *RosettaShare) AddToVirtualMachineConfig(vmConfig *vzVirtualMachineConfiguration) error { | ||
fileSystemDeviceConfig, err := dev.toVz() | ||
if err != nil { | ||
return err | ||
} | ||
log.Infof("Adding virtio-fs device") | ||
vmConfig.directorySharingDevicesConfiguration = append(vmConfig.directorySharingDevicesConfiguration, fileSystemDeviceConfig) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters