Monday, May 14, 2012

Mounting a USB device

ASSUME:
Command line knowledge
How to get to be a root user

Despite all the promises, Linux often chokes when it comes to mounting a USB device such as a camera, phone, etc, it often chokes and its frustrating not knowing a way to get it to work.  Here it goes:

FIRST:
You need to be a root user to get this to work.  Often times that just means SUDO but you can also use SU as well.  If you type SUDO, type your username

(e.g. SUDO foo)...or whatever your name is.

Type in your normal password and you're a root user.  SU works the same way but you don't need to type a username...just SU (super user in other words) and you need to know the ROOT password to do it.  Most distros are going the SUDO route so chances are try that.

SECOND:
lsusb  (list USB devices...linux people hate to type)

This will just ensure you have a USB device in there. Look for the term 'usb in the list.

Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 004 Device 002: ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0
Bus 004 Device 003: ID 045e:0040 Microsoft Corp. Wheel Mouse Optical
Bus 001 Device 006: ID 22b8:70c6 Motorola PCS

In this example, you'll see the USB-2.04-Port HUB.  Ya, that looks about right and this tells us that USB is working. 

You could also type:

lsusb | grep USB

This would filter out the list to only show anything with USB in the name.  Don't ya love greg!

THIRD
Now that we KNOW we have a USB device, let's see what the drive is that mounts it.  Fortunately, we have a miracle command called DMESG.  This lists all the messages recently printed.  Naturally we want the find any USB devices. 


dmesg (let it scroll past you.  We want the end of the list...NOT...anything else.


[ 2432.904237] sr 8:0:0:2: Attached scsi generic sg6 type 5
[ 2432.914538] sd 8:0:0:1: [sde] Attached SCSI removable disk
[ 2432.918523] sd 8:0:0:0: [sdd] Attached SCSI removable disk
[ 2435.563830] sd 8:0:0:1: [sde] 15572992 512-byte logical blocks: (7.97 GB/7.42 GiB)
[ 2435.565942] sd 8:0:0:1: [sde] No Caching mode page present
[ 2435.565950] sd 8:0:0:1: [sde] Assuming drive cache: write through
[ 2435.570814] sd 8:0:0:1: [sde] No Caching mode page present
[ 2435.570820] sd 8:0:0:1: [sde] Assuming drive cache: write through
[ 2435.573677]  sde: sde1
[ 2441.705601] sd 8:0:0:0: [sdd] 9050112 512-byte logical blocks: (4.63 GB/4.31 GiB)
[ 2441.707717] sd 8:0:0:0: [sdd] No Caching mode page present
[ 2441.707720] sd 8:0:0:0: [sdd] Assuming drive cache: write through
[ 2441.712716] sd 8:0:0:0: [sdd] No Caching mode page present
[ 2441.712718] sd 8:0:0:0: [sdd] Assuming drive cache: write throug




NOTICE: the 'removable disk.  Ya, that's what we want.  In this example we have sdd and sde telling us that there are two drives associated with the device.  We'll mount both.

Now, on some distro's they create a /media directory and you mount things there.  The default is always /mnt but honestly you can mount it anywhere.  I tend to use /mnt but its up to you.

mkdir /mnt/FRED
mkdir /mnt/FRED2

mount /dev/sdc /mnt/FRED
mount /dev/sde /mnt/FRED2

HU???

Well, easy.  mount is the command that tells us to mount the device.  It takes two parameters.  The first is the source and the second is where you want to mount it.

/dev/sdc comes from dmesg and /mnt/FRED is the directory (folder) I created to mount the device.  Ya, Fred isn't too original but you can come up with something more original.

That's it.  You should now see the data in /mnt/FRED and /mnt/FRED2

I tend to just cd into that directory (I'm not covering cd here) but you can use a file manager such as nautilus if you want.


No comments:

Post a Comment