Skip to content

Instantly share code, notes, and snippets.

@rikka0w0
Last active October 22, 2020 06:51
Show Gist options
  • Save rikka0w0/6ec4fb2f6a5fc3e1468112006a6d3643 to your computer and use it in GitHub Desktop.
Save rikka0w0/6ec4fb2f6a5fc3e1468112006a6d3643 to your computer and use it in GitHub Desktop.
Run x86 native Linux binary on WSL

microsoft/WSL#2468

Install qemu and binfmt

sudo apt update
sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Install a x86 chroot

debootstrap --arch=i386 --foreign stretch chroot-stretch-i386
mount -t proc proc     chroot-stretch-i386/proc/
mount -t sysfs sys     chroot-stretch-i386/sys/
mount -o bind /dev     chroot-stretch-i386/dev/
mount -o bind /dev/pts chroot-stretch-i386/dev/pts
cp /usr/bin/qemu-i386-static chroot-stretch-i386/usr/bin/
chroot chroot-stretch-i386 /debootstrap/debootstrap --second-stage
/usr/sbin/adduser --uid 0 root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment