# /dev/sda1 disappears, usb memory stick problem

## cesar

I have two usb flash memory sticks.  Each one is 512 MB but they are from different brands (one is Xiao and the other JetFlash).

I have the following line in my /etc/fstab

```

/dev/sda1    /mnt/usbfs      vfat       user,noauto,nosuid     0 0

```

When I attach one of the memory sticks to the usb port and I use the command as user "cesar"

```

mount /mnt/usbfs

```

I can see the list of the files as it should be expected.  However, after I unmount and insert the other memory stick, when I type

```

mount /mnt/usbfs

```

I get this message

```

mount:  /dev/sda1 is not a valid block device

```

To make things worse, if I try again the first memory stick, it cannot be mounted and I get this error

```

mount: special device /dev/sda1 does not exist

```

I have checked the /dev/sda* and this is what it looks like right after I boot

lr-xr-xr-x    /dev/sda -> scsi/host0/bus0/target0/lun0/disc

lr-xr-xr-x    /dev/sda1 -> scsi/host0/bus0/target0/lun0/part1

then, after that problem appears, this is what it looks like

lr-xr-xr-x    /dev/sda -> scsi/host0/bus0/target0/lun0/disc

In fact /dev/sda1 has disappeared and I have not idea why.  How can that link disappear if I mount/unmount the device as user "cesar" not as root.  Can anyone please help me to figure out what's going on?  Is the problem related to the /etc/fstab file?

----------

## cesar

Searching the internet I noticed that using

```

cat /proc/scsi/scsi

```

gave me the following output

```

Attached devices: 

Host: scsi0 Channel: 00 Id: 00 Lun: 00

  Vendor:          Model: X.i.a.o          Rev: 1.13

  Type:   Direct-Access                    ANSI SCSI revision: 02

Host: scsi1 Channel: 00 Id: 00 Lun: 00

  Vendor:          Model: TS512MJFLASHA    Rev: 1.00

  Type:   Direct-Access                    ANSI SCSI revision: 02

```

According to that, /dev/sda1 is assigned to memory stick "Xiao" while /dev/sdb1 to "TS512MJFLASHA" one.

Does this mean that I cannot make a 'generic' line for /etc/fstab file?  For example, if today I mounted TS512MJFLASHA first and then unmounted it, then /dev/sda1 would be pointing to that device instead of pointing to Xiao.

Each time I would have to check /proc/scsi/scsi to figure out which device corresponds to which memory stick  :Sad: 

----------

## Carlo

 *cesar wrote:*   

> Does this mean that I cannot make a 'generic' line for /etc/fstab file?

 

Either via LABEL or UUID.  :Arrow:  man fstab

Carlo

----------

## cesar

 *Carlo wrote:*   

> 
> 
> Either via LABEL or UUID.  man fstab
> 
> Carlo

 

Thank you for your reply Carlo, but as far as I have read in internet after you suggested the use of LABEL, it seemed that it should work if the device were formated with ext2, ext3, or xfs.  My two memory sticks are vfat.  I use them for sharing files with Windows machines.

I'd also like to know why after I unmount, let's say the Xiao stick, it appears still listed in the /proc/scsi/scsi list of attached devices.  It's like the system keeps memory of what it was attached in /dev/sda1 and only Xiao stick can use that link even when nothing is mounted.  As I said, if I use the TS512MJFLASHA device using /dev/sda1, the link is deleted and I get error.

----------

## Carlo

 *cesar wrote:*   

> it seemed that it should work if the device were formated with ext2, ext3, or xfs.  My two memory sticks are vfat.  I use them for sharing files with Windows machines.

 

May I proof you wrong!? Merge sys-apps/util-linux-2.12-r4 and you should be fine.  :Wink: 

edit:

About your other problem. Do you have the hotplug rc script added to your preferred runlevel? Configured /etc/conf.d/usb? Maybe having a look at /etc/hotplug/!? I have to admit, that I'm too lazy to do this. Plugging in such a stick should just work.  :Twisted Evil: 

Carlo

----------

## cesar

Well, I'm feeling bad already for asking, but I think I'm missing something pretty basic here.

This is what I did,

```

ACCEPT_KEYWORDS="~x86" emerge util-linux

```

After that I changed the /etc/fstab and included this line

```

LABEL=USB_STICK    /mnt/usbfs   vfat   noauto,users,noatime,sync   0 0

```

Then I rebooted the computer.

Now, as user "cesar" I put the Xiao stick and 

```

mount /mnt/usbfs

mount: no such partition found

```

This is the ouptput of

```

mount -l

/dev/root  on / type reiserfs (rw,noatime)

none on /proc type proc (rw)

none on /dev type devfs (rw)

none on /dev/shm type tmpfs (rw)

none on /proc/bus/usb type usbfs (rw)

```

I'm using LABEL=USB_STICK from the bug report, but probably this is something I should change by myself?  How do I use mlabel?  I've emerged mtools and tried a similar command like the one in the bug report , but how, I just keep getting

```

mlabel -v /dev/sda1:USB_STICK

Mtools version pre6-3.9.8, dated 27 May 2001

Usage: mlabel [-vscVn] [-N serial] drive:

```

I have tried mounting and unmounting the device before using mlabel.  I have also tried mlabel -vs /mnt/usbfs:USB_STICK and don't know what else to do.

It doesn't matter what I type "mlabel" does not seem to set the label.  I know this is pretty stupid to ask, but would you just give me an example.  Is the [drive] in this case /dev/sda1 or is it /mnt/usbfs.  Should it be mounted or not for setting the label?  Please help me.

----------

## Carlo

Right, mlabel doesn't work. Fortunately, the single usb stick which I call my own, was labeled by the manufacturer. blkid lists your devices, its labels and uuids.

Carlo

----------

## cesar

 *Carlo wrote:*   

> Right, mlabel doesn't work. Fortunately, the single usb stick which I call my own, was labeled by the manufacturer. blkid lists your devices, its labels and uuids.
> 
> Carlo

 

Wow.  I'm glad it was not my problem.  I was getting very frustrated with mlabel.

I have tried blkid and this is the output for Xiao:

```

/dev/sda1:  UUID="1CE4-0F4D"  TYPE="msdos"

```

and for TS512MJETFLASHA:

```

/dev/sdb1:  UUID="F80B-41FD"  TYPE="vfat"

```

So I guess what is left is to put those specification in my fstab.  I have tried the following,

```

UUID=1CE4-0F4D   /mnt/usb1    vfat  noauto,users,noatime,sync      0 0

UUID=F80B-41FD    /mnt/usb2    vfat  noauto,users,noatime,sync      0 0

```

but it gives me this error

```

mount /mnt/usb1

mount: bad UUID

```

I have tried putting "" arount the UUID names, but still I get the same error.  Is the syntax for UUID different from what I've written?

----------

## mb

fyi,

https://bugs.gentoo.org/show_bug.cgi?id=36722

i found a patch for mount to read the LABEL information from fat/vfat formatted media.

hth,

#mb

----------

## Carlo

@mb: That's why I suggested sys-apps/util-linux-2.12-r4. But it doesn't make mlabel (writing a label) work.

@cesar: Just tested it. The uuid of my usb-stick is 0000-0000 and it gives me the same error. 

Interesting enough, the patch uses the serial number to create the uuid - but only if there is no label given. I don't know what the problem is, but the uuid is usually 16 byte long and this piece of code creates a 4 byte uuid and fills the rest with zeros.

Carlo

----------

## cesar

 *Carlo wrote:*   

> 
> 
> I don't know what the problem is, but the uuid is usually 16 byte long and this piece of code creates a 4 byte uuid and fills the rest with zeros.
> 
> Carlo

 

I noticed that the UUID numbers from different samples I found in internet (not many BTW) were significantly larger than the ones I got from using blkid.  I thought that probably different devices would have different numbers, but since you experienced the same problem, then it must have to do with blkid itself.

Well, tomorrow I'll join you again.  Now I have to catch up some sleep.  Thanks for all your help guys.

----------

## Carlo

@cesar: Nope, have a look at the patch. blkid shows the correct uuids. You may have seen different representations of uuids.

edit: Problem solved. Don't use mlabel, but mkdosfs -n instead.

Carlo

----------

## cesar

 *Carlo wrote:*   

> @cesar: Nope, have a look at the patch. blkid shows the correct uuids. You may have seen different representations of uuids.
> 
> edit: Problem solved. Don't use mlabel, but mkdosfs -n instead.
> 
> Carlo

 

I've taken a look at the man blkid and decided not to give any options to it and this is the output.

```

/dev/ide/host0/bus0/target0/lun0/part1: LABEL="IBM_PRELOAD" UUID="3F3F-14F0" TYPE="vfat" 

/dev/ide/host0/bus0/target0/lun0/part2: UUID="6e998536-a856-4a26-b10b-4e9732a6d256" SEC_TYPE="ext3" TYPE="ext2" 

/dev/ide/host0/bus0/target0/lun0/part3: UUID="5d20b939-4565-4001-910b-d74a8a90c030" TYPE="reiserfs" 

/dev/ide/host0/bus0/target0/lun0/part5: TYPE="swap" 

/dev/sda1: UUID="F80B-41FD" TYPE="vfat" 

```

Interesting, my windows partition also shows a shorter UUID than the linux partitions.  If the correct UUID for my memory stick is the one shown there, why then I cannot mount it just typing

```

mount /mnt/usb2

mount: bad UUID

```

This is my /etc/fstab

```

/dev/hda2      /boot      ext3      noauto,noatime      1 2

/dev/hda3      /      reiserfs   noatime         0 1

/dev/hda5      none      swap      sw         0 0

/dev/cdroms/cdrom0   /mnt/cdrom   iso9660      noauto,ro      0 0

UUID=1CE4-0F4D          /mnt/usb1       vfat            noauto,users,noatime,sync      0 0

UUID=F80B-41FD          /mnt/usb2       vfat            noauto,users,noatime,sync      0 0

/dev/hda1              /mnt/win         vfat            user,noauto,nosuid      0 0

# NOTE: The next line is critical for boot!

none         /proc      proc      defaults      0 0

none         /dev/shm   tmpfs      defaults      0 0

```

And here is my lsmod in case I'm missing something.  BTW I'm using gentoo-sources-2.4.22-r2.

```

Module                  Size  Used by    Not tainted

nls_iso8859-1           2812   0  (autoclean)

nls_cp437               4316   0  (autoclean)

vfat                   10092   0  (autoclean)

fat                    31064   0  (autoclean) [vfat]

floppy                 49596   0  (autoclean)

usb-storage            62016   0 

radeon                107464  14 

agpgart                37184   3  (autoclean)

hid                    14568   0  (unused)

uhci                   24752   0  (unused)

i810_audio             23880   1 

ac97_codec             12968   0  [i810_audio]

soundcore               3716   2  [i810_audio]

eepro100               19348   1 

mii                     2512   0  [eepro100]

serial                 47044   0  (autoclean) (unused)

isa-pnp                29956   0  (autoclean) [serial]

parport_pc             26920   1  (autoclean)

lp                      6240   0  (autoclean)

parport                25120   1  (autoclean) [parport_pc lp]

usbcore                60480   1  [usb-storage hid uhci]

apm                     9640   1 

```

----------

## Carlo

 *cesar wrote:*   

> my windows partition also shows a shorter UUID than the linux partitions.

 

It's not a question of the tools you are using, but of the limitations of these old filesystem, which doesn't provide much metadata (or place to store it). One could create a workaround for it, one could just disable the check for the uuid length (and try to ensure, that "short uuids" don't break other programs...), but all this doesn't make much sense for this crappy old fs.

Just use mkdosfs -n yourlabel /dev/<sdX> and forget the uuids.  :Smile: 

Carlo

----------

## cesar

 *Carlo wrote:*   

> 
> 
> Just use mkdosfs -n yourlabel /dev/<sdX> and forget the uuids. 
> 
> Carlo

 

Thank you very much Carlo for all your help.  Here's what happened.

I did format the two memory sticks and put them a new label.  Then I put these two lines in the fstab

```

LABEL=mem-flash     /mnt/usb1   vfat   noauto,user,noatime,sync      0 0

LABEL=mem-xiao     /mnt/usb2   vfat   noauto,user,noatime,sync      0 0

```

Now, after rebooting I see this in

```

ls -l /dev/sd*

lr -xr -xr -x    1  root   root   34 Jan 4 14:19  /dev/sda1 -> scsi/host0/bus0/target0/lun0/part1

```

and then I typed

```

mount /mnt/usb2

```

and it worked OK, no problem.  Then I unmounted it

```

umount /mnt/usb2

```

I checked the following

```

cat /proc/scsi/scsi

Attached devices: 

Host: scsi0 Channel: 00 Id: 00 Lun: 00

  Vendor:          Model: X.i.a.o          Rev: 1.13

  Type:   Direct-Access                    ANSI SCSI revision: 02

```

and still don't know why it shows the devices even though I have unmounted it.  Anyway, next I mounted the other one

```

mount /mnt/usb1

```

and it worked.  Now this is shown in

```

ls -l /dev/sd*

lr-xr-xr-x    1 root     root     33 Jan  4 14:25 /dev/sda -> scsi/host0/bus0/target0/lun0/disc

lr-xr-xr-x    1 root     root     33 Jan  4 14:29 /dev/sdb -> scsi/host1/bus0/target0/lun0/disc

lr-xr-xr-x    1 root     root     34 Jan  4 14:29 /dev/sdb1 -> scsi/host1/bus0/target0/lun0/part1

```

Notice that the previous link /dev/sda1 is now missing.

Then I unmounted it

```

umount /mnt/usb1

```

Now here comes the problem, if I reinsert the first one then

```

mount /mnt/usb2

mount: no such partition found

```

Of course, /dev/sda1 is missing  :Sad:  I don't know why /proc/scsi/scsi keeps memory of the devices after they have been removed  :Crying or Very sad:   I cannot even remove that file as root!

----------

## Carlo

 *cesar wrote:*   

> 
> 
> and still don't know why it shows the devices even though I have unmounted it.  Anyway, next I mounted the other one

 

I can only quote myself:

 *Carlo wrote:*   

> About your other problem. Do you have the hotplug rc script added to your preferred runlevel? Configured /etc/conf.d/usb? Maybe having a look at /etc/hotplug/!? I have to admit, that I'm too lazy to do this. Plugging in such a stick should just work. 

 

```

mount /mnt/usb2

mount: no such partition found

```

Search bugs.g.o. for hotplug. 

Really, I woudn't dig deeper into this. Maybe it's getting better witch the change from devfs to udev. Right now it's a mess.

Carlo

----------

## mb

@Carlo & others

hmm.. i had no problems with mlabel... (Mtools version pre6-3.9.8, dated 27 May 2001)

```

# mlabel -s c:

 Volume label is USB_STICK

# mlabel c:

 Volume label is USB_STICK

Enter the new volume label : test123

# mlabel -s c:

 Volume label is TEST123

```

hth,

#mb

----------

## cesar

 *Carlo wrote:*   

> 
> 
> I can only quote myself:
> 
>  *Carlo wrote:*   About your other problem. Do you have the hotplug rc script added to your preferred runlevel? Configured /etc/conf.d/usb? Maybe having a look at /etc/hotplug/!? I have to admit, that I'm too lazy to do this. Plugging in such a stick should just work.  
> ...

 

I followed the installation guide.  I did,

```

rc-update add hotplug default

```

Here's what's in my /etc/conf.d/usb

```

more /etc/conf.d/usb

# If you have a USB mouse, you probably want to enable the following,

# and change your XFree86 configuration so that it uses /dev/input/mice

# as the mouse input device

#X11_USBMICE_HACK=true

# Put any modules here that you want to be loaded by the USB hotplug system

#STATIC_MODULE_LIST=

```

The memory sticks work just fine.  The problem is that I must always remember to which /dev/sd? they have beem mapped by the system,  otherwise I would get errors and missing links.  Unfortunately, the use of LABEL did not solve my problem.

It all started because under KDE I made an icon to mount (just by mouse click) /dev/sda1 to /mnt/usbfs.  It failed, of course, when I tried a different memory stick (because now the link was /dev/sdb1).  Anyway, I'll just take a look at /proc/scsi/scsi file each time before using usb.

Thank you guys for all your help.

----------

## cesar

Hello everyone:

If you have been following this thread and were wondering about similar problems with usb, you'll find this script helpful  https://forums.gentoo.org/viewtopic.php?t=53537&start=83

It's working for me.

----------

## mog

well I had the same problem and uncautiously created a new dir /dev/sda1 without realizing that it would not be a block device   :Embarassed:   ... this of course did not work ... so I deleted it again, but now everytime I reboot /dev/sda1 gets recreated as a directory with a set of permissions quite different to the remaining /dev/sdaX block devices ...   :Shocked:   ... HELP ... how can I recreate the /dev/sda1 block device ???

----------

## Peach

I'm asking me the reason noone of you ever tried to use sd_mod (whether as a module or built in the kernel) this module should be the responsible of creating such decices (I had a similar problem with my usbstick: I had only to enable sd_mod and usb-storage for everything to work properly)

there's also a nice how-to for usb mass storage devices under section Tips&Tricks... 

hope this can help someone...

----------

## mog

 *Quote:*   

> I had only to enable sd_mod and usb-storage for everything to work properly)

 

you are refering to including support in the kernel for usb mass storage devices. This is not the issue here as the device is correctly found at 

/dev/scsi/host0/bus0/target0/lun0/disc (as also stated in the first post   :Wink:  )

which implies that the kernel is correctly configured for that

The initial problem is that the /dev/sda link to the actual device disappears.  And in my case the additional complication is that I deleted and recreated the /dev/sda1 and now it does not get recreated properly on startup. 

 *Quote:*   

> there's also a nice how-to for usb mass storage devices under section Tips&Tricks... 

 

would be nice if you could post the link as well   :Smile: 

----------

## mog

well I have another weird thing happening with the usb drive. I just finished installing gentoo on my machine at university and I am positive about having included support for usb mass storage devices and scsi. 

now the problem is that 

dev/scsi/host0/bus0/target0/lun0/part1

is mountable and I can access it, but the /dev/sda and /dev/sdaX are never created. What exactly is responsible for creating those devices/links? Any constructive help is appreciated.

----------

## hulk2nd

i also have a problem with my sony memory stick (which is compatible to an usb memory stick): there is only one partition on it, so it is /dev/sda1. the strange thing is, i have to mount /dev/sda. of course i can't read something from that, so i have to umount it again and only after this procedure, /dev/sda1 appears. i dont know why, but i have to do this procedure everytime i reboot. after i did that once, everything just works fine and i can mount/umount and read/write to sda1 just as i want ...

greets,

hulk

----------

## Peach

 *mog wrote:*   

>  *Quote:*   there's also a nice how-to for usb mass storage devices under section Tips&Tricks...  
> 
> would be nice if you could post the link as well  

 

here it is :

https://forums.gentoo.org/viewtopic.php?t=53537&highlight=usb+storage+how+to

----------

## kormoc

DeletedLast edited by kormoc on Mon Dec 24, 2018 9:20 am; edited 1 time in total

----------

## mog

well I don't seem to have fsck.vfat how can I get it? ... sorry if this is a moron question, but since there is nothing like vfat-utils in portage how can I get that app?

----------

## hulk2nd

its in dosfstools, i think. but btw, it did not help in my case  :Confused: 

greets,

hulk

----------

## shardis

Pretty much anything acting on /dev/sda seems to recreate /dev/sda1 for me, allowing my "mount /mnt/usbpen" to work right off.  "touch /dev/sda" will do it even.

There any solutions to getting this to work automagically?

----------

## jetcowbob

Ok,   here is a new problem for ya'll...

I have more than one USB flash device.  No matter what order i plug them in, the first one plugged in always goes to either /dev/sda or /dev/sda1 (which depends on whether or not it is the one with a partition table or not)

and the second device goes to /dev/sdb1 or /dev/sdb.....

so, thing is, one of them is a digital camera, the other a USB flash stick.  If I go and make my fstab so it has a /dev/sda  mapped to /mnt/usbpen and a /dev/sdb mapped to /mnt/usbpen, only the first one listed will work,  ie mount only looks at the first /fstab entry for /mnt/usbpen   I could mount based upon the device, but ideally, i dont want to worry about whether or not i have the other device plugged in etc.

SO i looked in man fstab and found this nifty feature that lets me mount based upon UUID of the device so i could put a UUID entry and map it to the mount point i want to type to mount with. (ie mount /mnt/usbpen or /mnt/camera)   

Unfortuneately this doesnt work....  i read another thread where they had problems with this and nobody seemed to have a solution. 

SOOoooo, i guess my primary question is this:

How do I go about putting an entry for /mnt/camera and /mnt/usbpen in my fstab so that I dont have to worry about  the order they are plugged in order to mount them?

----------

## Mord

Regarding this problem where you plug in your USB stick, use it, remove it, plug it in again and can't mount it anymore:

I used sudo to allow my users to run "touch /dev/sda", which seems to knock some sense into devfs and give us back /dev/sda1 so that we can still remount USB drives without rebooting.  Heck, you could probably even script it such that /dev/sda is touched whenever a new storage device is plugged in.  But really.

I mean, come ON!!!!  Why should we go to UDEV just because someone won't fix this?  Oh thats right, this whole thing with the scsi subsystem and /dev/sda is probably doing exactly what its supposed to, the canned answer, that this is our problem, our fault.  Whatever.  This is just another example of exactly the kind of thing that keeps linux harder to use than windows.  I'd love to be able to look at a few lines of code and fix this for everyone, but this kind of stuff is a bit beyond me.  Thank god for these forums where I can actually find information on some of the weird problems I encounter.

Anyway, after scouring this forum, the above solution is what I'm doing for the time being.  I've got nothing against udev (except that it seems awfully complex), but I'm not moving to it until its standard issue.

----------

## Carlo

 *Mord wrote:*   

> Why should we go to UDEV just because someone won't fix this?

 

Because devfsd has fundamental flaws and isn't maintained anymore.

 :Arrow:  http://www.us.kernel.org/pub/linux/utils/kernel/hotplug/udev_vs_devfs

----------

## Mord

That's fine.  I said later in my post that once it becomes standard issue, I'll stop complaining.

But I mean, look at the work around.  Touching /dev/sda and problems go away.  Seems so trivial, and yet its an inconvenience.

EDIT:  Anyway, I'm not trying to start anything.  My little rant was the result of a lot of struggling with my own usb storage device before I finally got it working.  And now that its working, even with the "touch" workaround, I do not relish the thought of now upgrading my device subsystem and possibly screw up something else in my little house of cards I like to call a laptop.

----------

