Skip to content

Commit 5ef067b

Browse files
committed
Unregister rosetta if .rosetta.binfmt is not true
If `binfmt.d/rosetta.conf` already exists, Rosetta might already be registered by the time this script is called. To apply the settings in `lima.yml`, if Rosetta is already registered, the script will remove `binfmt.d/rosetta.conf` and unregister it from `binfmt_misc`. Signed-off-by: Norio Nomura <[email protected]>
1 parent 7c13a72 commit 5ef067b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

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

13+
binfmt_entry=/proc/sys/fs/binfmt_misc/rosetta
14+
binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf
1315
if [ "$LIMA_CIDATA_ROSETTA_BINFMT" = "true" ]; then
1416
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"
1517

1618
# If rosetta is not registered in binfmt_misc, register it.
17-
[ -f /proc/sys/fs/binfmt_misc/rosetta ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register
19+
[ -f "$binfmt_entry" ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register
1820

1921
# Create binfmt.d(5) configuration to prioritize rosetta even if qemu-user-static is installed on systemd based systems.
20-
binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf
2122
# If the binfmt.d directory exists, consider systemd-binfmt.service(8) to be enabled and create the configuration file.
2223
[ ! -d "$(dirname "$binfmtd_conf")" ] || [ -f "$binfmtd_conf" ] || echo "$rosetta_binfmt" >"$binfmtd_conf"
24+
else
25+
# unregister rosetta from binfmt_misc if it exists
26+
[ ! -f "$binfmt_entry" ] || echo -1 | "$binfmt_entry"
27+
# remove binfmt.d(5) configuration if it exists
28+
[ ! -f "$binfmtd_conf" ] || rm "$binfmtd_conf"
2329
fi

0 commit comments

Comments
 (0)