wsl 启动linux子系统后,systemctl 不可用

文章转载自然:https://itslinuxfoss.com/fix-system-not-booted-systemd-as-init-system-pidcant-operate

大概意思是 linux 上有两种管理服务的方法, Systemd 和 sysvinit,其中 wsl 启动的 linux 子系统是不支持 systemd 的,建议我们使用 sysvinit 的方式管理服务。

但其实笔者之前也见到过让 wsl 支持 systemd 的操作方法,感兴趣的同学可以自行查找相关方法。

Systemd and sysvinit are the two supported versions to manage the services on Linux. Systemd controls the start-up processes using the services files, while sysvinit controls the start-up processes using the shell script. Usually, the error “System has not been booted with systemd” occurs while using the WSL on Windows. This post will provide the possible reasons and the solutions to the above-stated error with the following outcomes:

  • Reason: Systemd Not Supported
  • Solution: Use Init Supported Commands

Reason: Systemd Not Supported

This problem mainly occurs in the WSL because it is not equipped with systemd utility, and thus the systemctl command doesn’t work in WSL, which can be seen in the below image:

image.png

So, this is the problem for WSL users, let’s move and find out the solutions for that problem.

Solution: Use Init Supported Commands

Let’s check in both WSL and Ubuntu (as a primary operating system or in a virtualization environment ). To check which system your operating system supports, use the appropriate command:

In WSL:

$ ps -p 1 -o comm=

image.png

In Linux:

$ ps -p 1 -o comm=

image.png

Hence, it is verified that the **systemd **has nothing to do with the WSL by default.

The solution for the problem is pretty simple because there is only a command difference between WSL and other Linux. Instead of systemctl commands, use the “Sysv Init” supported commands. Let’s clear this concept using the table comparison.

Purpose Systemd Supported Commands (For Primary Linux) Sysv Init Supported Commands (For WSL)
To Start $ sudo systemctl start service_name $ sudo service service_name start
To Stop $ sudo systemctl stop service_name $ sudo service service_name stop
To Restart $ sudo systemctl restart service_name $ sudo service service_name restart
To Check Status $ sudo systemctl status service_name $ sudo service service_name status
To Enable $ sudo systemctl enable service_name
To Disable $ sudo systemctl disable service_name

That’s it from this guide.

Conclusion

To resolve the error “system has not booted with systemd” in linux, there are two possible solutions, either use the **sysvinit **commands or make the **systemd **available on WSL. The table of the **sysvinit **commands is provided here. This post has demonstrated all the possible solutions for the error “system has not been booted with systemd” in linux.

你可能感兴趣的:(wsl 启动linux子系统后,systemctl 不可用)