Skip to content

Commit

Permalink
Unregister rosetta if .rosetta.binfmt is not true
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
norio-nomura committed Jul 13, 2024
1 parent 67a716d commit b6580e4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b6580e4

Please sign in to comment.