Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a partition with sfdisk under linux. After partition creation I want to create a filesystem.

This fails with mkfs.ext3 not finding the partition:

echo ",,L" | sfdisk $DEVICE
mkfs.ext3 $PARTITION

But this works:

echo ",,L" | sfdisk $DEVICE
sleep 1
mkfs.ext3 $PARTITION

I suspect, either the kernel takes some time to update it's internal data structures, or my script gets scheduled again, before udev had a chance to create the device node.

How do I wait exactly until the device node is created? With every constant time, there may be a system under load where this time is not eneugh.

share|improve this question
up vote 1 down vote accepted

There's always the low-tech solution, if you know in advance the device name:

while [ ! -e /dev/whatever ] ; do 
  sleep .1 # you can sleep for less than a second with coreutils sleep
  # optionally add a counter & timeout
share|improve this answer
polling is not the nicest concept, but so far nobody came up with something better – johannes May 9 '12 at 10:03

Try using inotifywait (from inotify-tools) on the device node. the /dev directory.

share|improve this answer
inotifywait faìls when called for non existing file – johannes May 8 '12 at 12:43
@johannes: It will work when called for /dev, though. – grawity May 8 '12 at 12:52
what if the file gets created before inotywait starts? – johannes May 8 '12 at 13:07
Check if file exists with if [[ -e /dev/whatever ]]; then ...; fi before invoking inotifywait. – LawrenceC May 8 '12 at 13:52
what if the file gets created inbetwen the -e and the invokation of inotifywait? – johannes May 8 '12 at 17:24

Later, but better than never. For completeness.

udevadm settle --timeout=15 --exit-if-exists=$PARTITION
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.