Full Version: Mounting A USB or Pen Drive In Linux
Dream.In.Code > Programming Tutorials > Linux Tutorials
bsdninja
If you are having problems mounting a USB storage drive (hard drive or pen drive etc) first plug in the device and boot the computer. Watch your boot-up process to see if it detects the device. If so you probably won’t have to recompile your kernel.

First step is to go into your kernel’s source directory. Usually /usr/src/linux
If it is a recent kernel i.e. 2.6+ type:
QUOTE
make menuconfig


This will bring up a graphical menu of your kernel’s options, If you have to change anything here you must compile your kernel for the changes to take affect.

You want to enable scsi support and USB support like below if they are not already:

Device Drivers -------->
SCSI Device Support --------->
[*] legacy /proc/scsi/ support
<*> SCSI disk support
<*> SCSI generic support
USB Support -------------->
<*> Support for USB
[*] USB device filesystem
< > EHCI HCD (USB 2.0) support
< > OHCI HCD support
<*> UHCI HCD (most Intel and VIA) support
<*> USB Mass Storage support

If you experience problems with it still not seeing your drive try enabling EHCI or OHCI.

Now if you didn’t have to change anything here you can skip the compiling phase and go to mounting.

Next you need to compile. There are many ways to go about this so I'll just show you how I usually do it (recent kernels 2.6+). Type:
QUOTE
make (not necessary but I like to make sure)
(wait)
make modules
(wait)
make modules_install
(wait)
make bzImage
cp arch/i386/boot/bzImage /boot/linux-usb (you can name "linux-usb" what ever you want)


I will explain this next part for lilo if you use grub or something else your on your own here.

Edit your /etc/lilo.conf
and add:
CODE

       image=/boot/linux-usb (where linux-usb is the name of your image)
    label=name (where name is the name you want to pop up on lilo)
    read-only
    root=/dev/hda1 (where hda1 is what ever partition your using)

Now save and exit the lilo.conf file.
Now type "lilo" at the command line. It should say something about adding your image.
Reboot and make sure it all works.

*mounting*
If your kernel is all good and ready you should be able to mount
Go into your /dev directory
look for sdXX where XX is a leter and number ex: sda1.
Some distros will only make a dev for the devices you have and some will not. If there are a lot of sdXX's in there than just start with sda1 and try others if you have no luck.
Make a directory to mount your drive to ex:
QUOTE
mkdir /mnt/pendrive

Then mount it:
QUOTE

mount -t vfat /dev/sda1 /mnt/pendrive
where vfat is the type and sda1 is the dev for your drive.
the -t vfat is not allways nessisary but if it mounts and you have read or write errors then you need the -t vfat.
Well hopefully this helps someone. Oh don't forget to unmount using
umount /mnt/pendrive
Where /mnt/pendrive is the mount point.  If you dont unmount you will loose changes and risk messing up your partition.
_byte_
Description is gud! Let me try that on my linux.
Nova Dragoon
Some flashdrives do not have partitions. And linux will attach them to /dev/sda
Nova Dragoon
Many digital cameras will attach to linux as a usb mass-storage device and will be accessible the same way as a flash drive.

Ex. My Nikon CoolPix 4600
siddu_sundaram
hi
i have a problem when i am using this command to load my usb it just gives me details that it is not able to load this file system what may be the problem pls helproot@ttyp0[knoppix]# mkdir /mnt/usb/
root@ttyp0[knoppix]# mount -t -vfat /dev/sda /mnt/usb
mount: fs type -vfat not supported by kernel
root@ttyp0[knoppix]#

this is the reply i get when i am typing the command
thanks sad.gif
Nova Dragoon
Looks like you don't have vfat filesystem support compiled in your kernel.

Go to your source directory which should be
/usr/src/linux*.* ....

run:
make menuconfig

VFAT is found
In 2.6:
Goto Filesystems->DOS/FAT/NT Filesystems
Select VFat

In 2.4:
Goto Filesystems
Select DOS Fat fs support


Look here for more info on compiling and installing your kernel

If you need more help compiling your kernel, open up a new thread in the Operating Systems Forum.
born2c0de
Thanx Nova Dragoon, helped me out quite a bit.
amos
I've previously had all of the following attached to my box at one time or another as USB drives - pendrive, mp3 player (iRiver), camera, and mobile phone. Its probably 6 months or more since I upgraded to Slackware 10.1, for one reason or another I'd connected none of these recently. I've been using a 2.6.11 kernel which I compiled myself.(I might get round to slapt-get upgrading to 10.2 next weekend and compiling a newer kernel)

When I plugged my pendrive in the other month, so that I could copy something from it to my Linux box, I had the normal entries for it in fstab, but got an error when I tried to mount it.

Looking at dmesg after plugging the drive in gave me the following output:

CODE
usb 2-2.3: new full speed USB device using ehci_hcd and address 5
uba: device 5 capacity nsec 125952 bsize 512
uba: device 5 capacity nsec 125952 bsize 512
/dev/ub/a: p1


It used to have /dev/sda or /dev/sda1 as its mount point. I couldn't find any references to what was going on on Google or Linuxquestions.org, and I tried all of the combinations of /dev/ub* I could think of so I left it. I've now found a reply to someones similar query which boils down to:

If you enable BLK_DEV_UB it completely disrupts the USB-storage driver. So what you have to do is disable it in:

->Device Drivers
->Block Devices

and deselect the option for:
Low Performance USB Block driver

this should re-enable the SCSI drivers (after recompiling and installing the kernel) and restore the pendrive/camera/mp3 player to /dev/sd*.

Hope this helps anyone who was having similar problems to myself.

Cheers
Amos
Nova Dragoon
CONFIG_BLK_DEV_UB:

This driver supports certain USB attached storage devices
such as flash keys.

Warning: Enabling this cripples the usb-storage driver.

If unsure, say N.

Symbol: BLK_DEV_UB [=n]
Prompt: Low Performance USB Block driver
Defined at drivers/block/Kconfig:354
Depends on: USB
Location:
-> Device Drivers
-> Block devices


These guys are to blame tongue.gif
* Copyright © 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
* Copyright © 2004 Pete Zaitcev (zaitcev@yahoo.com)
amos
When I originally came across the problem at the end of July I did a search on both Google and linuxquestions and nothing showed up. It was only when I checked it out again today that I actually found anything.

I'm assuming it must have been enabled by default because the kernels on both my laptop and desktop had it enabled (and I configured both from scratch).

Cheers
Amos
Nova Dragoon
Thats weird, it shouldnt have been enabled by default, default is N in the config script?

Were you using Vanilla sources?
amos
QUOTE
Thats weird, it shouldnt have been enabled by default, default is N in the config script?

Were you using Vanilla sources?


Maybe I did enable it then, it just seems strange that I enabled it twice separately on 2 different machines. I assumed I'd used vanilla sources but I might have used a Slackware 2.6.x .config file to get me started I can't actually remember (but I doubt if that was the cause as I can't see Patrick rendering users' pendrives unusable without a kernel recompile).

Basically I must have done it! blush.gif

Twice! stupid.gif

Cheers
Amos
k.sangeeth
-t option in mount was very helpful .. good work
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.