본문 바로가기
개발/정리

[Linux] systemctl 명령 에러 System has not been booted with systemd as init system (PID 1).

by parkkingcar 2023. 4. 11.

 

WSL을 사용 중  systemd 환경이 아니라는 오류가 발생합니다.

 

$ sudo systemctl status 

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

 

 

 

 

원인은 WSL은 루트 시스템 프로세스가 systemd가 아닌 init이기 때문입니다.

$ pstree 명령을 통해 확인할 수 있습니다. pstree 명령어는 실행되고 있는 프로세스들간의 연결구조를 트리형식으로 보여줍니다.

$ pstree
init─┬─init─┬─init───docker-desktop-───14*[{docker-desktop-}]
     │      └─init───docker───20*[{docker}]
     ├─init───init───bash───pstree
     └─2*[{init}]

근래 들어 리눅스 진영은 init에서 systemd로 바뀌는 추세라고 하며, WSL은 아직 그것을 반영하지 못하고 있는 것이라고 합니다.


아마 이번 오류의 경우 WSL1에 먼저 우분투를 설치한 후 WSL2로 버전 업데이트를 해서 그런것으로 추측했습니다.

따라서 WSL에서 init 시스템 프로세스를 systemd 체계로 바꿔주어야 합니다.

 

구글링을 하면 github의 systemd-genie라는 프로젝트를 통해 해결하라고 하는데, 잘 해결되지 않고 복잡하여 다른 해결방안을 찾았습니다.

 

 

 

 

해결방안

wsl 에서 리눅스 부팅 시 systemd 환경으로 부팅하도록 하면 됩니다.

 

 

먼저 $ cd / 로 최상단 디렉토리로 이동합니다.

 

 

$ cd etc 로 etc 폴더로 이동합니다.

 

 

$ sudo vim wsl.conf 로 파일을 생성한 뒤, 다음과 같이 작성 후 저장합니다.

 

wsl.conf

[boot]
systemd=true

 

 

이후 wsl 을 재부팅하면 됩니다.

 

$ pstree 

 

 

 

그러면 $ sudo systemctl status 명령어 실행이 잘되는지 확인할 수 있습니다.

 

 

 

 

 

 

참고자료:

 

Linux: 51. WSL - init에서 systemd로 전환하는 방법

Linux: 51. WSL - init에서 systemd로 전환하는 방법 [링크 복사], [링크+제목 복사] 조회: 3089 글쓴 사람 정성태 (techsharer at outlook.com) 홈페이지 첨부 파일 부모글 보이기/감추기 (연관된 글이 2개 있습니다

www.sysnet.pe.kr

 

System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down · Issue #

Version Microsoft Windows [Version 10.0.22621.521] WSL Version WSL 2 WSL 1 Kernel Version 5.15.57.1 Distro Version Ubuntu 22.04.1 LTS Other Software N/A Repro Steps Enable systemd via /etc/wsl.conf...

github.com

 

리눅스-프로세스 관계 확인 pstree

pstree 명령어는 실행되고 있는 프로세스들간의 연결구조를 트리형식으로 보여줍니다. 상위에서와 같이 여...

blog.naver.com

 

System has not been booted with systemd as init system (PID 1). Can't operate

I use WSL2 on Windows 11. I want to run the systemctl command in Ubuntu 20.04, but it gives me the following error: System has not been booted with systemd as init system (PID 1). Can't operate. F...

askubuntu.com

 

댓글