LinHES Forums http://forum.linhes.org/ |
|
I'd LOVE a definitive answer on mounting usb flash drives! http://forum.linhes.org/viewtopic.php?f=5&t=9075 |
Page 1 of 2 |
Author: | RichardBronosky [ Sun Mar 19, 2006 12:03 am ] |
Post subject: | I'd LOVE a definitive answer on mounting usb flash drives! |
I have been at this for almost a year and I still cannot get this figured out. I have a camera that uses an SD card. So I put a 6-in-1 card reader in my mythtv box. I've NEVER got it to do anything. So I bought a usb pen drive that uses SD. I got that to mount once several months ago, but I don't think it ever worked with my R5A30.2 install. So how is this done? What details do I need to give to get help? |
Author: | cesman [ Sun Mar 19, 2006 2:05 am ] |
Post subject: | |
Plug in your USB pen, then run dmesg. You should see what device your device is (/dev/sdX). Edit you /etc/auto.master so it look like: Quote: # $Id: auto.master,v 1.2 1997/10/06 21:52:03 hpa Exp $ # Sample auto.master file # Format of this file: # mountpoint map options # For details of the format look at autofs(5). # /var/autofs/misc /etc/auto.misc # /var/autofs/net /etc/auto.net # KNOPPIX automounts for floppy and cdrom(s), see knoppix-autoconfig /mnt/auto /etc/auto.mnt --timeout=2 /var/autofs/usb /etc/auto.usb --timeout=2 #/mnt/auto /etc/automount.sh --timeout=2 Edit (create) /etc/auto.usb, it should look like: Quote: # Format of file: Note in the above example, sdc is what I want to use.
# mountpoint options device #sda -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sda1 #sdb -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdb1 sdc -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdc1 #sdd -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdd1 Code: ln -s /var/autofs/usb/sdc /mnt/usb Code: /etc/init.d/autofs restart
Then simply cd to /mnt/usb.... |
Author: | tjc [ Fri Mar 24, 2006 12:44 am ] |
Post subject: | |
Cecil, I'd really like to be able to use my new USB thumb drives for customizing installs. However since this process is kind of a nusicance to do manually before all my usual infrastructure is set up, I thought turning it into a script might be worthwhile. What do you think? Code: root@black2:~# cat setup_usb_drive.sh
#!/bin/bash if [ $(id -u) != 0 ] ; then echo "Error: You must be root to run this script!" exit 4 fi case $1 in sd[a-z]) drive=$1 ;; /dev/sd[a-z]) drive=$(basename $1) ;; *) echo "Error: Device '$1' is not a SCSI disk (sd?)" exit 2 ;; esac if [ -n "$2" ] ; then mntpoint=$2 else mntpoint=/mnt/${drive} fi mntparent=$(dirname $mntpoint) if [ ! -d "$mntparent" ] ; then echo "Error: Parent of mount point '$mntpoint' is not a directory!" exit 2 elif [ -L "$mntpoint" ] ; then rm $mntpoint elif [ -e "$mntpoint" ] ; then echo "Error: mount point '$mntpoint' already exists!" exit 2 fi if grep ^/var/autofs/usb /etc/auto.master >/dev/null ; then echo "Looks like there is already a USB storage hook in auto.master" else echo "Adding a USB storage hook to auto.master" cp /etc/auto.master /etc/auto.master.orig echo "/var/autofs/usb /etc/auto.usb --timeout=2" >>/etc/auto.master fi if grep ^$drive /etc/auto.usb >/dev/null 2>&1 ; then echo "Looks like /dev/$drive is already in auto.usb" else echo "Adding /dev/$drive to auto.usb" [ -f /etc/auto.usb ] && cp /etc/auto.usb /etc/auto.usb.orig echo "$drive -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/${drive}1" >>/etc/auto.usb fi ln -s /var/autofs/usb/$drive $mntpoint /etc/init.d/autofs restart |
Author: | cesman [ Fri Mar 24, 2006 12:56 am ] |
Post subject: | |
Nice! I was thinking of writing a script for this. |
Author: | mjl [ Fri Mar 24, 2006 7:17 am ] |
Post subject: | |
HI, Subject close to my own interests I usually just add a line in the fstab and make a directory to match. With the R5B7 release, my son wanted to also join the KnoppMyth group so when it came time to do the fstab trick, it didn't work. The only thing "un-typical" is that the machine has the additional sd / cf / mmc / etc slots which appears to change things enough to not allow the machine to find the memory stick. I haven't tried tjc's script yet, as I try to understand what it does first. As a side note, this is a triple boot machine, M$, Ubuntu and KnoppMyth. What is so cool about Ubuntu is the memory stick just pops up on the desktop when plugged in..... That would be very nice KnoppMyth feature, but I am just as happy keeping it simple & manual.. It doesn't make any difference which R5Ax or R5Bx, any ideas or hints? Have a great day! Mike |
Author: | EvilTwin [ Fri Mar 24, 2006 8:18 am ] |
Post subject: | |
mjl wrote: I haven't tried tjc's script yet, as I try to understand what it does first.
It looks like it checks two command line arguments (required device name and optional pseudo mount point), then does pretty much what Cecil's manual procedure does, being careful not to duplicate stuff that's already in place. The only difference I see is that it leaves automount.sh uncommented rather than switching to auto.mnt, and the ordering of the entries in auto.master is different because it appends... It seems to work OK. |
Author: | cesman [ Sat Mar 25, 2006 5:18 am ] |
Post subject: | |
A little improvement. Just plug in the key and run the script. "R6" will have a more elegant solution. This only needs to be done once. After this, you simple need to plug in the drive and access the properly directory. Code: #!/bin/bash
if [ $(id -u) != 0 ] ; then echo "Error: You must be root to run this script!" exit 4 fi echo "Please insert USB key and press <ENTER>." read echo "Just a sec..." echo "Trying to determine location of USB key." sleep 7 dmesg | tail >> /tmp/usb drive=$(grep " sd[a-z]: sd" /tmp/usb | awk '{print $2}') mntpoint=/mnt/$drive mntparent=$(dirname $mntpoint) if [ ! -d "$mntparent" ] ; then echo "Error: Parent of mount point '$mntpoint' is not a directory!" exit 2 elif [ -L "$mntpoint" ] ; then rm $mntpoint elif [ -e "$mntpoint" ] ; then echo "Error: mount point '$mntpoint' already exists!" exit 2 fi if grep ^/var/autofs/usb /etc/auto.master >/dev/null ; then echo "Looks like there is already a USB storage hook in auto.master" else echo "Adding a USB storage hook to auto.master" cp /etc/auto.master /etc/auto.master.orig echo "/var/autofs/usb /etc/auto.usb --timeout=2" >>/etc/auto.master fi if grep $drive /etc/auto.usb >/dev/null 2>&1 ; then echo "Looks like /dev/$drive is already in auto.usb" else echo "Adding /dev/$drive to auto.usb" [ -f /etc/auto.usb ] && cp /etc/auto.usb /etc/auto.usb.orig echo "$drive -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/$drive" > >/etc/auto.usb fi ln -s /var/autofs/usb/$drive $mntpoint ln -s $mntpoint /myth/gallery/usb ln -s $mntpoint /myth/music/usb ln -s $mntpoint /myth/video/usb /etc/init.d/autofs restart |
Author: | tjc [ Sat Mar 25, 2006 9:51 am ] |
Post subject: | |
I'd thought about looking at the output of dmesg or /var/log/messages for "sd" devices, but had opted to leave it manual so that the timing of when the drives were plugged in or how many you plugged in wasn't an issue. Say if you have a couple external USB HDs which are normally plugged in when you power up, or if you wanted to setup so that when you do plug in the drive later (say in another room) it would be recognized. On the other hand, this actually makes my intended use easier... Of course automatically recognizing and mounting the drive the first time it's plugged in is even better. |
Author: | tjc [ Sun Mar 26, 2006 2:13 pm ] |
Post subject: | |
Looks like the autodetection in that second version of the script is broken. I'll get back to you with a fix ASAP. |
Author: | proto [ Tue Apr 11, 2006 7:24 am ] |
Post subject: | |
When I try the script I get the following message... root@mythtv:~# ./check Please insert USB key and press <ENTER>. Just a sec... Trying to determine location of USB key. Error: mount point '/mnt/' already exists! --Proto |
Author: | tjc [ Tue Apr 11, 2006 6:44 pm ] |
Post subject: | |
Try this more recent version: Code: #!/bin/bash
if [ $(id -u) != 0 ] ; then echo "Error: You must be root to run this script!" exit 4 fi if grep ^/var/autofs/usb /etc/auto.master >/dev/null ; then echo "Looks like there is already a USB storage hook in auto.master" else echo "Adding a USB storage hook to auto.master" cp /etc/auto.master /etc/auto.master.orig echo "/var/autofs/usb /etc/auto.usb --timeout=2" >>/etc/auto.master fi echo "Please insert USB key and press <ENTER>." read echo "Just a sec..." echo "Trying to determine location of USB key." sleep 7 drives=$(dmesg | awk '/Attached scsi removable disk sd/ {print $7}' | sort -u) for drive in $drives ; do mntpoint=/mnt/$drive mntparent=$(dirname $mntpoint) if [ ! -d "$mntparent" ] ; then echo "Error: Parent of mount point '$mntpoint' is not a directory!" exit 2 elif [ -L "$mntpoint" ] ; then rm $mntpoint elif [ -e "$mntpoint" ] ; then echo "Error: mount point '$mntpoint' already exists!" exit 2 fi if grep ^$drive /etc/auto.usb >/dev/null 2>&1 ; then echo "Looks like /dev/$drive is already in auto.usb" else echo "Adding /dev/$drive to auto.usb" [ -f /etc/auto.usb ] && cp /etc/auto.usb /etc/auto.usb.orig echo "$drive -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/$drive" >>/etc/auto.usb fi ln -s /var/autofs/usb/$drive $mntpoint done /etc/init.d/autofs restart This still could use a few enhancements but it should work a bit better. |
Author: | iscraigh [ Thu Apr 13, 2006 9:06 pm ] |
Post subject: | |
Ok I tried the newest script to mount a usb harddrive it seems to mount under /var/autofs/usb If I try to create a directory as root I get a permission denied. The permisions on /var/autofs/usb are 755 Any suggestions as to what may be going on. Also look for my thread on mount points. Craig |
Author: | tjc [ Thu Apr 13, 2006 10:03 pm ] |
Post subject: | |
That's because /var/autofs/usb isn't a normal filesystem. Try running the mount command with no arguments and notice that instead of a device it's associated with a process. Why do you think you need to create a directory? The automounter does that for you based on what is in the auto.XXX file. Once you've run that script you should be able to refer to the symbolic link it sets up and see/modify the drives contents. You may need to comment out this line: Code: #/mnt/auto /etc/automount.sh --timeout=2
in /etc/auto.master, as Cecil shows in his original directions, but other than that it, it should just work. |
Author: | iscraigh [ Thu Apr 13, 2006 10:43 pm ] |
Post subject: | |
Fortunately I am comfortable feeling like an Idiot. If I am understanding it correctly I should be able to cd to /mnt/usb when I try I get root@mythtv:/# cd /mnt/usb -bash: cd: /mnt/usb: No such file or directory My auto.usb file is # Format of file: # mountpoint options device #sda -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sda1 sda -fstype=ext3,uid=1002,gid=1002,umask=002,noatime :/dev/sda1 #sdb -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdb1 sdc -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdc1 #sdd -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdd1 my auto.master is # $Id: auto.master,v 1.2 1997/10/06 21:52:03 hpa Exp $ # Sample auto.master file # Format of this file: # mountpoint map options # For details of the format look at autofs(5). # /var/autofs/misc /etc/auto.misc # /var/autofs/net /etc/auto.net # KNOPPIX automounts for floppy and cdrom(s), see knoppix-autoconfig /mnt/auto /etc/auto.mnt --timeout=2 #/mnt/removable auto.removable /var/autofs/usb /etc/auto.usb --timeout=2 #/mnt/auto /etc/automount.sh --timeout=2 seems to be correct. Am I misunderstanding where the mount point is? Craig |
Author: | tjc [ Fri Apr 14, 2006 10:12 am ] |
Post subject: | |
iscraigh wrote: If I am understanding it correctly I should be able to cd to /mnt/usb Only if you created that as a symbolic link. iscraigh wrote: My auto.usb file is
- Comment out the line for sdc. - Unplug and replug your USB drive. - Go look in /var/log/messages for how it was recognized and hopefully mounted. This should be as "/dev/sda". - Look at the /mnt directory - ls -al /mnt the script should have set up a /mnt/sda link there. - Use that link to access the device. You can create any other links to the same target that you want. |
Page 1 of 2 | All times are UTC - 6 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |