Skip to content

Commit 2302641

Browse files
committed
Create rosetta.conf for binfmt.d(5)
Sometime `qemu-user-static` interpreters are registered with `systemd-binfmt.service(8)` by creating configuration files for `binfmt.d(5)`. By creating a `binfmt.d(5)` configuration for Rosetta, Rosetta will be prioritized over `qemu-user-static` regardless of the execution timing of `systemd-binfmt.service(8)`. In subsequent startups, Rosetta will already be registered with binfmt_misc at this stage, so a check has been added to prevent errors due to duplicate registrations. Signed-off-by: Norio Nomura <[email protected]>
1 parent 0f21216 commit 2302641

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ else
2929
fi
3030

3131
if [ "$LIMA_CIDATA_ROSETTA_BINFMT" = "true" ]; then
32-
echo \
33-
':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' \
34-
>/proc/sys/fs/binfmt_misc/register
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"
33+
34+
# If rosetta is not registered in binfmt_misc, register it.
35+
[ -f /proc/sys/fs/binfmt_misc/rosetta ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register
36+
37+
# Create binfmt.d(5) configuration to prioritize rosetta even if qemu-user-static is installed on systemd based systems.
38+
binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf
39+
# If the binfmt.d directory exists, consider systemd-binfmt.service(8) to be enabled and create the configuration file.
40+
[ ! -d "$(dirname "$binfmtd_conf")" ] || [ -f "$binfmtd_conf" ] || echo "$rosetta_binfmt" >"$binfmtd_conf"
3541
fi

0 commit comments

Comments
 (0)