WSL2 에서 Systemd 사용하기
Overview
WSL을 기본적으로 설치하면 sysvinit, 줄여서 init을 사용한다. 이는 오래된 시스템으로 centos 기준 6버전 이하, ubuntu 기준 12.04 이하 버전에서 사용해 왔다. 최신 리눅스 시스템은 init 대신 systemd를 사용한다. 이 둘의 차이점은 서비스를 실행할 때 명령이 service이냐 systemctl 이냐 차이를 가지고 있다. 최신 리눅스 시스템을 사용하는 사용자라면 systemctl에 서비스를 구성하는 것에 익숙하기다. 이 포스트에서는 service 대신 systemctl을 사용하는 방법을 설명한다.
Prepare
WSL에서 init 대신 systemd를 사용하려면 기본적으로 WSL 2를 써야만한다. WSL 2 구성은 아래 포스트를 참고한다.
[Information Technology/Operation System] - WSL Version Upgrade
Install
아마도 2022년 9월 이전에 설치한 WSL 2 버전에서는 systemd를 사용하기 위해 다양한 방식이 도전되어 왔었다. 대부분 누군가가 systemd를 활성화하기 위한 스크립트를 제작하고, 이것을 다운로드 받는 방식으로 진행되었다.
https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950
WSL 2 - Enabling systemd
WSL 2 - Enabling systemd. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
https://dzzienki.tistory.com/93
window wsl2 systemctl 활성화
윈도우 터미널에서 지원하는 wsl2 ubuntu 22-04 버전은 기본적으로 systemctl 을 지원하지 않습니다. 그래서 수동 설정으로 사용할 수 있도록 설정을 해야하는데 방법은 sudo apt install git git clone https://git
dzzienki.tistory.com
하지만 Microsoft에서 공식적으로 systemd 사용을 지원을 한다고 포스팅이 올라왔고, 오피셜 문서에도 관련 내용이 업데이트 되었다.
https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/
Systemd support is now available in WSL!
Systemd support is now available in WSL! The Windows Subsystem for Linux (WSL) can now run systemd inside of your WSL distros, empowering you to do more with your Linux workflows on your Windows machine. This post will cover: What is systemd?
devblogs.microsoft.com
https://learn.microsoft.com/en-us/windows/wsl/systemd
Use systemd to manage Linux services with WSL
Learn how to use systemd to manage Linux services with Windows Subsystem for Linux.
learn.microsoft.com
방법은 간단하다. wsl을 최신 버전으로 업데이트(최소한 wsl 0.67.6 이상 버전으로)하면 된다.
wsl --update
하나 추가로 확인해야할 것은 /etc/wsl.conf에 systemd=true로 설정되어 있는가이다. ubuntu 22.04에는 기본적으로 설정되어 있지만, 다른 유형의 리눅스나 낮은 버전의 ubuntu에는 이 설정이 안되어 있을 수 있다.
cat /etc/wsl.conf
[boot]
systemd=true