1

I have an /etc/init.d script that is supposed to detect an external drive mounted at /dev/sda1, if it's there it mounts it. This works fine on my odroid device with the following specs:

pi@odroid64:~$ uname -a
Linux odroid64 3.14.65-73 #1 SMP PREEMPT Tue Aug 2 08:21:02 BRT 2016 aarch64 aarch64 aarch64 GNU/Linux

But when I run the same script on my raspberry pi with these specs:

pi@box:~ $ uname -a
Linux box 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux

It's unable to finish. By outputting lsblk in my script when I detect failure, I can see that the device has yet to appear under /dev/sda by the time the script is running. Here is the output of lsblk when the script is ran

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
 mmcblk0 179:0 0 7.4G 0 disk 
 ├─mmcblk0p1 179:1 0 63M 0 part /boot 
 └─mmcblk0p2 179:2 0 7.3G 0 part /

And here is the output of lsblk by the time I login

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 111.8G  0 disk
└─sda1        8:1    0 111.8G  0 part
mmcblk0     179:0    0   7.4G  0 disk
├─mmcblk0p1 179:1    0    63M  0 part /boot
└─mmcblk0p2 179:2    0   7.3G  0 part /

So if, after I login, I run

sudo /etc/init.d/usbstorage restart

It mounts the drive as expected, and lsblk outputs

pi@camio-box:~ $ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 111.8G  0 disk
└─sda1        8:1    0 111.8G  0 part /mnt/usbstorage
mmcblk0     179:0    0   7.4G  0 disk
├─mmcblk0p1 179:1    0    63M  0 part /boot
└─mmcblk0p2 179:2    0   7.3G  0 part /

And mounts the drive as expected.

So I think that I have the wrong headers on my init-script, like I'm not waiting for the system to detect external drives before the script it being ran. Here is the header for my script.

#! /bin/bash
### BEGIN INIT INFO
# Provides:          usbstorage
# Required-Start:    $local_fs $remote_fs $network $named $portmap
# Required-Stop:
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Mounts an external drive to /mnt/usbstorage for the cam process
### END INIT INFO

What am I doing wrong?

1

I didn't exactly figure out what went wrong, but I found a much easier way of accomplishing the same thing. Simply add this line to /etc/fstab

/dev/sda1 /mnt/usbstorage auto defaults,user,rw,uid=pi,gid=pi 0 0

the auto keyword will detect the device formatting automatically, which is what my last script was doing. Setting the uid and gid explicitly makes it work with FAT-formatted drives as well.

Your Answer

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

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