If I accessed either drives after they had gone to sleep they would be mounted again but because the first mount points were still in /media my system seemed to like to randomly append an ‘_’ to the names of the mount points… sometimes… when it felt like it. The problem with this is that if anything running on my machine was looking for ‘/media/my_usb_drive’ it might find this mount point but because it is has become a ghost mount point the program will find nothing inside. The real drive would now be mounted to ‘/my_media/usb_drive_’.
So I created a script to deal with automatically finding the drives attached to my computer and mounting them to permanent mount points I created in /mnt. The mount points are simply directories I created in /mnt for the sole purpose of being a permanent home for my drive partitions. Now if the drives go to sleep I can simply run this script file and it will wake up the drives that are sleeping and mount them in their proper place in /mnt.
The benefit of this is that I no longer have to worry about having ghost mount points and I can use absolute file paths with no problems. Also, if I unplug and plug back in one of the drives I run this script and it automatically finds the correct /dev location of the drive and mounts it for me.
The script is fairly simple and contains enough comments that it should be fairly easy to edit it for your own needs. It is currently setup for my own system. Also, notice this program does not need to be used just with USB drives. Any drive type will work.
An extra tip
If you really hate to have your drives fall asleep you can directly edit your cron job process by using “crontab -e” and adding the line for each partition or drive:
“0 1 * * * ls /path_to_drive/my_mount_point”
The cron job process executes a command at a specific time like 1 AM for a system backup or at set time interval like every hour. Adding the above will tell the cron job to poke your drives every hour to keep them awake. Although if you don’t have a serious reason for using this you’ll save energy and have happier drives by letting them fall asleep. :) You could also setup cron to execute this script every so often just to make sure you’ll definitely keep your drives awake and mounted properly.
Click to directly download mount-usb-drives.sh
|
#!/bin/bash # file name 'mount-usb-drives.sh' # coded by: Louis Casillas, e-mail: oxaric@gmail.com # Below are the physical IDs of the drives # ID: USB DRIVE: S_DRIVE # ID: USB DRIVE: P_DRIVE # My USB drives are FAT32 so they use the vfat format to be mounted # this is my user ID total_max_drives_to_find=2 # number of USB drives I have echo # grabs a list of all the drives connected to the machine # setup the input so the while loop will read every # remove the temp file while read line # if the ID was found then attempt to mount the drives number_of_drives_found=$(( $number_of_drives_found + 1 )) echo # burn a line # read in the line that will tell us where linux has mounted # grab the basic location i.e. /dev/sdb # my USB drives have 3 partitions and I have created a permanent location # takes the current line and looks for the physical ID # if the ID was found then attempt to mount the drives number_of_drives_found=$(( $number_of_drives_found + 1 )) echo # burn a line # read in the line that will tell us where linux has mounted # grab the basic location i.e. /dev/sdb # my USB drives have 3 partitions and I have created a permanent location echo |