udev:启动时连接的设备

发布于 2024-12-01 04:00:34 字数 399 浏览 8 评论 0原文

我正在使用 udev 来检测 Ubuntu 10.04 LTS x64 服务器上的 USB 驱动器连接和断开连接。当机器运行时连接 USB 设备时,一切正常,但如果在启动时已经存在 USB 设备,我的脚本将无法完成,显然是因为 mkdir /tmp/blah 不起作用。

如果我随后在终端输入 sudo udevadm trigger,一切都会正常。

我假设当 udev 首先根据其规则评估连接的设备时,根文件系统尚未安装。

因此,我的问题是:

  1. 我是否正确地识别了问题?
  2. 有没有标准的方法来解决它 - 即是否有 /tmp/ 的替代方案,我可以同时使用 / 安装之前和之后?

I'm using udev to detect USB drive connection and disconnection on my Ubuntu 10.04 LTS x64 server. Everything works fine when USB devices are connected while the machine is running, but if one is already present at boot time, my script does not complete, apparently because mkdir /tmp/blah doesn't work.

If I subsequently type sudo udevadm trigger at the terminal, everything is okay.

I'm assuming that at the point that udev first evaluates connected devices against its rules, the root filesystem has not been mounted.

My questions are therefore:

  1. Have I correctly identified the problem?
  2. Is there a standard way to solve it - i.e. is there an alterative to /tmp/ that I can use both
    before and after / has been mounted?

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

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

发布评论

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

评论(3

夏日落 2024-12-08 04:00:34

根文件系统已挂载,但当时是只读的。 /dev/shm (内存文件系统)应该可用;较新的 Linux 发行版也可能有 /run ramdisk。您还可以在某处选择一个永久目录,在脚本中在其上安装 tmpfs,然后在那里完成工作。

The root filesystem is mounted, but is read-only at the time. /dev/shm (an in-memory filesystem) should be available; newer linux distributions may also have a /run ramdisk. You can also pick a permanent directory somewhere, mount a tmpfs over it in your script, and do your work there.

清风无影 2024-12-08 04:00:34

此问题的一种解决方案是编写一个由 udev 规则调用的脚本,该脚本立即分离,并等待某些事件发生,以确保系统“足够启动”以创建挂载点等来挂载您的设备。回答以下帖子的人(http://superuser.com/questions/53978/ubuntu-automatically-mount-external-drives-to-media-label-on-boot-without-au)编写了一个脚本来检查是否“httpd”在继续之前正在运行。我确信可能还有其他“更好”的方法来做到这一点。

One solution to this problem is to write a script that's called by your udev rules that immediately detaches, and waits for some event to occur to ensure the system is "booted enough" to create mount points, etc. to mount your devices. The person who answered the following post (http://superuser.com/questions/53978/ubuntu-automatically-mount-external-drives-to-media-label-on-boot-without-a-u) wrote a script that checks if "httpd" is running before continuing on. I'm sure there are probably other "better" ways to do this too.

尘曦 2024-12-08 04:00:34

1-我不知道,即使在initramfs中,在挂载根文件系统之前,也有一个可写的/tmp目录。

确实,当安装真正的根时,此 /tmp 将被丢弃,最终的 /tmp 将为空。您确定 mkdir /tmp/blah 命令失败吗?或者你认为是因为当你寻找它时它不在那里?

2-在 Ubuntu 中(我不知道其他发行版),您在 /dev/.initramfs 中有一个隐藏目录可以满足此类需求。由于 /dev 是保留在最终根文件系统中的 tmpfs(或 devtmpfs)挂载点,因此您仍然可以在那里保留它。

1- I don't know, even in the initramfs, before the root filesystem is mounted, there is a writable /tmp directory.

True, when the real root is mounted this /tmp will be discarded and the final /tmp will be empty. Are you sure that the mkdir /tmp/blah command is failing? Or do you assume that because it is not there when you look for it?

2- In Ubuntu (I don't know of other distros) you have a hidden directory in /dev/.initramfs for these kind of needs. Since /dev is a tmpfs (or devtmpfs) mountpoint preserved in final root filesystem you will still have it there.

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