Last active
March 19, 2022 20:14
-
-
Save junxy/c1fc03f1d16953f861936059e3d546ec to your computer and use it in GitHub Desktop.
WS2 启动慢 - WSL2 startup slow notes -> https://github.com/microsoft/WSL/issues/4737
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
if type pactl > /dev/null 2>&1 || type xvinfo > /dev/null 2>&1; then | |
# detect WSL host | |
if type systemd-detect-virt > /dev/null 2>&1 && test "$(systemd-detect-virt -c)" != wsl -a -e /etc/resolv.conf; then | |
WSL_HOST=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null) | |
fi | |
WSL_HOST=${WSL_HOST:-localhost} | |
# set DISPLAY if there is an X11 server running | |
if type xvinfo > /dev/null 2>&1 && env DISPLAY=${WSL_HOST}:0 xvinfo > /dev/null 2>&1; then | |
export DISPLAY=${WSL_HOST}:0 | |
export LIBGL_ALWAYS_INDIRECT=1 | |
fi | |
# set up audio if pulse server is reachable only via tcp | |
if type pactl > /dev/null 2>&1 \ | |
&& (! pactl info > /dev/null 2>&1 || pactl info 2> /dev/null | grep -q 'Default Sink: auto_null' ) \ | |
&& env PULSE_SERVER=tcp:${WSL_HOST} pactl info > /dev/null 2>&1; then | |
export PULSE_SERVER=tcp:${WSL_HOST} | |
fi | |
unset WSL_HOST | |
fi |
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
printf "wsl:1 ->\n" | |
date +"%T" | |
if type pactl > /dev/null 2>&1 || type xvinfo > /dev/null 2>&1; then | |
printf "\nwsl:2 ->\n" | |
date +"%T" | |
# detect WSL host | |
if type systemd-detect-virt > /dev/null 2>&1 && test "$(systemd-detect-virt -c)" != wsl -a -e /etc/resolv.conf; then | |
WSL_HOST=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null) | |
fi | |
WSL_HOST=${WSL_HOST:-localhost} | |
printf "\nwsl:3 detect WSL host: $WSL_HOST ->\n" | |
date +"%T" | |
# set DISPLAY if there is an X11 server running | |
if type xvinfo > /dev/null 2>&1 && env DISPLAY=${WSL_HOST}:0 xvinfo > /dev/null 2>&1; then | |
export DISPLAY=${WSL_HOST}:0 | |
export LIBGL_ALWAYS_INDIRECT=1 | |
fi | |
printf "\nwsl:4 set display ->\n" | |
date +"%T" | |
# set up audio if pulse server is reachable only via tcp | |
if type pactl > /dev/null 2>&1 \ | |
&& (! pactl info > /dev/null 2>&1 || pactl info 2> /dev/null | grep -q 'Default Sink: auto_null' ) \ | |
&& env PULSE_SERVER=tcp:${WSL_HOST} pactl info > /dev/null 2>&1; then | |
export PULSE_SERVER=tcp:${WSL_HOST} | |
fi | |
unset WSL_HOST | |
printf "\nwsl:5 set audio done ->\n" | |
date +"%T" | |
fi |
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
λ wsl | |
wsl:1 -> | |
11:25:29 | |
wsl:2 -> | |
11:25:29 | |
wsl:3 detect WSL host: 192.168.208.1 -> | |
11:25:29 | |
wsl:4 set display -> (33s) | |
11:26:02 | |
wsl:5 set audio done -> (5s) | |
11:26:07 |
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
return | |
if type pactl > /dev/null 2>&1 || type xvinfo > /dev/null 2>&1; then | |
# detect WSL host | |
if type systemd-detect-virt > /dev/null 2>&1 && test "$(systemd-detect-virt -c)" != wsl -a -e /etc/resolv.conf; then | |
WSL_HOST=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null) | |
fi | |
WSL_HOST=${WSL_HOST:-localhost} | |
# set DISPLAY if there is an X11 server running | |
if type xvinfo > /dev/null 2>&1 && env DISPLAY=${WSL_HOST}:0 xvinfo > /dev/null 2>&1; then | |
export DISPLAY=${WSL_HOST}:0 | |
export LIBGL_ALWAYS_INDIRECT=1 | |
fi | |
# set up audio if pulse server is reachable only via tcp | |
if type pactl > /dev/null 2>&1 \ | |
&& (! pactl info > /dev/null 2>&1 || pactl info 2> /dev/null | grep -q 'Default Sink: auto_null' ) \ | |
&& env PULSE_SERVER=tcp:${WSL_HOST} pactl info > /dev/null 2>&1; then | |
export PULSE_SERVER=tcp:${WSL_HOST} | |
fi | |
unset WSL_HOST | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment