# How to Install Mininet in WSL2
## Compile a new kernel (to include some necessary modules)
**In WSL:**
```
git clone https://github.com/microsoft/WSL2-Linux-Kernel
cd WSL2-Linux-Kernel
cp Microsoft/config-wsl .config
sudo apt update
sudo apt install cmake libncurses-dev flex bison libboost-all-dev openssl libspdlog-dev build-essential libssl-dev libelf-dev dwarves
make menuconfig
```
- Set the following option to a custom name you like:
```
General-setup -> Local version - append to kernel release
```
- Set the following options to \<M\> (by pressing M):
```
Networking support -> Networking options -> 802.1d Ethernet Bridging
Networking support -> Networking options -> QoS and/or fair queueing -> (Everything)
Networking support -> Networking options -> Open vSwitch
```
> In *QoS and/or fair queueing*, perhaps only HTB, NETEM, HFSC, TBF, and RED are needed (according to some code in mininet/link.py), but I didn't want to risk missing something and having to rebuild the kernel, so I just \<M\> everything...
- Save and Exit
```
make
cp arch/x86/boot/bzImage /mnt/c/Users/[USERNAME]/Desktop
```
## Install the new kernel
- Copy bzImage from Desktop to C:\Windows\System32\lxss\tools
- Rename kernel to kernel.old
- Rename bzImage to kernel
**In cmd or powershell:**
```
wsl --shutdown
```
**In WSL:**
> Use `uname -r` to check if you're in the new kernel.
```
cd WSL2-Linux-Kernel
sudo make modules_install
```
## Install Mininet
```
cd ~
git clone https://github.com/mininet/mininet
sudo PYTHON=python3 mininet/util/install.sh -a
```
## Run these lines everytime WSL restarts
```
sudo modprobe -a openvswitch sch_htb sch_netem sch_hfsc sch_tbf sch_red
sudo /etc/init.d/openvswitch-switch start
```
> Or maybe add them to somwhere like *.bashrc*? But then you'll have to type the password everytime you open a shell, which is annoying...
## X11 Forwarding
(so you can use xterm in mininet)
https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2
## Reference
https://zhuanlan.zhihu.com/p/138933513