running macOS on WSL2 using sickcodes

Shi
CI/CD/DevOps
Published in
3 min readApr 1, 2023

KVM+QEMU

in this experiment, I am trying to launch macOS in a docker from Ubuntu 1804 installed to a WSL2 VM.

https://github.com/sickcodes/Docker-OSX#id-like-to-run-docker-osx-on-windows

environment


host OS: Windows 11 Home

CPU: AMD Ryzen 5 4500U with Radeon Graphics 2.38 GHz

vm: Ubuntu 18.04.6 LTS Bionic Beaver on WSL2

Docker Desktop 4.17.1 (101757)

Docker Engine: 23.0.2

1) enable KVM in BIOS

(refer to https://support.lenovo.com/lt/lt/solutions/ht500006-how-to-enable-virtualization-technology-on-lenovo-computers for details)

2) rebuild Linux kernel with KVM with kvm_amd module

(see detailed instruction from https://douran.academy/wp-content/uploads/ebooks/pro-windows-subsystem-for-linux.pdf)

git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel

sudo apt -y install build-essential libncurses-dev bison flex libssl-dev libelf-dev

cd WSL2-Linux-Kernel/

cp Microsoft/config-wsl .config

# make sure you have the following in .config
KVM_GUEST=y
CONFIG_KVM=y
CONFIG_KVM_AMD=m
CONFIG_VHOST=y

make -j 8

sudo make modules_install

cp arch/x86/boot/bzImage $(wslpath $(wslvar USERPROFILE))

at this stage, you should be able to verify that kvm is ready with

$ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

3) install Docker Desktop

you have to reinstall it if you already have it because the integration to docker engine needs to be refreshed.

then enable the following in docker desktop settings.

4) reload WSL2

modify your docker config and make sure you have the following inside and then reload WSL 2

[wsl2]
nestedVirtualization=true

5) install docker engine to ubuntu 1804 on WSL2

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
sudo chown root:docker /var/run/docker.sock

sudo apt install docker-compose

6) launch sickcodes container

docker run -it     \
--device /dev/kvm \
-p 50922:10022 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=${DISPLAY:-:0.0}" \
sickcodes/docker-osx:mojave

to be continued . . .

--

--

Shi
CI/CD/DevOps

I am a coder/engineer/application security specialist. I like to play around with language and tools; I have strong interest in efficiency improvement.