Monday 14 May 2007

Configuration to mount usb memory sticks

Today I'll explain how to configure the system to mount a usb memory stick so we can read and write from an user account, instead of just from the root account.

I have now two computers running PCLinuxOS, one with a HD installation (my old PII 300Mhz) and one with the LiveUSB instalation (the not so old PIV Dual Core 3GHz). As I have been working on the PII before I completed the installation and configuration of the LiveUSB, I wanted to transfer all my work (including Thunderbird mails and folders) to the LiveUSB so I could use it in the PIV.

But then I run into trouble when connecting the USB memory stick to the old PII. First, although I could mount and see and write to the USB memory from user root, when I was logged as other user i suffered different problems, from not been able to mount the usb memory stick, to been able to mount it but not read, or been able to read but not write. This different combination of problems were happening as I was changing configurations trying to fix the problem.

If you have run into this problem, you might have tried to put in the /etc/fstab file an entry for the usb device. I did that but it is not a good idea because it locks the usb mounting point to a particular usb drive "letter" and number, so DON'T do something like "/dev/sda1 /mnt/usb vfat defaults 0 0".

As I was googling and learning, I found that there is a special file system for usb that precisely provides the functionality to make the usb file systems mount automaticall without the need to indicate a specific device name and mount point.

In the /etc/fstab file there is already an entry to provide this functionality, which is:
none /proc/bus/usb usbfs defaults 0 0

But that entry was not good enough for me because I could mount and read the two partitions in my USB memory stick (one vfat and the other ext2), but I could not write to them (at least not to the ext2 because the truth is that I didn't try to write to the vfat).

So googling a bit more I learnt the options that I could use in fstab and after a few trials I found the combination that allowed me to write to the usb memory stick with my standard user. What I did was to replace the line mentioned about from the /etc/fstab with the line:
none /proc/bus/usb usbfs dev,suid,user,rw 0 0

Be careful because I believe that the order of the options is important, for example if you put the "dev" option after the user and rw options I believe it overrides them and set it back to nouser (only root can mount) and ro (read only).

With that modified fstab, I re-inserted the usb memory stick and I was able to write with my standard account. Also, if I issue a "mount" command from a root terminal window I get the following for my usb memory stick:

/dev/sda1 on /media/usb type vfat (rw,nosuid,nodev,sync,uhelper=hal,flush,uid=501,utf8,shortname=lower)

/dev/sda2 on /media/disk type ext3 (rw,nosuid,nodev,sync,uhelper=hal,data=ordered)

Which initially looks correct to me.

These guidelines, I believe, will be also useful to anyone connecting through USB a storage device, like for example a external USB HD.

It it was useful to you this post, please send me a comment or link to it.

3 comments:

Unknown said...

Thank you for your blog on PCLinuxOS!
I was needing inof regarding SB on TinyME. Yours was the first to use the none /proc/bus/usb.. in fstab.

I will try it and see if it works.

Some good stuff here!

Anonymous said...

Thanks, found this very helpful.

Anonymous said...

Great help