I have an embedded system with a tiny initramfs which needs to mount an overlayfs over the rootfs partition and switch_root to the new merged filesystem.

It's just a couple operations run from the init shell script so I don't want to pull in the entire systemd infrastructure but I want to make sure all relevant block devices are already present in the system or wait for them to appear. I added the systemd-udevd component to my initramfs (considering even switching to eudev if I can get the same results).

I was unable to find any examples or figure out how to use udevadm to block and wait until a specific device appears. It seems to me that some combination of udevadm trigger and settle should do it, but no combination seemed to work in my case.

I can easily code it using libudev in C or pyudev in Python, but I guess there should be a way to achieve that using existing tools.

I would prefer to avoid some busy waiting with manual checking if given file exists already.

  • udevadm monitor will output new devices as they appear, so you can pipe that into some script, but typically if you are running udev you should set up a rule to run the script when the device is matched by the rule. see man 7 udev. – meuh Sep 14 '18 at 19:00
  • There are a few systemd-udev alternatives (e.g. mdev, eu-dev etc) that may be more appropriate for space constrained devices and nice list of them can be seen in a Are there alternatives to using udev Unix Stack Exchange answer . – Anon Jan 17 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.