forked from StevenBaby/onix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6668ed7
commit 658cc39
Showing
7 changed files
with
116 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# WSL2 开发环境 | ||
|
||
## minix 文件系统 | ||
|
||
mount 的时候 minix 文件系统未知,通过查证,需要重新编译 Linux,然后开启 minix 文件系统支持。 | ||
|
||
需要安装一些包: | ||
|
||
sudo pacman -S bc | ||
sudo pacman -S pahole | ||
|
||
--- | ||
|
||
从下面的地址下载的源码。 | ||
|
||
> <https://github.com/microsoft/WSL2-Linux-Kernel/releases> | ||
--- | ||
|
||
修改文件 `Microsoft/config-wsl`,添加下面一行,以支持 minix 文件系统: | ||
|
||
CONFIG_MINIX_FS=y | ||
|
||
我还改了: | ||
|
||
CONFIG_CC_VERSION_TEXT="gcc (GCC) 13.2.1 20230801" | ||
|
||
--- | ||
|
||
然后: | ||
|
||
make KCONFIG_CONFIG=Microsoft/config-wsl -j16 | ||
|
||
|
||
后面 -j16 表示 16 个任务同时编译,可以根据自己的 CPU 数量来设置,等待,编译完成。。。 | ||
|
||
--- | ||
|
||
然后将编译好的文件 `arch/x86/boot/bzImage` 复制到用户目录 `%UserProfile%`, 该目录一般为 `C:/Users/xxx/`,当然也可以放在其他位置,自行决定;也有人直接替换了 `C:\Windows\System32\lxss\tools\kernel`,然后无需下面的配置文件,不过直觉告诉我,这种方式不推荐。 | ||
|
||
在用户目录添加或修改配置文件 `.wslconfig` | ||
|
||
``` | ||
[wsl2] | ||
kernel=C:\\Users\\xxx\\bzImage | ||
``` | ||
|
||
然后重启 `wsl2` | ||
|
||
wsl --shutdown | ||
|
||
重新进入 `wsl`,输入命令 `uname -r` 得到: | ||
|
||
5.15.123.1-microsoft-standard-WSL2 | ||
|
||
## 网络 NAT 模式 | ||
|
||
这部分内容来自 [@znyin](https://github.com/znyinyyniu),经过了优化。 | ||
|
||
## 参考 | ||
|
||
- <https://gist.github.com/oleksis/eb6d2f1cd2a6946faefb139aa0e38c35> | ||
- <https://wiki.archlinux.org/title/Internet_sharing#Enable_NAT> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,20 @@ | ||
IFACE:=onix | ||
IFACE:=$(shell sudo ip -o -4 route show to default | awk '{print $$5}') | ||
|
||
BR0:=/sys/class/net/br0 | ||
TAPS:= /sys/class/net/tap0 \ | ||
/sys/class/net/tap1 \ | ||
/sys/class/net/tap2 \ | ||
TAP0:=/sys/class/net/tap0 | ||
|
||
.SECONDARY: $(TAPS) $(BR0) | ||
.SECONDARY: $(TAP0) | ||
|
||
# 网桥 IP 地址 | ||
BNAME:=br0 | ||
IP0:=192.168.111.22 | ||
MAC0:=5a:5a:5a:5a:5a:22 | ||
GATEWAY:=192.168.111.2 | ||
GATEWAY:=172.16.16.1 | ||
|
||
$(BR0): | ||
sudo ip link add $(BNAME) type bridge | ||
sudo ip link set $(BNAME) type bridge ageing_time 0 | ||
|
||
sudo ip link set $(IFACE) down | ||
sudo ip link set $(IFACE) master $(BNAME) | ||
sudo ip link set $(IFACE) up | ||
|
||
sudo ip link set dev $(BNAME) address $(MAC0) | ||
sudo ip link set $(BNAME) up | ||
|
||
# sudo iptables -A FORWARD -i $(BNAME) -o $(BNAME) -j ACCEPT | ||
sudo iptables -F | ||
sudo iptables -X | ||
sudo iptables -P FORWARD ACCEPT | ||
sudo iptables -P INPUT ACCEPT | ||
sudo iptables -P OUTPUT ACCEPT | ||
|
||
sudo ip addr add $(IP0)/24 brd + dev $(BNAME) metric 10000 | ||
sudo ip route add default via $(GATEWAY) dev $(BNAME) proto static metric 10000 | ||
# sudo dhclient -v -4 br0 | ||
|
||
br0: $(BR0) | ||
- | ||
|
||
/sys/class/net/tap%: $(BR0) | ||
sudo ip tuntap add mode tap $(notdir $@) | ||
sudo ip link set $(notdir $@) master $(BNAME) | ||
$(TAP0): | ||
sudo ip tuntap add mode tap $(notdir $@) user $(USER) | ||
sudo ip addr add $(GATEWAY)/24 dev $(notdir $@) | ||
sudo ip link set dev $(notdir $@) up | ||
|
||
tap%: /sys/class/net/tap% | ||
sudo sysctl net.ipv4.ip_forward=1 | ||
sudo iptables -t nat -A POSTROUTING -s $(GATEWAY)/24 -o $(IFACE) -j MASQUERADE | ||
sudo iptables -A FORWARD -i $(notdir $@) -o $(IFACE) -j ACCEPT | ||
|
||
tap0: $(TAP0) | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# ipaddr=192.168.111.33 | ||
# netmask=255.255.255.0 | ||
# gateway=192.168.111.2 | ||
ipaddr=172.16.16.11 | ||
netmask=255.255.0.0 | ||
gateway=172.16.16.1 |