Skip to content

Commit bf0bfc3

Browse files
committed
Mount the rosetta volume in user-data
After creating the `binfmt.d(5)` configuration for Rosetta, `systemd-binfmt.service(8)` attempts to register at an earlier stage in subsequent boots. To prevent errors from not finding the Rosetta interpreter, `user-data` is used to mount the Rosetta volume earlier. Signed-off-by: Norio Nomura <[email protected]>
1 parent 58bb804 commit bf0bfc3

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,31 @@ if [ -f /etc/alpine-release ]; then
1010
rc-service qemu-binfmt stop --ifstarted
1111
fi
1212

13-
mkdir -p /mnt/lima-rosetta
14-
15-
#Check selinux is enabled by kernel
16-
if [ -d /sys/fs/selinux ]; then
17-
##########################################################################################
18-
## When using vz & virtiofs, initially container_file_t selinux label
19-
## was considered which works perfectly for container work loads
20-
## but it might break for other work loads if the process is running with
21-
## different label. Also these are the remote mounts from the host machine,
22-
## so keeping the label as nfs_t fits right. Package container-selinux by
23-
## default adds rules for nfs_t context which allows container workloads to work as well.
24-
## https://github.com/lima-vm/lima/pull/1965
25-
##########################################################################################
26-
mount -t virtiofs vz-rosetta /mnt/lima-rosetta -o context="system_u:object_r:nfs_t:s0"
27-
else
28-
mount -t virtiofs vz-rosetta /mnt/lima-rosetta
13+
# Mount the rosetta volume for non cloud-init based images
14+
rosetta_interpreter=/mnt/lima-rosetta/rosetta
15+
if [ ! -f "$rosetta_interpreter" ]; then
16+
rosetta_mountpoint=$(dirname "$rosetta_interpreter")
17+
mkdir -p "$rosetta_mountpoint"
18+
19+
#Check selinux is enabled by kernel
20+
if [ -d /sys/fs/selinux ]; then
21+
##########################################################################################
22+
## When using vz & virtiofs, initially container_file_t selinux label
23+
## was considered which works perfectly for container work loads
24+
## but it might break for other work loads if the process is running with
25+
## different label. Also these are the remote mounts from the host machine,
26+
## so keeping the label as nfs_t fits right. Package container-selinux by
27+
## default adds rules for nfs_t context which allows container workloads to work as well.
28+
## https://github.com/lima-vm/lima/pull/1965
29+
##########################################################################################
30+
mount -t virtiofs vz-rosetta "$rosetta_mountpoint" -o context="system_u:object_r:nfs_t:s0"
31+
else
32+
mount -t virtiofs vz-rosetta "$rosetta_mountpoint"
33+
fi
2934
fi
3035

3136
if [ "$LIMA_CIDATA_ROSETTA_BINFMT" = "true" ]; then
32-
rosetta_binfmt=":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/lima-rosetta/rosetta:OCF"
37+
rosetta_binfmt=":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:$rosetta_interpreter:OCF"
3338

3439
# If rosetta is not registered in binfmt_misc, register it.
3540
[ -f /proc/sys/fs/binfmt_misc/rosetta ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register

pkg/cidata/cidata.TEMPLATE.d/user-data

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ package_upgrade: true
1111
package_reboot_if_required: true
1212
{{- end }}
1313

14-
{{- if or (eq .MountType "9p") (eq .MountType "virtiofs") }}
15-
{{- if .Mounts }}
14+
{{- if or .RosettaEnabled (or (eq .MountType "9p") (eq .MountType "virtiofs")) }}
1615
mounts:
17-
{{- range $m := $.Mounts}}
16+
# Mount the rosetta volume before systemd-binfmt.service(8) starts
17+
{{- if .RosettaEnabled }}
18+
- ["vz-rosetta", "/mnt/lima-rosetta", "virtiofs", "context=\"system_u:object_r:nfs_t:s0\""]
19+
{{- end }}
20+
{{- if .Mounts }}
21+
{{- range $m := $.Mounts}}
1822
- [{{$m.Tag}}, {{$m.MountPoint}}, {{$m.Type}}, "{{$m.Options}}", "0", "0"]
23+
{{- end }}
1924
{{- end }}
2025
{{- end }}
21-
{{- end }}
2226

2327
{{- if .TimeZone }}
2428
timezone: {{.TimeZone}}

0 commit comments

Comments
 (0)