dotfiles/Note/WSL.org
2022-04-18 18:15:30 +09:00

6.2 KiB

Wsl

Arch 리눅스 기반으로 작성되었음. WSL1 기반임. WSL2는 네트워크가 불안정해보임.

WSL Installation (Powershell)

Windows Function Enable

Windows Function enable ()

  # WSL
  Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

  # Install wsl2 kernel
  wget https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi -OutFile wsl_update_x64.msi
  ./wsl_update_x64.msi
  rm ./wsl_update_x64.msi

  # Windows Sandbox (optional)
  #Enable-WindowsOptionalFeature -FeatureName "Containers-DisposableClientVM" -All -Online

Download and Installation

$Arch_instDir = "c:/Archlinux"
mkdir -p $Arch_instDir
pushd $Arch_instDir
wget https://github.com/yuk7/ArchWSL/releases/latest/download/Arch.zip -OutFile Arch.zip
unzip ./Arch.zip
./Arch.exe

Terminal Emulator Installation

Installation

vcxsrv는 X windows 기반 앱사용시 설치.

choco install wsltty vcxsrv -y
pushd 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs'
& '.\WSL Generate Shortcuts.lnk'
popd

시작 폴더 shell:startup 에 다음의 config.xlaunch 넣으면 좋은듯?

  echo "<?xml version=""1.0"" encoding=""UTF-8""?>
  <XLaunch WindowMode=""Windowed"" ClientMode=""NoClient"" LocalClient=""False"" Display=""10"" LocalProgram=""xcalc"" RemoteProgram=""xterm"" RemotePassword="""" PrivateKey="""" RemoteHost="""" RemoteUser="""" XDMCPHost="""" XDMCPBroadcast=""False"" XDMCPIndirect=""False"" Clipboard=""True"" ClipboardPrimary=""True"" ExtraParams=""-keyhook"" Wgl=""True"" DisableAC=""True"" XDMCPTerminate=""False""/>" > $HOME/AppData/Roaming/Microsoft/Windows/"Start Menu"/Programs/Startup/config.xlaunch

Icon Change

/JaeUs/dotfiles/media/commit/700c32a94f8fe0be94ae0bd39150ee4ba3dc76a8/Note/images/screenshot-02.png

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortcutPath = [Environment]::GetFolderPath("Desktop") + "/WSL Terminal.lnk"
$Shortcut = $Shell.CreateShortcut($ShortcutPath);
$Shortcut.IconLocation = "$Arch_instDir/arch.exe, 0"
$Shortcut.Save()

Add Context Menu

/JaeUs/dotfiles/media/commit/700c32a94f8fe0be94ae0bd39150ee4ba3dc76a8/Note/images/screenshot-03.png

reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\wsltty" /t REG_SZ /d "Open in WSLtty..." /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\wsltty" /v Icon /t REG_SZ /d "$Arch_instDir/arch.exe" /f
$mintty_cmd = $HOME + "\AppData\Local\wsltty\bin\mintty.exe --WSL= --configdir=" + $HOME + "\AppData\Roaming\wsltty"
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\wsltty\Command" /t REG_SZ /d $mintty_cmd /f

Minttyrc

wsltty는 mintty기반이므로 .minttyrc의 설정값을 따른다. $HOME Directory에 위치시키자

cp $HOME/.dotfiles/.minttyrc $HOME/

WSL Initialization (in WSL)

Locale

echo ko_KR.UTF-8 UTF-8 >> /etc/locale.gen
locale-gen
echo LANG=ko_KR.UTF-8 > /etc/locale.conf
echo [network] > /etc/wsl.conf
echo generateHosts = false >> /etc/wsl.conf
pacman-key --init
pacman-key --populate archlinux

User Addition

EDITOR=vim visudo	# uncomment %wheel ALL=(ALL) ALL
useradd -m -g users -G wheel -s /bin/bash jaeus
passwd jaeus

Arch.exe 실행파일 있는곳에서 실행. (in powershell)

./arch.exe config --default-user jaeus

Git

  sudo pacman -S git stow
  rm ~/.zshrc
  rm ~/.bashrc
  git clone https://github.com/JaeUs3792/dotfiles.git ~/.dotfiles
  cd ~/.dotfiles
  stow .

Paru (AUR Manager)

WSL1에서는 fakeroot-tcp를 사용해야 한다.

sudo pacman -S --needed base-devel # don't install fakeroot
cd ~
git clone https://aur.archlinux.org/paru-bin.git
cd paru-bin
makepkg -si

Application

paru -S openssh python inetutils

ZSH

  paru -S zsh zsh-syntax-highlighting zsh-autosuggestions
  # Install oh-my-zsh
  sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  mv ~/.zshrc.* ~/.zshrc # overwrite configuration

TMUX

paru -S tmux
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
TMUX_PLUGIN_MANAGER_PATH=~/.config/tmux/plugins/tpm ~/.tmux/plugins/tpm/scripts/install_plugins.sh
TMUX_PLUGIN_MANAGER_PATH=~/.config/tmux/plugins/tpm ~/.tmux/plugins/tpm/bin/update_plugins all

EMACS

GUI를 사용하기 위해 DISPLAY환경변수 추가.

  paru -S ripgrep emacs ttf-fira-code ttf-nanum

  # WSL1
  #echo export DISPLAY=:10.0 >> ~/.zshrc
  # WSL2
  VETHER_IP=$(/bin/grep nameserver /etc/resolv.conf 2> /dev/null | /bin/tr -s ' ' | /bin/cut -d' ' -f2)
  export DISPLAY=$VETHER_IP:0.0

Latex 지원

paru -S auctex texlive-most texlive-lang

Emacs Windows shortcut c:\windows\system32\bash.exe 를 이용하며, 실행시 cmd창이 자꾸 뜨기 때문에 runs.exe프로그램을 이용한다.

in wsl.

cp ~/.dotfiles/Note/WSL/run_emacs.sh ~/.run_emacs.sh

in Powershell.

unzip $HOME/.dotfiles/Note/WSL/usr_cmd.zip -d $HOME/usr_cmd

/JaeUs/dotfiles/src/commit/700c32a94f8fe0be94ae0bd39150ee4ba3dc76a8/Note/WSL/usr_cmd.zip 파일의 내용을 Windows의 $HOME/usr_cmd 에 넣는다.

Libre-office

Libre-office를 깔면 Emacs에서도 그 파일이 열림.

paru -S libreoffice

Proxy

export proxy_addr="http://192.168.1.168:3128"

Global

echo export http_proxy=$proxy_addr >> ~/.zshrc
echo export HTTP_PROXY=$proxy_addr >> ~/.zshrc
echo export https_proxy=$proxy_addr >> ~/.zshrc
echo export HTTPS_PROXY=$proxy_addr >> ~/.zshrc
echo export ftp_proxy=$proxy_addr >> ~/.zshrc
echo export FTP_PROXY=$proxy_addr >> ~/.zshrc
echo export rsync_proxy=$proxy_addr >> ~/.zshrc
echo export RSYNC_PROXY=$proxy_addr >> ~/.zshrc

Sudo 명령어에 proxy 환경변수 통과

echo "Defaults env_keep += \"*_proxy *_PROXY\"" > ./05_proxy
sudo mv 05_proxy /etc/sudoers.d
sudo chown root:root /etc/sudoers.d/05_proxy

Git

git config --global http.proxy $proxy_addr
git config --global https.proxy $proxy_addr