# usb flash drive ... help!

## KsE

I just got a usbdrive (a 256meg usb flash drive), but I don't know how to use it with linux? Do I need hotplug for it? Or is that just for pci stuff? 

I would like to be able to plug it in and out without restarting.

It's a driverless plug-n-play device. Does anyone know?

-KsE

----------

## nephros

You need the following in your kernel:

USB support   :Razz: 

USB Storage Support

SCSI generic support

SCSI disk support

FAT filesystem support (not nesessary if you re-format it with a linux filesystem, but this does not make much sense with a USB drive if you want to access the data on other OSs)

Compile these into your kernel as modules, plug the drive in, modprobe the modules, and your drive should show up as, for example, /dev/sda1 (if you have no other SCSI devices).

Watch dmesg output after modprobing to see whitch.

You can then mount the device and access it normally.

Before unplugging, you should umount it, and can, to be on the safe side, "eject" it too.

hope that helps.

----------

## nephros

oh, and on hotplug: you can use hotplugd or usbd to detect the device when it's plugged in and load the modules for you, I never do that personally though.

I am afraid you will have to reboot at least once after you recompiled your kernel (if it does not have the support already), but after that you won't.

----------

## KsE

Thanks for the help! I shouldn't have a problem with the kernel part, but I've never done a modprobe before. How do you do that? Also, how do you eject a drive? I usually just unmount something and push eject on the hardware itself, but there's no eject button here  :Smile: 

-KsE

----------

## mr45acp

Here is a "HOWTO USB Mass Storage Device and Gentoo" thread.

----------

## nephros

 *KsE wrote:*   

> Thanks for the help! I shouldn't have a problem with the kernel part, but I've never done a modprobe before. How do you do that? 

 

You just do "modprobe <modulename>".

But if you don't know that, you should probably read some of the HOWTOS or even a book for linux newbies.

Nothing wrong with being new, but this is rather basic basics   :Smile:  .

 *KsE wrote:*   

> Also, how do you eject a drive? I usually just unmount something and push eject on the hardware itself, but there's no eject button here  

 

There is an "eject" command. It usually is used with CDROM drives to eject the tray, but it also unlinks removable devices from the SCSI bus.

My USB drive has a little LED which indicates that it is accessible. It stays on when I umount, but goes out when I "eject".

----------

## KsE

I think I've tried everything here, and on the link that mr45acp gave, and I still can't get it to work. Is there something I'm doing wrong?

I compiled everything as modules, but then decided to compile them into the kernel. Emerge hotplug, put 

```

/dev/sda1     /mnt/usbdrive     auto     noauto,user,exec     0 0 

```

into my /etc/fstab file. Tried modprobe and things, did everything that I could find and I still can't get it to work. When I do dmesg I get:

```

hub.c: new USB device 00:07.2-2, assigned address 2

hub.c: USB hub found

hub.c: 1 port detected

hub.c: new USB device 00:07.2-2.1, assigned address 3

scsi1 : SCSI emulation for USB Mass Storage devices

  Vendor: JMTek     Model: USBDrive 2.0      Rev: P1.0

  Type:   Direct-Access                      ANSI SCSI revision: 02

Attached scsi removable disk sda at scsi1, channel 0, id 0, lun 0

SCSI device sda: 512000 512-byte hdwr sectors (262 MB)

sda: Write Protect is off

 /dev/scsi/host1/bus0/target0/lun0: p1 p2 p3 p4

WARNING: USB Mass Storage data integrity not assured

USB Mass Storage device found at 3

```

I really don't know what to do know. Can you help?

-KsE

----------

## nephros

Well, you can now 

```
mount /dev/sda1 /mnt/stick
```

 and access your files as usual. (And, as your stick seems to have four partitions, can use sda2,3,4 too.)

If you want the mounting and unmounting to be automated, you will have to use automount (man automount).

----------

## KsE

I did

```

mount /dev/sda1 /mnt/usbdrive

```

and got this

```

mount: special device /dev/sda1 does not exist

```

Now what?

-KsE

----------

## nephros

Try it with /dev/scsi/host1/bus0/target0/lun0/part1 instead of /dev/sda1.

----------

## oniq

/dev/sda* should exist.  According to the output you pasted.  Check with ls /dev/sda*.

----------

## KsE

Ok. Here's what happens. (sorry about the delay, I have school and work a lot, so there's not much time to be spent on my computer) I start up my computer and there is no sda1... I plug in the usbdrive and get this from the dmesg:

```

hub.c: new USB device 00:07.2-2, assigned address 2

hub.c: USB hub found

hub.c: 1 port detected

hub.c: new USB device 00:07.2-2.1, assigned address 3

scsi1 : SCSI emulation for USB Mass Storage devices

  Vendor: JMTek     Model: USBDrive 2.0      Rev: P1.0

  Type:   Direct-Access                      ANSI SCSI revision: 02

Attached scsi removable disk sda at scsi1, channel 0, id 0, lun 0

SCSI device sda: 512000 512-byte hdwr sectors (262 MB)

sda: Write Protect is off

 /dev/scsi/host1/bus0/target0/lun0: p1 p2 p3 p4

WARNING: USB Mass Storage data integrity not assured

USB Mass Storage device found at 3

```

Then there is now a sda1,sda2,sda3,sda4. So far things seem to be going ok. Then I do:

```

localmachine root # mount /dev/sda1 /mnt/usbdrive

/dev/sda1: Input/output error

mount: you must specify the filesystem type

```

So then I do:

```

localmachine root # mount -t vfat /dev/sda1 /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda1,

       or too many mounted file systems

```

Does this mean my usbdrive isn't in vfat? I never formatted it, but I did use it in windows and already put some files on there from my windows machine, so I just asssumed it came preformatted. Or maybe it is a different type that both windows and mac can read? Or maybe there is no type at all, and winXP can just do that. I don't know. I also can't use fdisk on it.

I also got rid of the

```

/dev/sda1     /mnt/usbdrive     auto     noauto,user,exec     0 0 

```

line in my /etc/fstab, because nephros never mentioned to do that, so I'm assuming that it is not needed.

So this is where I'm at now. What next?

-KsE

----------

## KsE

Just tried it on a mac at school and it works fine there. So I don't know what file system it's formatted with. Is there any other way to find out besides fdisk?

----------

## KsE

K, found out that the fs type is FAT.

----------

## nephros

 *KsE wrote:*   

> K, found out that the fs type is FAT.

 

... and does it work now?

----------

## AresTheImpaler

 *nephros wrote:*   

>  *KsE wrote:*   K, found out that the fs type is FAT. 
> 
> ... and does it work now?

 

if it doesnt, then do this:

```
cat /proc/filesystems
```

search if it has vfat in the output.. If it doesnt then you need to compile support fo it as a kernel module...

----------

## KsE

No. It didn't work. It's the same as I tried it before.

```

localmachine root # mount -t vfat /dev/sda1 /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda1,

       or too many mounted file systems

```

cat /proc/filesystems gave this

```

localmachine root # cat /proc/filesystems

nodev   rootfs

nodev   bdev

nodev   proc

nodev   sockfs

nodev   futexfs

nodev   tmpfs

nodev   shm

nodev   pipefs

nodev   binfmt_misc

        ext3

nodev   ramfs

        umsdos

        msdos

        vfat

        iso9660

nodev   devfs

nodev   nfs

nodev   autofs

        reiserfs

```

Do I need to edit my /etc/fstab file?

----------

## Liathus

I am having very similar errors.  I am using a 64MB thumb-drive and as far as I can tell have everything in the kernal enabled.   However when I try to mount the drive I get a wrong fs type.  I KNOW the unit is formated in vfat ( i formatted it myself on a windows machine at school).  and I do have the vfat module loaded.  I don't understand why this doesnt work???

----------

## Klonk

With some USB sticks it is possible to create "protected" areas which have a different filesystems, maybe protected.

perhaps you should try to access the other partitions sda2 or so. maybe it's similar to a ZIP-drive that uses partition 4 for saving data under windows.

----------

## KsE

That didn't work either...

```

localmachine root # mount -t vfat /dev/sda4 /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda4,

       or too many mounted file systems

localmachine root # mount -t vfat /dev/sda3 /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda3,

       or too many mounted file systems

localmachine root # mount -t vfat /dev/sda2 /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda2,

       or too many mounted file systems

localmachine root # mount -t vfat /dev/sda1 /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda1,

       or too many mounted file systems

localmachine root # mount -t vfat /dev/sda /mnt/usbdrive

mount: wrong fs type, bad option, bad superblock on /dev/sda,

       or too many mounted file systems

```

----------

## nephros

Hmm, from reading this thread on LKML, it could be those errors are related to a kernel bug in the partition table parsing.

You people having those problems might want to watch this.

----------

## djf_jeff

Try to do 

```

mount /dev/sda /mnt/stick

```

Mine dont have a partition on. So it's sda and not sda1.

I have search a long long time to find this...

----------

## KsE

I've tried doing that...

```

localmachine root # mount -t vfat /dev/sda4 /mnt/usbdrive 

mount: wrong fs type, bad option, bad superblock on /dev/sda4, 

       or too many mounted file systems 

localmachine root # mount -t vfat /dev/sda3 /mnt/usbdrive 

mount: wrong fs type, bad option, bad superblock on /dev/sda3, 

       or too many mounted file systems 

localmachine root # mount -t vfat /dev/sda2 /mnt/usbdrive 

mount: wrong fs type, bad option, bad superblock on /dev/sda2, 

       or too many mounted file systems 

localmachine root # mount -t vfat /dev/sda1 /mnt/usbdrive 

mount: wrong fs type, bad option, bad superblock on /dev/sda1, 

       or too many mounted file systems 

localmachine root # mount -t vfat /dev/sda /mnt/usbdrive 

mount: wrong fs type, bad option, bad superblock on /dev/sda, 

       or too many mounted file systems 

```

None of that works. Plus the output from dmesg gives:

```

hub.c: new USB device 00:07.2-2, assigned address 2 

hub.c: USB hub found 

hub.c: 1 port detected 

hub.c: new USB device 00:07.2-2.1, assigned address 3 

scsi1 : SCSI emulation for USB Mass Storage devices 

  Vendor: JMTek     Model: USBDrive 2.0      Rev: P1.0 

  Type:   Direct-Access                      ANSI SCSI revision: 02 

Attached scsi removable disk sda at scsi1, channel 0, id 0, lun 0 

SCSI device sda: 512000 512-byte hdwr sectors (262 MB) 

sda: Write Protect is off 

/dev/scsi/host1/bus0/target0/lun0: p1 p2 p3 p4 

WARNING: USB Mass Storage data integrity not assured 

USB Mass Storage device found at 3 

```

which suggests that there is sda1, sda1, sda3, sda4. Also sda1-4 appear after the drive is plugged in.

Maybe it has something to do with a kernel bug like nephros said. I don't know, but it's driving me crazy. I set up an ftp server to transfer files right now, but I'd still like to know how to do it, and how to solve this problem regardless if I've found a different way around it.

----------

## jsc1959

This might be a dumb question but are you logged in as root when you are doing this, and do you have a directory under /mnt called usbdrive?

Ive had similar error messages when i was not logged in as root, and or did not have a directory that I was trying to mount.

----------

## wdreinhart

Have you tried mounting it as type msdos instead of vfat?  IIRC, the vfat driver supports only FAT32 filesystems.  Since USB pendrives are so small, they usually use FAT instead of FAT32.  (at least mine does)

----------

## KsE

Yes, I'm using root and the directory is there.

I tried using msdos and had the same problem, I also tried using umsdos, and that didn't work either.

----------

## dargosch

Jumping into the debate well after it's died..

I find that I have to do a 

```
eject /dev/sdb1

```

after unmounting the drive in order to not destroy the filesystem on it..

The downside is that I have to do a 

```

kill -HUP `pidof devfsd`

```

after that in order to get the device back again when re-insert it in the same session.

----------

## KsE

My problem is I can't get the device to work in the first place. I can't mount it if for use and I've pretty much given up..... I'm starting to think it's my brand. But it does work on MacOSX. So I think it should work fine in linux.

----------

