优雅地将资源从 initramfs 移交给用户空间

发布于 2024-10-05 01:12:09 字数 326 浏览 4 评论 0原文

有些硬件设备需要用户空间支持,例如守护进程运行和处理不适合内核空间(太复杂或与策略相关)的交互部分。

一旦到达用户空间,运行此类守护进程就很容易——您可以由于热插拔事件而运行它们,而不必太担心。

一旦 initramfs 出现,一切都会突然崩溃:如果守护进程是从 initramfs 运行的,那么它需要在执行切换到常规 rootfs 时继续运行,这是特别困难的,因为 initramfs 在 switch_root 期间被释放,或者分发资源并状态到其自身的另一个副本,从 rootfs 运行。这两种解决方案看起来都不优雅而且很老套。

是否有明显的方法来管理我忽略的此类设备及其支持守护进程?

There are hardware devices which need userspace suppport, like daemon running and handling parts of interaction not suitable (too complex or policy-related) for kernel space.

Running such daemons is easy once you reach userspace -- you can run'em as a result of hotplug event and don't worry much.

Once initramfs comes to the picture, everything suddenly breaks apart: if the daemon is run from initramfs then it needs to either keep running when execution is switched to regular rootfs, which is particularily hard, given initramfs is freed during switch_root or hand out resources and state to another copy of itself, run from rootfs. Both solutions seem inelegant and hacky.

Is there obvious way to manage such devices and their supporting daemons I overlooked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离线来电— 2024-10-12 01:12:32

你需要这个守护进程来挂载你真正的根设备吗?我想答案是肯定的,否则解决方案就是等待你真正的root。

我的设备非常复杂,需要一个守护进程才能工作,也许您可​​以在内核中完成部分工作,并通过 sysfs 属性处理策略?
我没有看到安装真正的根设备所需的硬件示例,该设备需要守护进程才能工作。设备发现适用,但您不需要守护程序即可使设备实际工作。欢迎举个例子。

另外,你真的需要切换root吗?你可以保留你的 initramfs,并在 /usr/ 下安装你需要的任何东西来拥有一个功能齐全的系统,这就是我对我的一些嵌入式系统所做的。

更新 :
mdev 是 udev 的嵌入式替代品,它以两种模式运行:扫描 sysfs 以添加设备,另一种运行热插拔事件。所以我想你不需要“存储”热插拔事件,因为所有信息在 sysfs 中仍然可用。所以解决方案是这样的:

  • 从 initramfs 运行 udev
  • 安装真实根目录并切换根
  • 扫描 sysfs (udev 在启动时执行此操作吗?)
  • 正常操作(即等待热插拔事件)

Do you need this daemon to mount your real root device ? I guess the answer is yes, otherwise the solution would be to wait for your real root.

I your device is so complicated it needs a daemon to just work, may be you could do part of the job in the kernel, and handle the policy through sysfs attribute ?
I fail to see an example of hardware invlved in mounting the real root deice that would need a daemon to work. Device discovery apply, but you don't need a daemon for the device to actually work. An example would be welcome.

Also, do you really need to switch root ? You could keep your initramfs, and mount whatever you need to have a fully functionnal system under /usr/ That is what I do with some of my embedded system.

Update :
mdev is an embedded alternative to udev, which runsin two mode: on scans sysfs to add device, the other is running for hotplug event. So I guess you don't need to "store" hotplug event, because all the info is still available in sysfs. So the solution is something like :

  • run udev from initramfs
  • mount real root and switch root
  • scan sysfs (does udev do that on startup ?)
  • normal operation (ie wait for hotplug event)
久隐师 2024-10-12 01:12:30

你有具体的案例吗?其他发行版是如何处理这个问题的?

看看 Fedora 如何处理 udev,它从 initramfs 启动它,让它做它的事情,以便可以挂载真正的 root fs,然后在切换之前再次关闭它。

Do you have a specific case? How have the other distributions handled this?

Looking at how Fedora does udev, it starts it up from the initramfs, gets it to do its stuff so the really root fs can be mounted, then shuts it down again before switching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文