Udev: device connected at boot time

I use udev to detect a USB connector and disconnect on my Ubuntu 10.04 LTS x64 server. Everything works fine when USB devices are connected while the device is running, but if it is already present at boot time, my script does not end, apparently because mkdir /tmp/blah does not work.

If later I type sudo udevadm trigger on the terminal, everything will be okay.

I assume that at the moment when udev first evaluates the connected devices against their rules, the root file system was not mounted.

So my questions are:

  • Did I identify the problem correctly?
  • Is there a standard way to solve it - i.e. Is there an alternative to /tmp/ that I can use both before and after / was installed?
+6
source share
3 answers

The root file system is mounted but read-only. /dev/shm (file system in memory) should be available; newer Linux distributions may also have ramdisk /run . You can also find the permalink directory somewhere, connect tmpfs to it in a script and do your work there.

+5
source

One solution to this problem is to write a script called by your udev rules that immediately detaches and waits for some kind of event to provide a "sufficiently loaded system" to create mount points, etc. to mount your devices. The person who responded to the next post (http://superuser.com/questions/53978/ubuntu-automatically-mount-external-drives-to-media-label-on-boot-without-au) wrote a script that checks whether "httpd" is running before proceeding. I'm sure there are other “better” ways to do this too.

+2
source

1- I don’t even know, even in initramfs, before the root file system is mounted, there is a directory for writing / tmp.

However, when the real root is set, this / tmp will be discarded, and final / tmp will be empty. Are you sure the mkdir /tmp/blah command does not work? Or do you assume that because he is not there when you seek him?

2- In Ubuntu (I do not know other distributions) you have a hidden directory in /dev/.initramfs for these needs. Since /dev is the mount point of tmpfs (or devtmpfs) stored on the destination root file system, it will still be there.

+1
source

Source: https://habr.com/ru/post/895690/


All Articles