From 9f4dd7cb88f9d89b5e8961d95dc3e32344e328f7 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Wed, 2 Oct 2024 12:34:24 +0200 Subject: teams/asahi: FEX: Minimize rootfs by removing most data files and executables We only really need i686/x86_64 libraries, and executables which do not exist (or do not work equivalently) on the arm64 host system. In particular, removing libexec avoids situations where random dbus services are started under emulation for no reason. --- config.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fex-excludes.yaml | 34 ++++++------------------- 2 files changed, 81 insertions(+), 27 deletions(-) diff --git a/config.sh b/config.sh index d169c98..fcc6461 100755 --- a/config.sh +++ b/config.sh @@ -309,4 +309,78 @@ EOF /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas fi +if [[ "$kiwi_profiles" == *"FEX"* ]]; then + # Remove most things except libraries used by FEX and wine stuff. + # Most binaries that are present in non-x86 architectures should be removed, + # so they do not run under emulation. + + # rm mingw static libs and headers + rm -rf /usr/{x86_64,i686}-w64-mingw32/sys-root/mingw/{lib,include} + + # rm everything in libexec + rm -rf /usr/libexec + + # rm everything in /usr/share except wine and mesa related stuff + find /usr/share -mindepth 1 -maxdepth 1 \ + \! -name wine -a \ + \! -name mesa-demos -a \ + \! -name drirc.d -a \ + \! -name vulkan \ + \! -name licenses \ + -exec rm -rf {} \; + + # rm everything in /etc except /etc/alternatives and ld stuff + find /etc -mindepth 1 -maxdepth 1 \ + \! -name alternatives -a \ + \! -name 'ld.so*' -a \ + \! -name '*.kiwi' \ + -exec rm -rf {} \; + + # rm non-libs in lib/lib64 + rm -rf /usr/{lib,lib64}/{locale,tmpfiles.d,systemd,modprobe.d,kbd,cmake} + rm -rf /usr/{lib,lib64}/python* + + # lib/clc and lib64/clc are identical, replace with a symlink + rm -rf /usr/lib/clc + ln -s ../lib64/clc /usr/lib/clc + + # rm sbin except for ldconfig, we don't even have root in some setups + find /usr/sbin -mindepth 1 -maxdepth 1 \ + \! -name 'ldconfig' \ + -exec rm -rf {} \; + + # rm misc stuff + rm -rf /usr/{include,games,local,src,tmp} + + # Finally, remove most binaries except Wine stuff, Mesa stuff, the shell, + # path-related stuff, and system info tools. + find /usr/bin -mindepth 1 -maxdepth 1 \ + \! -name 'wine*' -a \ + \! -name 'mango*' -a \ + \! -name notepad -a \ + \! -name 'msi*' -a \ + \! -name regedit -a \ + \! -name regsvr32 -a \ + \! -name 'vulkan*' -a \ + \! -name 'vk*' -a \ + \! -name ulimit -a \ + \! -name ldd -a \ + \! -name env -a \ + \! -name sh -a \ + \! -name bash -a \ + \! -name ls -a \ + \! -name stat -a \ + \! -name dirname -a \ + \! -name realpath -a \ + \! -name basename -a \ + \! -name nproc -a \ + \! -name uname -a \ + \! -name arch -a \ + \! -name rm \ + -exec rm -rf {} \; + + # Do this last for obvious reasons. + rm /usr/bin/rm +fi + exit 0 diff --git a/fex-excludes.yaml b/fex-excludes.yaml index 3597228..3582368 100644 --- a/fex-excludes.yaml +++ b/fex-excludes.yaml @@ -1,35 +1,15 @@ exclude: -- /dev -- /sys -- /proc -- /etc/hosts -- /etc/resolv.conf -- /etc/timezone -- /etc/localtime -- /etc/passwd -- /etc/passwd- -- /etc/group -- /etc/group- -- /etc/shadow -- /etc/shadow- -- /etc/gshadow -- /etc/gshadow- -- /etc/fstab -- /etc/mtab -- /etc/subuid -- /etc/subgid -- /etc/machine-id +- /afs - /boot +- /dev - /home - /media - /mnt +- /opt +- /proc - /root +- /run - /srv +- /sys - /tmp -- /run -- /opt -- /usr/share/fonts -- /var/tmp -- /var/run -- /var/lock -- /var/lib/dbus/machine-id +- /var -- cgit v1.3.1+13