From b6580e466cd94b2aab0468a729525886f14d1bb3 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Sat, 13 Jul 2024 09:11:41 +0900 Subject: [PATCH] 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 --- pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh index bb8369bf4450..38e71b3b00b0 100755 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh @@ -10,14 +10,20 @@ if [ -f /etc/alpine-release ]; then rc-service qemu-binfmt stop --ifstarted fi +binfmt_entry=/proc/sys/fs/binfmt_misc/rosetta +binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf if [ "$LIMA_CIDATA_ROSETTA_BINFMT" = "true" ]; then 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" # If rosetta is not registered in binfmt_misc, register it. - [ -f /proc/sys/fs/binfmt_misc/rosetta ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register + [ -f "$binfmt_entry" ] || echo "$rosetta_binfmt" >/proc/sys/fs/binfmt_misc/register # Create binfmt.d(5) configuration to prioritize rosetta even if qemu-user-static is installed on systemd based systems. - binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf # If the binfmt.d directory exists, consider systemd-binfmt.service(8) to be enabled and create the configuration file. [ ! -d "$(dirname "$binfmtd_conf")" ] || [ -f "$binfmtd_conf" ] || echo "$rosetta_binfmt" >"$binfmtd_conf" +else + # unregister rosetta from binfmt_misc if it exists + [ ! -f "$binfmt_entry" ] || echo -1 | "$binfmt_entry" + # remove binfmt.d(5) configuration if it exists + [ ! -f "$binfmtd_conf" ] || rm "$binfmtd_conf" fi