关于系统服务#
ly@tabs8:~$ ls -l /etc/systemd/system/sshd.service
lrwxrwxrwx. 1 root root 31 Apr 3 14:16 /etc/systemd/system/sshd.service(用户自定义service存放地址) -> /lib/systemd/system/ssh.service(系统安装软件后的service存放地址)
但是sudo service hello status,chroot容器中查找的只是/etc/init.d/这个路径下的hello(不查找/etc/systemd和lib/systemd中的),但是如果使用systemctl disable hello,则/etc/init.d中的hello服务不会被运行,并且会删除/etc/systemd/system/multi-user.target.wants文件夹下的软连接。如果systemctl enable hello,则会在/etc/systemd/system/multi-user.target.wants文件夹下生成一个软连接。
执行完/etc/init.d/hello就不会再操作其他东西了(hello.service没有用)建议linuxdeploy的自动化开启Sysv模式,然后在/etc/init.d/里头编写脚本就可以了,如果要开机启动,使用systemctl enable xxx即可。
问题1#
chroot容器中,sudo systemctl enable hello.service后,开机启动时并没有执行。但是如果服务名hello在/etc/init.d/文件中存在对应名的SysV Init 脚本,就会执行,这是为什么呢
在普通 chroot 中,SysV Init 脚本能执行是因为其不依赖 PID 1 管理器,而 systemd 服务需要完整的初始化环境。若需 systemd 功能,应优先使用 systemd-nspawn。
问题2 ★#
chroot容器中,默认情况下,系统启动时会执行/etc/init.d/hello脚本(SysV Init 脚本),但是如果sudo systemctl disable hello.service后,开机启动时就不会执行了,这是为什么呢
Debian 12(即使使用 systemd)默认保留了 SysV Init 兼容性,通过systemd-sysv-generator 工具动态生成 .service 文件来管理 /etc/init.d/ 中的脚本。当执行 systemctl disable hello.service 时:①删除符号链接:会移除 /etc/systemd/system/<target>.wants/ 中指向自动生成的 hello.service 的符号链接(如 multi-user.target.wants/hello.service)。②禁用服务:即使 /etc/init.d/hello 存在,systemd 也不会在开机时触发其执行,因为兼容层已被禁用。systemctl enable#
ly@tabs8:~$ sudo systemctl disable ssh
Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable ssh
Removed "/etc/systemd/system/multi-user.target.wants/ssh.service".
Removed "/etc/systemd/system/sshd.service".
#=================================
ly@tabs8:~$ ls -l /etc/systemd/system/multi-user.target.wants | grep ssh
ly@tabs8:~$ ls -l /etc/systemd/system/ | grep ssh
#================开机自启动========
ly@tabs8:~$ sudo systemctl enable ssh
Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable ssh
#创建了两个符号链接
#保证兼容性,十几年前一直是用sshd
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
#multi-user.target.wants下: 开机自启动
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
#开机自启动其实是直接链接到系统(软件)自己的service
ly@tabs8:~$ ls -l /etc/systemd/system/multi-user.target.wants | grep ssh
lrwxrwxrwx. 1 root root 31 Apr 3 15:05 ssh.service -> /lib/systemd/system/ssh.service
ly@tabs8:~$ ls -l /etc/systemd/system/ | grep ssh
lrwxrwxrwx. 1 root root 31 Apr 3 15:05 sshd.service -> /lib/systemd/system/ssh.service
#====总的来说,我只要在/etc/systemd/system/下创建自己的服务S,然后systemctl enable S即可service编写(这里没用上)#
vim /etc/systemd/system/vncser
[Unit]
Description=TigerVncService # 服务描述
After=network.target # 定义启动顺序(在网络就绪后启动)
[Service]
Type=simple # 服务类型(simple/forking/oneshot等)
ExecStart=/usr/local/bin/tigervnc.sh # 启动命令(绝对路径)
Restart=on-failure # 失败时自动重启
User=ly # 运行用户(可选)
#Group=nogroup # 运行组(可选)
#WorkingDirectory=/path/to # 工作目录(可选)
[Install]
WantedBy=multi-user.target # 定义服务所属的“目标”(开机自启)一些命令暂记#
#镜像下载 https://mirrors-i.tuna.tsinghua.edu.cn/lxc-images/images/debian/bookworm/arm64/
#发行版 [rootfs.tar]
#源地址 ${EXTERNAL_STORAGE}/linuxdeploy/bookworm.tar.xz
#=====!!!!安装类型[ 目录]会有一些问题,比如ssh提示权限过高,不太懂..=======
#安装路径[ ${ENV_DIR}/rootfs/bookworm ] --> [ /data/data/ru.meefik.linuxdeploy/files/rootfs/bookworm ]----安装类型[ 目录]
#安装路径[ /data/media/0/linuxdeploy/bookworm ]----安装类型[ 目录]
#建议放镜像
#安装路径{EXTERNAL_STORAGE}/linuxdeploy/bookworm.img----安装类型[ 镜像文件]
#用户名--用户密码--特权用户--本地化--DNS--networktrigger--powertrigger--随便弃用
#(弃用)初始化-启用-run-parts--路径/etc/rc.local--初始用户root
#!!!!初始化我这里使用sysv,通过systemctl enable ssh可以让ssh开机自启动,但是systemctl start ssh不能使用,需要用service ssh start替代
#挂载目录--挂载点--source使用/data/media/0 (data开头的,android14中其他的好像都不行不知道为什么,给ly加了 aid_media_rw 这个组权限) sudo usermod -aG aid_media_rw username
#其他都不需要
#设置 telnet守护模式打开挂载目录说明#
为了统一,可以用/mnt/pass_through/0/emulated/0/(内置存储卡) 以及/mnt/pass_through/0/822C-9525/(外置存储卡)






















