我特意拿我的Debian initrd做了个试验
在/init里设置了几个环境变量,结果真没继承下来。
ChatGPT给的解释是这样的,大概3个原因
Process Isolation: Many init systems (like systemd, Upstart, etc.) and containerization systems (like Docker) intentionally isolate environment variables to prevent them from being passed from the init process to other processes for security reasons.
Init Replacement: After the initial boot phase, /init (on an initramfs or initrd) typically executes a switch_root or pivot_root operation and starts the actual init process (like systemd or sysvinit) from the real root filesystem. This new init process might not inherit the environment of the original /init process.
Service Configuration: Even if the init process inherits the environment variables, it might not pass them on to services it starts. For example, systemd services only inherit a few specific variables by default and ignore the rest unless explicitly configured to do so.
systemd系统可以这么干
If the init system you're using is systemd, you should know that systemd doesn't directly inherit the environment variables of its parent process. If you need some environment variables to be available for all systemd services, you could set them in the /etc/systemd/system.conf or /etc/systemd/user.conf files by using the DefaultEnvironment directive.
【 在 DreamDreams 的大作中提到: 】
: 标 题: Re: 有什么办法启动后修改全局环境变量
: 发信站: 水木社区 (Thu Jun 1 13:45:37 2023), 站内
:
: 当然不是了,/etc/init.d和initrd没什么关系
:
: 我说的就是kenrel启动完成之后第一个调用的东西,要么是/init要么是/sbin/init
:
: Debian的initrd下面就是/init这个脚本
:
: 【 在 JulyClyde 的大作中提到: 】
: : 标 题: Re: 有什么办法启动后修改全局环境变量
: : 发信站: 水木社区 (Thu Jun 1 11:45:53 2023), 站内
: :
: : 你这是混淆init和init.d
: : 【 在 DreamDreams 的大作中提到: 】
: : : /sbin/init就可以是一个脚本,不一定是是二进制文件。
: : : 在使用initrd的情况下,initrd里的init就是个脚本
: :
: : --
: :
: : ※ 来源:·水木社区 mysmth.net·[FROM: 139.226.19.*]
:
: --
:
: ※ 修改:·DreamDreams 于 Jun 1 13:50:25 2023 修改本文·[FROM: 124.207.188.194]
: ※ 来源:·水木社区 mysmth.net·[FROM: 124.207.188.194]
--
修改:DreamDreams FROM 124.207.188.194
FROM 124.207.188.194