====== WSL ====== * description : WSL 활용법 * author : 주레피 * email : dhan@repia.com * lastupdate : 2022-04-14 ===== Backup or restore ===== 백업 및 복구 // PowerShell or CMD // 목록 조회 PS C:\Users> wsl -l -v NAME STATE VERSION * docker-desktop-data Stopped 2 docker-desktop Stopped 2 Ubuntu-20.04 Stopped 2 // 백업 PS C:\Users> wsl --export Ubuntu-20.04 Ubuntu-20.04_20220414.tar // 복구 $> wsl --import Ubuntu-20.04 C:\User\jurepi\Ubuntu-20.04_20220414.tar 계정 패스워드를 잃어 버렸을 때 (sudo시 패스워드가 기억이 나지 않을 때) 1. 기본 사용자를 기록 한다. 2. 명령행 프롬프트를 관리자 권한으로 실행한다. 3. 기본 사용자를 root로 변경한다 PS C:\User> ubuntu2004 config --default-user root // ubuntu2004 <- Windows Terminal 설정에서 확인 가능 4. Windows Terminal에서 Ubuntu에 접속 한다. 현재 사용자가 root임을 알 수 있다. 5. 계정의 패스워드를 변경 한다. $> passwd ${계정명} // 1번에서 기록된 계정명 New password: ***** Retype new password: ***** 6. 기본 사용자를 원래 계정으로 변경한다. PS C:\User> ubuntu2004 config --default-user ${계정명} // 1번에서 기록된 계정명 7. Windows Terminal에서 Ubuntu에 접속 한다. 아래 명령어를 확인한다. $> sudo ls // 5번에서 입력한 패스워드 [sudo] password for jurepi: 8. 감사합니다. WSL 재시작 하기 명령행 프롬프트를 관리자 권한으로 실행한다. 종료하기 PS C:\User> net stop LxssManager or PS C:\User> wsl -t ${Distribute Name} // Ubuntu-20.04 재시작하기 PS C:\User> net start LxssManager ===== Troubleshooting ===== * System has not been booted with systemd as init system (PID 1). Can’t operate. Failed to connect to bus: Host is down $> sudo apt install daemonize dbus-user-session fontconfig $> sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target $> exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME $> snap version // 서비스 목록 확인하기 $> service --status-all $> systemctl list-units --type=service > [+] running, [-] stopped service * Error: 0x80070050 조치 방안 // PowerShell OR CMD PS C:\Users> wsl --shutdown // In Windows, run the Registry Editor 컴퓨터\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{....} DistributionName 값을 Ubuntu20.04LTS -> Ubuntu-20.04 > 히안하게 되네요 ㅠㅠ ===== 윈도우에서 WSL, Ubuntu 디렉토리 열기 ===== $> explorer.exe . ===== Ref ===== * [[https://blog.lilis.net/wsl-wsl%EC%97%90%EC%84%9C-systemctl-%EC%8B%A4%ED%8C%A8%ED%95%A0-%EB%95%8C/|wsl에서 systemctl 실패할 때]] * [[https://askubuntu.com/questions/1401830/wsl-not-working-after-update-from-microsoft-store|Error: 0x80070050 The file exists.]] * [[https://code.visualstudio.com/docs/remote/wsl|Developing in WSL]] {{tag>주레피 slaptear wsl}}