I have a custom buildroot build with minimalistic kerenel for the RPi and busybox as init and shell. At the end of the boot process I start my own service which tries to access the usb drive. However at this moment the usb driver is still initializing the usb devices including the USB drive. Kernel boots in about 4 seconds, USB device recognition takes another 4-5 seconds. So actually I would like to know how to get the USB drive automatically mounted during boot and only if that happens start my service. I could also mount the disk before starting my service, but also here it has somehow to know if the USB disk is already recognized and the /dev/sda1 is created.
1 Answer
If you built your kernel with inotify
support you'd better use to wait for device creation using inotify. If not you can put this code to where before your service started by busybox init system:
# Waiting for device creation
while true
do
test -e /dev/yournode
if [ $? -eq 0 ]; then
echo "Device created";
break;
else
echo "Waiting for device";
sleep 1;
fi
done
systemd
can do that, but might be a bit heavyweight for your application. Audev
hook?systemd
orudev
. If you aren't using either of those, you probably have to roll your own, that is, write a program that watches the kernel messages until it sees the USB drive becoming ready, then does the automount and starts your service.