Skip to content

Instantly share code, notes, and snippets.

@lzjluzijie
Last active May 15, 2024 02:22
Show Gist options
  • Save lzjluzijie/06edc9e820aeebb9299e33fea60813ef to your computer and use it in GitHub Desktop.
Save lzjluzijie/06edc9e820aeebb9299e33fea60813ef to your computer and use it in GitHub Desktop.
在WSL里编译kernel以通过tc实现限流
# 有时间再写blog
# https://github.com/microsoft/WSL/issues/6065
# https://gist.github.com/charlie-x/96a92aaaa04346bdf1fb4c3621f3e392
sudo apt install -y autoconf bison build-essential flex libelf-dev libncurses-dev libssl-dev libtool libudev-dev bc dwarves
sudo dnf install -y autoconf bison gcc gcc-c++ flex elfutils-libelf-devel ncurses-devel openssl-devel libtool systemd-devel bc elfutils-devel dwarves
mkdir kernel && cd kernel
wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-5.15.153.1.tar.gz
tar -xf linux-msft-wsl-5.15.153.1.tar.gz
cd WSL2-Linux-Kernel-linux-msft-wsl-5.15.153.1
cat /proc/config.gz | gunzip > .config
make prepare modules_prepare -j $(expr $(nproc) - 1)
# 开启 Networking Support -> Networking Options -> QoS and/or Fair Queueing 的全部
make menuconfig -j $(expr $(nproc) - 1)
make modules -j $(expr $(nproc) - 1)
sudo make modules_install
make -j $(expr $(nproc) - 1)
sudo make install
# copy it to windows drive
cp vmlinux /mnt/c/Users/<yourwindowsloginname>/
#create this file, change /<yourwindowsloginname> to your windows users directory name
vi /mnt/c/Users/<yourwindowsloginname>/.wslconfig
#with these contents
[wsl2]
kernel=C:\\Users\\<yourwindowsloginname>\\vmlinux
# 重启wsl
wsl --shutdown
# 限速
sudo tc qdisc add dev lo root netem delay 20ms rate 500mbit
# 恢复
sudo tc qdisc delete dev lo root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment