Skip to content

Commit

Permalink
vz: configure Rosetta’s ahead of time (AOT) caching options using an …
Browse files Browse the repository at this point in the history
…abstract socket

This change allows starting the `/mnt/lima-rosetta/rosttad daemon` in the VM.
Without this change, it cannot be started as shown below:
```console
$ sudo /mnt/lima-rosetta/rosettad daemon
rosetta error: Failed bind socket: 98
Trace/breakpoint trap
```

Since `rosettad` needs to run in the same namespace as `rosetta` and must be executed directly from `/mnt/lima-rosetta/rosettad` (copies of `rosettad` do not work), it is difficult to use during container image builds or similar processes.

In a container, `rosettad` can be run as follows:
```console
$ docker run -it --rm --platform linux/amd64 --name test-rosettad -v/mnt/lima-rosetta:/mnt/lima-rosetta ubuntu
root@45f887cb0eaa:/# ls -la ~/.cache/rosettad
/usr/bin/ls: cannot access '/root/.cache/rosettad': No such file or directory
root@45f887cb0eaa:/# /mnt/lima-rosetta/rosettad daemon&
[1] 10
root@45f887cb0eaa:/# ls -la ~/.cache/rosettad
total 2700
drwxr-xr-x 2 root root    4096 Jul 17 04:16 .
drwxr-xr-x 3 root root    4096 Jul 17 04:16 ..
-rwxr-xr-x 1 root root  186600 Jul 17 04:16 169a47096736cdeb5714fa040c30ef80426e439f02a3f4e4137733cbaae1fec5.aotcache
-rwxr-xr-x 1 root root  104848 Jul 17 04:16 1bea8094b78a3910345d80af3d182390fda07ae5788352651eb7773505dc39af.aotcache
-rwxr-xr-x 1 root root  121772 Jul 17 04:16 9fb501baf5ceec1ff4c9abb0473492ab4a66893203b932e28dfaa5c73c05e191.aotcache
-rwxr-xr-x 1 root root  244608 Jul 17 04:16 b7695da977e205398b33922d61493cc1e436cd2321bb2e54fbdc39b95fabeff7.aotcache
-rwxr-xr-x 1 root root 2092260 Jul 17 04:16 fc4c52f3910ed57a088d19ab86c671358f5e917cd4e95b21fd08e4fd922c0aa2.aotcache
```

Even if `rosettad` is not running, it does not affect the operation of `rosetta`, so the existing functionality remains unchanged.

There is also a configuration to use Unix Domain Sockets instead of Abstract Sockets. However, it appears that some preparation is required on the VM guest side before mounting, and I was unable to make it work. Therefore, I am using the configuration with Abstract Sockets.

SeeAlso: https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta#4239539

Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
  • Loading branch information
norio-nomura committed Jul 17, 2024
1 parent 8ecee92 commit 644ad91
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/vz/rosetta_directory_share_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"

"github.com/Code-Hex/vz/v3"
"github.com/coreos/go-semver/semver"
"github.com/lima-vm/lima/pkg/osutil"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -33,6 +35,17 @@ func createRosettaDirectoryShareConfiguration() (*vz.VirtioFileSystemDeviceConfi
if err != nil {
return nil, fmt.Errorf("failed to create a new rosetta directory share: %w", err)
}
macOSProductVersion, err := osutil.ProductVersion()
if err != nil {
return nil, fmt.Errorf("failed to get macOS product version: %w", err)
}
if !macOSProductVersion.LessThan(*semver.New("14.0.0")) {
cachingOption, err := vz.NewLinuxRosettaAbstractSocketCachingOptions("rosetta")
if err != nil {
return nil, fmt.Errorf("failed to create a new rosetta directory share caching option: %w", err)
}
rosettaShare.SetOptions(cachingOption)
}
config.SetDirectoryShare(rosettaShare)

return config, nil
Expand Down

0 comments on commit 644ad91

Please sign in to comment.