Skip to content

Instantly share code, notes, and snippets.

@sr229
Last active December 21, 2023 17:59
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sr229/e07d47131b98ab1f3fabe3df48cd24b8 to your computer and use it in GitHub Desktop.
Save sr229/e07d47131b98ab1f3fabe3df48cd24b8 to your computer and use it in GitHub Desktop.
Automated Script to Install Anbox Ashmem and Binder to WSL2 Linux Kernel
#!/bin/bash
set -o pipefail
KERNEL_WORKING_DIRECTORY="/usr/src"
KERNEL_VERSION=$(uname -r)
REQUIRED_DEPENDENCIES="git bison flex elfutils-libelf-devel openssl-devel"
KERNEL_SRC_DIR="$KERNEL_WORKING_DIRECTORY/WSL2-Linux-Kernel-$(uname -r)"
echo "Warning: This script has to be run on sudo permissions. If you encounter issues please report it immediately."
sleep 3
# Check if we have this installed first things first.
# We need this to install our Anbox stuff later
dnf install $REQUIRED_DEPENDENCIES -y
if [ ! -d "$KERNEL_SRC_DIR" ]; then
git clone --branch "$KERNEL_VERSION" --depth=30 https://github.com/microsoft/WSL2-Linux-Kernel "$KERNEL_SRC_DIR"
fi
cd "$KERNEL_SRC_DIR" && \
cp /proc/config.gz $(pwd) && \
gzip -d config.gz && \
mv config .config && \
make prepare && \
make modules_prepare && \
make modules && \
make scripts;
if [ ! -d /lib/modules/$KERNEL_VERSION/ ]; then
mkdir -p /lib/modules/$KERNEL_VERSION
ln $KERNEL_SRC_DIR -s /lib/modules/$KERNEL_VERSION/build
fi
git clone https://github.com/anbox/anbox-modules.git $HOME/anbox-modules && \
cd $HOME/anbox-modules && \
bash INSTALL.sh
rm -rf $HOME/anbox-modules
(source /etc/os-release && sudo dnf copr enable yanqiyu/anbox ${ID_LIKE}-${VERSION_ID}-$(uname -m)) && \
dnf install anbox -y
wget -O - https://build.anbox.io/android-images/2018/07/19/android_amd64.img > /var/lib/anbox/android.img
bash /usr/share/anbox/anbox-bridge.sh start && \
daemonize /usr/bin/anbox container-manager --daemon --privileged --data-path=/var/lib/anbox
#!/bin/bash
set -eo pipefail
KERNEL_WORKING_DIRECTORY="/usr/src"
KERNEL_VERSION=$(uname -r)
REQUIRED_DEPENDENCIES="git bison flex libelf-dev elfutils libssl-dev dkms"
KERNEL_SRC_DIR="$KERNEL_WORKING_DIRECTORY/WSL2-Linux-Kernel-$(uname -r)"
echo "Warning: This script has to be run on sudo permissions. If you encounter issues please report it immediately."
sleep 3
# Check if we have this installed first things first.
# We need this to install our Anbox stuff later
apt install $REQUIRED_DEPENDENCIES -y
if [ ! -d "$KERNEL_SRC_DIR" ]; then
git clone --branch "$KERNEL_VERSION" --depth=30 https://github.com/microsoft/WSL2-Linux-Kernel "$KERNEL_SRC_DIR"
fi
cd "$KERNEL_SRC_DIR" && \
cp /proc/config.gz $(pwd) && \
gzip -d config.gz && \
mv config .config && \
make prepare && \
make modules_prepare && \
make modules && \
make scripts;
if [ ! -d /lib/modules/$KERNEL_VERSION/ ]; then
mkdir -p /lib/modules/$KERNEL_VERSION
ln $KERNEL_SRC_DIR -s /lib/modules/$KERNEL_VERSION/build
fi
git clone https://github.com/anbox/anbox-modules.git $HOME/anbox-modules && \
cd $HOME/anbox-modules && \
bash INSTALL.sh
rm -rf $HOME/anbox-modules
#!/bin/bash
set -eo pipefail
KERNEL_WORKING_DIRECTORY="/usr/src"
KERNEL_VERSION=$(uname -r)
REQUIRED_DEPENDENCIES="git bison flex libelf-dev elfutils libssl-dev dkms"
KERNEL_SRC_DIR="$KERNEL_WORKING_DIRECTORY/WSL2-Linux-Kernel-$(uname -r)"
echo "Warning: This script has to be run on sudo permissions. If you encounter issues please report it immediately."
sleep 3
# Check if we have this installed first things first.
# We need this to install our Anbox stuff later
apt install $REQUIRED_DEPENDENCIES -y
if [ ! -d "$KERNEL_SRC_DIR" ]; then
git clone --branch "$KERNEL_VERSION" --depth=30 https://github.com/microsoft/WSL2-Linux-Kernel "$KERNEL_SRC_DIR"
fi
cd "$KERNEL_SRC_DIR" && \
cp /proc/config.gz $(pwd) && \
gzip -d config.gz && \
mv config .config && \
make prepare && \
make modules_prepare && \
make modules && \
make scripts;
if [ ! -d /lib/modules/$KERNEL_VERSION/ ]; then
mkdir -p /lib/modules/$KERNEL_VERSION
ln $KERNEL_SRC_DIR -s /lib/modules/$KERNEL_VERSION/build
fi
@MrAk47Anand007
Copy link

I am facing some issues when i run this script on my wsl2 machine in windows 11
image

@cstayyab
Copy link

Error Encountered:
fatal: Remote branch 5.10.16.3-microsoft-standard-WSL2 not found in upstream origin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment