Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
done
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
add comment

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
1  
@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. –  ultrasawblade 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
show 1 more comment

Your Answer

 
discard

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.