[컴] wsl command 와 config

wsl 2 / windows / WSL2 에서 linux distro path 변경 / Windows Subsystem for Linux 2 (WSL) 에서 / 다른 경로로 옮기기 /wsl commadns / config / configuration / 설정 / wsl2 command / cmd

wsl command 와 config

아래 export, import 를 이용해서 linux distro 가 저장된 위치를 바꿀 수 있다.

  • wsl hostname -I : wsl 의 ip address 를 얻을 수 있다.
  • wsl --list --all -v : wsl 에 설치된 모든 image 를 확인할 수 있다.
    • wsl -l -v
  • wsl --status : status 확인
  • wsl --export <DistributionName> <Full path to .tar FileName> : wsl –export docker-desktop c:\desktop.tar
  • wsl --import <DistributionName> <InstallLocation> <Full path to .tar FileName>: : wsl –import docker-desktop d:\path c:\desktop.tar
    • 새로운 path 에 기존의 tar 을 import
  • wsl --distribution <DistributionName> : 원하는 distro 를 실행할 수 있다.
    • wsl -d Ubuntu
  • wsl --unregister <DistributionName> : distro 를 삭제 할 때 사용한다.
  • wsl --install -d Ubuntu-20.04 : Ubuntu-20.04 를 설치한다.(이것은 Windows 10 Insiders Preview build 20246 에서 가능, 현재는 store 에서 설치해야 한다. 2021-06-05)
  • ubuntu2004 config --default-user <user-name> : distro 접속시 기본 계정을 설정할 때 사용, (참고: Set Default User for Windows Subsystem for Linux Distro in Windows 10 | Tutorials)
  • wsl --update : kernel update 를 해준다.

wsl2 에서 default user 변경

windows 에서 wsl 로 접근하는 경로(path)

  • wsl 을 하면 linux distro 가 실행되는데, 이때 자신이 원하는 path 에 가서 explorer 를 current directory(.) 를 parameter 로 해서 호출하면 된다.

    /mnt/c/Windows/explorer.exe .

ip address 확인 방법

windows 와 wsl2 는 다른 ip adress 를 갖는다. Ubuntu 20.04 를 기준으로 이야기하면, 확인방법은 다음과 같다.

  • windows에서 wsl hostname -I : wsl 의 ip address 를 얻을 수 있다.
# windows 의 ip address
grep nameserver /etc/resolv.conf

# wsl2 의 ip address
hostname -I

만약 hostname -I 의 ip 와 nameserver 의 ip 가 같다면 wsl1 을 사용하고 있을 수 있다. 삭제하고 wsl2 로 다시 깔려면 See Also 3. 을 확인하자.

WSL 관련 설정

wsl.conf :

  • /etc/wsl.conf
  • wsl.conf 예시
  • 각 disto 의 /etc 에 만들어서 사용
  • /etc 디렉토리에 저장되는 Unix 파일.
  • 이 파일을 사용하여 배포판(distribution)별로 설정할 수 있다.
  • WSL 1 또는 WSL 2에서 실행되는 배포에 모두 사용가능.

.wslconfig

  • C:\Users\<사용자명>\.wslconfig
  • .wslconfig 예시
  • windows 의 %UserProfile% 디렉토리에 저장된다.
  • WSL 2 버전으로 실행되는 모든 설치된 Linux 배포판에 대한 설정을 할 수 있다.
  • WSL 1로 실행되는 배포에는 가상 머신(VM)으로 실행되지 않기 때문에 이 구성은 영향을 주지 않는다.

systemd 사용법

  1. systemd=true
  2. sudo apt-get install daemonize

/etc/wsl.conf에 다음 내용을 추가한다. systemctl list-unit-files --type=service 로 모든 service 의 상태를 확인할 수 있다.

[boot]
systemd=true

이것과 더불어 daemonize 가 필요하다.

See Also

  1. 쿠…sal: [컴] docker 의 image path 변경하기
  2. New Windows 10 Insider Preview Skip Ahead Build 18836 (20H1) -Feb. 14 Insider - Windows 10 Forums
    • Windows 10 build 18836 (20H1) 이후에 wsl --export 가 추가됐다.
  3. 쿠...sal: [컴] Windows Subsystem Linux (WSL) 설치
  4. 쿠…sal: [컴] VSCode 를 이용해서 WSL 사용하기
  5. 쿠…sal: [컴][윈도우즈] WSL 에서 VM disk 위치
  6. 쿠...sal: [컴] 알아두면 좋을 linux commands > alias function alias 부분에 유용한 tip이 있다.

Reference

  1. Export and Import Windows Subsystem for Linux WSL Distro in Windows 10 | Tutorials

댓글 없음:

댓글 쓰기