[systemd-devel] Can udev assist?

Robert Milasan rmilasan at suse.com
Fri Nov 20 09:55:01 PST 2015


On Fri, 20 Nov 2015 09:08:35 -0800
<Aaron_Wright at selinc.com> wrote:

> I have a script that creates a partition (using pyparted) and then
> tries to format it (using mkfs.ext4). Most of the time this works OK.
> However, sometimes the format fails because it can't find the device.
> There seems to be a race condition due to a delay between creating a
> partition and the device node in /dev being created.
> Is there a tool in udev or udevadm that can help my script know when
> it safe to proceed?

Try to use:

<create the partition>
udevadm settle --exit-if-exists=/dev/<devname>
<format the partition>

True, you need to come up with the <devname>, but if you are using
mkfs.ext4, you need to know the <devname> anyway.

Or you can do a loop for about 5-10 seconds and you
watch /dev/<devname>, but is about the same thing as with 'udevadm
settle'.

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmilasan at suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


More information about the systemd-devel mailing list