LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   usb flash drive (https://www.linuxquestions.org/questions/linux-hardware-18/usb-flash-drive-73359/)

tyiooo 07-16-2003 05:04 PM

usb flash drive
 
Hello,

I just bought a pendrive mp3 player usb with 128Mo, I tried to plug it in with redhat 9, everything is working perfectly well. I just had to mount /dev/sda1
so here's what I did:

mkdir /mnt/pendrive
mount -t msdos -o rw /dev/sda1 /mnt/pendrive

But now, my only problem is I didn't understand how to set the permissions with mount. I'm able to write to /mnt/pendrive only when I'm root. How can I easily read and write my pendrive under my user account?

Thanks for your help!

Bye

tyiooo

michaelk 07-16-2003 05:55 PM

Its the same thing as read / write permissions on a vfat i.e. fat32 partition.

There are tons of posts on the site you can search for on the above subject.

Hint: You want to add an entry to your /etc/fstab file and use the options noauto and umask=000.

tyiooo 07-17-2003 04:45 AM

I know and I searched a lot but what works for others didn't necessarily worked for me.

I succeeded in mounting the device under root permission, I succeeded to have the device read/write for the user only when I start redhat with the flash drive already plugged in.

What I really want is to be able to hotplug it under my user account anytime I want then to be able to modify its content with read and write permissions.

In /etc/fstab I tried :

/dev/sda1 /mnt/pendrive auto defaults 0 0

/dev/sda1 /mnt/pendrive auto noauto,owner,user 0 0

/dev/sda1 /mnt/pendrive msdos user,kudzu 0 0

/dev/sda1 /mnt/pendrive msdos umask=000,defaults 0 0

/dev/sda1 /mnt/pendrive auto noauto,owner,kudzu,ro 0 0

/dev/sda1 /mnt/pendrive auto noauto,owner,user,kudzu,ro 0 0

/dev/sda1 /mnt/pendrive auto noauto,user,kudzu,ro 0 0

And so on and so on ...and nothing worked...

tyiooo 07-17-2003 04:54 AM

OKAY !!! I'm posting the good combination :

in /etc/fstab :

/dev/sda1 /mnt/pendrive auto noauto,owner,user 0 0


I can hotplug it whenever I want , there's even an icon appearing on my desktop with redhat 9 !

tyiooo 07-17-2003 05:18 AM

false alarm
 
Well I was so glad to make it work then really disappointed :

I can delete or copy files only once... after it says "generic error - cannot delete" or when I try to copy it says "disk is full" although it is empty.

So I tried to umount /mnt/pendrive but it says "device is busy" although it is not.

A lot of "ALTHOUGH" , this is a total nonsense .

Thanks for your help.

note : the pendrive is totally standard, it doesn't need any driver to be loaded, everything is ok under Win2K but I try to get rid of windows little by little so I absolutely have to be able to do this with redhat 9.

michaelk 07-17-2003 11:07 AM

I don't use hotplug but this might help.

http://www.linuxquestions.org/questi...+drive+hotplug

Adding the umask option will allow all users to read / write:

/dev/sda1 /mnt/pendrive auto noauto,owner,user,umask=000 0 0

tyiooo 07-18-2003 06:24 AM

okay thanks for your help, I'll try with umask

the thread you're talking about is very useful even if it doesn't give a lot of informations. I know at least where to search now (hotplug service).

I thought this was so simple to do in linux..I was so wrong. there's a lot of configuration to do for this device to work as it is designed to be used. I mean it is supposed to be plugged then immidiately usable by the user who could then be able to write erase data on the key without mounting/umounting each time.

So if you don't use hotplug, then you just added the appropriate line in /etc/fstab with umask and you mount/umount each time you want to add/erase files ?

plehman 07-18-2003 07:18 AM

Hi,

I was the one asking about hotplug in the referenced thread, but I guess I forgot to post the resolution, and maybe it will help you:

In short, to get hotplug working (at least for me), I had to create a file called 'usb-storage.add' located in the '/etc/hotplug/usb' directory. That file had to look something like this:

#!/bin/bash
DEV=/dev/sda1
MNTPOINT=/mnt/flashdrive
mount -t vfat $DEV $MNTPOINT
cat <<END> $REMOVER
umount $MNTPOINT
END
chmod +x $REMOVER

Obviously, the DEV and MNTPOINT variables should be changed to fit your device. I'm still not completely sure what all it does, but my understanding is that the hotplug service will run this file when a USB storage device is added, and handle the mounting. The part starting with cat, I am not completly sure what it does, and I am still investigating that.

Next, you have to add a function to the '/etc/hotplug/hotplug.functions' file as follows. Note that I placed this at the end (between the last 'fi' and before 'done') of the file.

if [ -x $HOTPLUG_DIR/$TYPE/$MODULE.add ]: then
debug_mesg Module setup.add $MODULE for $DESCRIPTION
$HOTPLUG_DIR/$TYPE/$MODULE.add
fi

The assumption here is that when a new device is added, and hotplug detects the <device-type>.add file in the <type> directory, it will run that script.

Now, concerning the problem where you cannot umount the device because it says "device is busy"...

Assuming you are using RH, this is likely due to the fact that a service called 'fam' is still running, and hence you cannot umount the device because some program is still using it. This is apparently a bug in the Nautilus filemanager, documented on RedHat's Bugzilla site.

fam stands for File Alteration Monitor, and it monitors changes made to filesystems. Most likely you cannot umount the device because this service didn't exit quietly. To my knowledge, there is no patch for this problem yet.

The only workaround I know of now is to kill the process for fam, and then umount the drive. I'm sure someone could write a script or something, and then add it to 'hotplug.functions' file so its autmatically run on removal.

Hope that helps.

tyiooo 07-18-2003 09:21 AM

hello! Thanks a lot for posting the resolution I was about to write you an e-mail :D

I created the file usb-storage.add changing the DEV and MNTPOINT variables to fit my device.
I also added the function in the '/etc/hotplug/hotplug.functions' file

After a reboot, I plugged in my device and nothing happened this time (usually the usb storage is detected then I can mount it) . I thought it doesn't work so I tried to mount it manually as I've done it before but now it says "non-valid block peripheric".

I think I missed something :

I just copied the function to add in the '/etc/hotplug/hotplug.functions' did I have to modify some variables to fit my system ?
Quote:

The assumption here is that when a new device is added, and hotplug detects the <device-type>.add file in the <type> directory, it will run that script.
Did you mean I have to replace some variables by my <device-type> in the hotplug.functions file ?

Another question : After these changes, how does your '/etc/fstab' looks like?

I really appreciate your help, thank you once again!

plehman 07-18-2003 09:53 AM

Hi,

Sorry it didn't work for you first try out. The file data I provided was from my USB Flash Drive (a Lexar 64MB JumpDrive), and as I am still pretty new to linux, I would have to assume that the '-t vfat' part of the mount command in usb-storage.add is what might be causing the 'non-valid block peripherlc' message.

What I meant by <device-type>.add in the <type> directory was this.

under '/etc/hotplug', I have a directory (RH made it) called 'USB'. USB is what I intended to be <type>.

Under the 'USB' directory, RH has a file for USB cameras (even though I never hooked one up) called 'usbcam'. Thus, when I was told to make a file called usb-storage.add', I assumed that hotplug needs a .add file or something of that nature to tell it how to handle various types of USB or other devices. So 'usb-storage' was the <device-type> I was referring to.

Presumably, though this has not been verified, hotplug could also be used for say removable hard-drives, pci/pcmcia periherals, optical media, or maybe even smart cards.

as far as my '/etc/fstab' file goes, here it is:

LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/hda6 swap swap defaults 0 0
/dev/sda1 /mnt/flash vfat noauto,user,rw 0 0
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0

Not to confuse this any further, but I should note that in order to get an icon to appear on the desktop (I am using GNOME), I also had to add a line to '/etc/auto.misc' as follows:

flash -fstype=vfat :/dev/sda1

I got this idea from trying to determine how cd-roms got automounted, and got indications this was needed from 'man automount' and man 'auto.master', though this may not be needed since I now have hotplug functioning.

I don't know how much more help I can be, but if you would like to email me directly, please feel free to do so at plehman@siceltech.com.

toblo 07-31-2003 03:50 AM

Anybody knows how to do this in Mandrake 9.1? I can't find /dev/sda1. Thanks.

mobileMike 08-09-2003 01:05 AM

This is what I did to get my flash drive working with Redhat 9.

http://www.connecteduser.com/forum/v....php?p=250#250

I show 3 methods: direct mounting, fstab, and hotplug

- mike


All times are GMT -5. The time now is 09:52 PM.