LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (http://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   USB Thumb drive mounting issues (http://www.linuxquestions.org/questions/linux-hardware-18/usb-thumb-drive-mounting-issues-463557/)

joreen 07-13-2006 02:28 AM

USB Thumb drive mounting issues
 
Hi all,

I have a start up script that starts at runlevel 5, in which it's purpose is to detect a file in the thumb drive (path: /media/CANON_DC/file_xyz)

I have no problem in detecting the /media/CANON_DC directory. However, I cannot detect the file_xyz.

In my script, before I starting the read the content of file_xyz, I have done some echo so that I can know which part of the script is having a problem.
1. ls /proc/bus/usb -> I am able to see the USB thumb drive device in the file - devices
2. ls /media/CANON_DC -> no file exists
3. cat /proc/scsi/scsi -> no USB storage drive exists during the script is running.

However, when I run my script after GNOME is started, the script works perfectly.

May I know what is the problem here? Could it be the undetectable scsi during run level 5?
How can I read the content of file_xyz? Please advice! Thank You!

cdhgee 07-13-2006 03:29 AM

The most likely thing is that the drive hasn't yet been mounted. Removable storage drives such as USB drives, CDs and DVDs are usually mounted by the automounter. However, it is possible that your script is running before the automounter starts. Check to see the relative order of the automounter script (which on my FC5 system is called autofs) and your script.

Another possibility is that gnome may be doing something clever to mount the drive. Can you get your script to do issue a [tt]mount[/tt] command and capture the output so we can see whether the drive is actually mounted or not.

Are you detecting your file using ls by the way? If so, there's a better way; use the following code instead:

Code:

[ -f "/media/CANON_DC/file_xyz" ]
The [] indicate that it's a boolean test. This will return a 0 or 1. -f tells it to look for the existence of a file. You could then combine this with an if statement, thus:

Code:

if [ -f "/media/CANON_DC/file_xyz"] ; then
    echo "good, file exists"
else
    echo "bad, can't find file...HELP!"
fi

To detect a directory, use -d in place of -f.

joreen 07-13-2006 04:32 AM

Hi cdhgee

Thanks for your reply!
I think that my script must be running before the USB drive is mounted.
May I know how can I configure the automounter such that it can starts before my script at level 5?

These are output from the "mount" command:
/dev/md0 on / type reiserfs (rw,acl,user_xattr)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
tmpfs on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
It looks like the USB is not mounted at the point of my script running.

Please advice on how I can do the mounting process right before my script.
Thank You!

cdhgee 07-13-2006 04:38 AM

Well there's various ways you could do it. Assuming you're running Fedora and as root, then this is one option, at the beginning of your script:

Code:

service autofs start
which would explicitly start the automounter.

Alternatively, manually mounting the drive is another option:

Code:

mount -t vfat /dev/sda1 /media/CANON_DC
Though that requires more effort as you then have to make sure that sda1 is the correct device and that the CANON_DC directory exists prior to mounting into it.

The most elegant solution would be to change the startup order of the scripts - this is controlled by a number in the header comment of your script. If you compare your script and /etc/init.d/autofs, you will see that autofs has a startup and a shutdown priority - simply adjust your script so that the startup priority is after that of autofs and all should be good.


All times are GMT -5. The time now is 12:24 AM.