카테고리 없음

windows 10/11 cmd에서 bash 명령 오류

lovian 2024. 1. 19. 14:51

배경

  • Windows 11 환경
  • WSL설치해서 잘 쓰고 있음
  • 유독 도스 창에서 bash 명령을 실행하면 오류남 (아래와 같이)
PS D:\Application\bin> bash
<3>WSL (8) ERROR: CreateProcessParseCommon:754: getpwuid(0) failed 2
Processing fstab with mount -a failed.

<3>WSL (8) ERROR: CreateProcessEntryCommon:331: getpwuid(0) failed 2
<3>WSL (8) ERROR: CreateProcessEntryCommon:502: execvpe /bin/bash failed 2
<3>WSL (8) ERROR: CreateProcessEntryCommon:505: Create process not expected to return

 

※ 도스창에서 ubuntu를 입력하면, bash 화면이 잘 뜸

분석

bash != ubuntu ??

예전에는 동일했던거 같은데, 일단 지금은 어떤 이유로 동일하지 않음

 

일단 wsl의 정보를 볼 수 있는 유일한 명령 wsl로 현재 상황을 확인해보자

 

PS D:\Application\bin> wsl -l
Linux용 Windows 하위 시스템 배포:
docker-desktop-data(기본값)
docker-desktop
Ubuntu
Ubuntu-22.04

 

어? 갑자기 답이 보인다.

 

나는 docker를 설치했지만, 필요할때만 띄워서 사용한다.

위의 목록을 보면 기본값으로 docker가 선택되어 있는데, 용도는 docker가 알아서 잘쓰는 것일테고

나는 ubuntu의 bash를 실행하고 싶었는데, 엉뚱한 것을 실행하다가 문제가 생기지 않았을까?

 

해결 과정

PS D:\Application\bin> bash --help
<3>WSL (8) ERROR: CreateProcessParseCommon:754: getpwuid(0) failed 2
Processing fstab with mount -a failed.

<3>WSL (8) ERROR: CreateProcessEntryCommon:331: getpwuid(0) failed 2
<3>WSL (8) ERROR: CreateProcessEntryCommon:502: execvpe /bin/bash failed 2
<3>WSL (8) ERROR: CreateProcessEntryCommon:505: Create process not expected to return

 

안타깝게도 bash 명령으로는 방법이 없다.

어떤 옵션도 먹지 않고 있음.

 

다시 wsl을 뜯어보자

PS D:\Application\bin> wsl --help
저작권(c) Microsoft Corporation. All rights reserved.
이 제품에 대한 개인 정보 보호 정보는 https://aka.ms/privacy를 방문하세요.

사용법: wsl.exe [인수] [옵션...] [CommandLine]

Linux 이진 파일을 실행하기 위한 인수:

    명령줄이 제공되지 않으면 wsl.exe는 기본 셸을 시작합니다.

    --exec, -e <CommandLine>
        기본 Linux 셸을 사용하지 않고 지정된 명령을 실행합니다.

    --shell-type <standard|login|none>
        제공된 셸 형식으로 지정된 명령을 실행합니다.

    --
        나머지 명령줄을 있는 그대로 전달합니다.

옵션:
    --cd <디렉터리>
        지정된 디렉터리를 현재 작업 디렉터리로 설정합니다.
        ~ 가 사용되는 경우 Linux 사용자의 홈 경로가 사용됩니다. 경로가 시작되면
        / 문자를 사용하면 절대 Linux 경로로 해석됩니다.
        그렇지 않으면 값이 절대 Windows 경로여야 합니다.

    --distribution, -d <Distro>
        지정된 배포를 실행합니다.

 

-d -e를 조합하면 될 것 같다.

PS D:\Application\bin> wsl -d Ubuntu -e "bash"
(base) lovian@susutop:/mnt/d/Application/bin$

 

역시.. 명령어가 좀 길어졌지만, 목표는 달성했다.

 

하지만 다른 방법도 있지 않을까?

복잡한 실행보다는 (기본값)를 바꿀 수 있다면 더 쉬울 것 같은데.??

wsl --help를 더 읽어보면, 마지막 즈음에

    --set-default, -s <Distro>
        배포를 기본값으로 설정합니다.

아, 너무 쉬울 것 같다

 

PS D:\Application\bin> wsl -s "Ubuntu"
작업을 완료했습니다.
PS D:\Application\bin> wsl -l
Linux용 Windows 하위 시스템 배포:
Ubuntu(기본값)
docker-desktop-data
docker-desktop
Ubuntu-22.04

 

쉽다. 이제 그냥 bash명령어로 작업 하자.