@@ -10,26 +10,20 @@ if [ -f /etc/alpine-release ]; then
1010 rc-service qemu-binfmt stop --ifstarted
1111fi
1212
13- mkdir -p /mnt/lima-rosetta
13+ binfmt_entry=/proc/sys/fs/binfmt_misc/rosetta
14+ binfmtd_conf=/usr/lib/binfmt.d/rosetta.conf
15+ if [ " $LIMA_CIDATA_ROSETTA_BINFMT " = " true" ]; then
16+ 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"
1417
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
29- fi
18+ # If rosetta is not registered in binfmt_misc, register it.
19+ [ -f " $binfmt_entry " ] || echo " $rosetta_binfmt " > /proc/sys/fs/binfmt_misc/register
3020
31- 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
21+ # Create binfmt.d(5) configuration to prioritize rosetta even if qemu-user-static is installed on systemd based systems.
22+ # If the binfmt.d directory exists, consider systemd-binfmt.service(8) to be enabled and create the configuration file.
23+ [ ! -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 "
3529fi
0 commit comments