首页 > 系统相关 >[踩坑] WSL2 Ubuntu20.04启用systemctl

[踩坑] WSL2 Ubuntu20.04启用systemctl

时间:2023-07-25 12:11:57浏览次数:34  
标签:Ubuntu20.04 systemd -- sudo PID SYSTEMD systemctl usr WSL2

一、安装fontconfig daemonize

sudo apt install -y fontconfig daemonize

二、修改/etc/profile

# 在末尾添加以下内容
SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')

if [ -z "$SYSTEMD_PID" ]; then
   sudo /usr/bin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
   SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')
fi

if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then
    exec sudo /usr/bin/nsenter -t $SYSTEMD_PID -a su - $LOGNAME
fi

三、修改/etc/sudoer

# 在末尾添加以下内容
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
%sudo ALL=(ALL) NOPASSWD: /usr/bin/nsenter -t [0-9]* -a su - [a-zA-Z0-9]*

四、生效profile

$ sudo -s
$ source /etc/profile

 

 

= =

 

标签:Ubuntu20.04,systemd,--,sudo,PID,SYSTEMD,systemctl,usr,WSL2
From: https://www.cnblogs.com/leokale-zz/p/17579564.html

相关文章

  • ubuntu18.04、ubuntu20.04桌面版换国内源
    ubuntu18.04、ubuntu20.04桌面版换国内源一、ubuntu18.04换源1.备份原始源文件source.list2.修改源文件二、ubuntu20.04换源三、其他换源方法安装好ubuntu18.04或ubuntu20.04后,软件更新默认使用国外源,在国内更新时速度很慢,所以需要更换成国内源,这样软件的更新和安装才......
  • systemctl
    systemctl系统服务管理器指令补充说明systemctl命令是系统服务管理器指令,它实际上将service和chkconfig这两个命令组合到一起。任务旧指令新指令使某服务自动启动chkconfig--level3httpdonsystemctlenablehttpd.service使某服务不自动启动chkconfi......
  • ubuntu20.04安装Kubernetes(k8s)
    1.禁止swap分区(必须)暂时禁止:sudoswapoff-a永久禁止:#注释掉swap一行sudovi/etc/fstab2.更改net.bridge.bridge-nf-call-iptables的值为1.(Ubuntu20.04默认为1)cat<<EOF|sudotee/etc/sysctl.d/k8s.confnet.bridge.bridge-nf-call-ip6tables=1net.bridge.br......
  • wsl2问题
    问题如下:解决:Then:重启......
  • 搭建远程开发环境@Win11+OpenWrt+Vscode+WSL2+Ubuntu22.04
    Pre之前618从pdd上买了配件,第一次尝试自己组装了电脑,本意是作为炼丹炉,不过毕竟是自己的电脑不像服务器可以一天到晚打黑工,还是用来开发就好,测测代码跑跑ai。没显示器——远程连接(后来还是买了,而且今天才发现买的那款大降价,唉),没键鼠——远程连接,没网络——二手路由刷openwrt去中......
  • ubuntu20.04使用plx9054官方驱动 转载
    转载地址http://wuhongyi.cn/PKUXIADAQ/en/INSTALL.htmlInstallationofSoftwareInstallationforthissoftwareisrequriredbyCERNROOT6GCC>=4.8FFTW3OPENSSLTheoperatingsystemtestedbythisprogramincludesCentOS7/ScientificLinux7/......
  • 利用U盘给Intel NUC重装Ubuntu20.04系统
    背景因为社团里刚好有一个被玩坏的IntelNUC,我又刚好对此感兴趣,于是学长就交给我这一项任务,让我给这台NUC刷机。目录NUC刷机基本上简单分为四步一、格式化U盘二、下载Ubuntu20.04系统镜像三、将系统镜像写入U盘,制成启动盘四、把启动盘里的系统整到NUC里,重装系统,完成刷机。......
  • ubuntu20.04 配置编译安装nginx的systemctl启动命令
    vim/usr/lib/systemd/system/nginx.service[Unit]Description=nginx-highperformancewebserverAfter=network.targetremote-fs.targetnss-lookup.target[Service]Type=forkin......
  • WSL2安装CUDA记录
    ❗建议直接Windows安装驱动,不要在子系统里装官网安装,选择自己的版本即可https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_localwget<https://developer.download.nvidia.com/co......
  • ubuntu20.04安装mongodb步骤
    注:虚拟机无法运行mongodb5.0以上的版本1、wget-qO-https://www.mongodb.org/static/pgp/server-4.4.asc|apt-keyadd-导入并设置公钥2、echo"deb[arch=amd64,arm64]https://repo.mongodb.org/apt/ubuntufocal/mongodb-org/4.4multiverse"|tee/ect/apt/sources.list.......