Problems with udev & mounting fat32 usb storage


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Problems with udev & mounting fat32 usb storage
# 1  
Old 04-04-2011
Problems with udev & mounting fat32 usb storage

I have been trying to get USB storage devices to auto-mount themselves under "/media/usb/<dev>" but have been running into some problems with udev (on FC7, btw... running udevd v.106)

Every time I put in a FAT (not 32) USB stick, udev identifies it as "USB storage", identifies the partition and calls it "/dev/sdb1", triggers my rule to create a dev-alias of "/dev/sdb1" to something like "/dev/usb-sdb1", and triggers my other rule to run a "safely mount/unmount" script on that dev-alias.

The problem is when I try to use FAT32. I never get more than a "SCSI Generic" detection, thus never get a "sdb1"... in other words, it looks like FC7/udev cant identify that there is a valid partition there? The problem I have with this is that it kills the auto-mounting. I dont care if there is a dev-node for the partition itself, but if I cannot detect this situation, then I cant run the subsequent mount on "/dev/sdb" for example (which does actually work)

Is there some kind of Kernel USB/FAT32 options that need to be used for this to work? Or am I doing something stupid?

BTW - I will try to get udevmonitor output, but I don't own the machine
# 2  
Old 04-04-2011
Some manufacturers have obnoxiously preformatted their flash drives with no boot sector whatsoever, the FAT32 partition begins right at sector zero like an old-fashioned floppy disk -- meaning the disk, /dev/sdb, does what you'd normally expect the partition to do. There's no /dev/sdb1, you must mount /dev/sdb!

When I encounter a flash drive laid out like that I usually fdisk and reformat it.
# 3  
Old 04-05-2011
MySQL

Believe it or not, you have helped me significantly.

I admit my udev rules relied heavily on a "USB-Storage" partition existing:
Code:
ACTION=="add", KERNEL=="sd*[0-9]", DRIVERS=="usb-storage",  SYMLINK="usb/%k"
ACTION=="add", KERNEL=="sd*[0-9]", DRIVERS=="usb-storage", RUN+="/bin/mkdir -p /media/usb/%k"
ACTION=="add", KERNEL=="sd*[0-9]", DRIVERS=="usb-storage", RUN+="/bin/mount /dev/%k /media/usb/%k -o sync", OPTIONS="last_rule"

However, if I tried to change them to use the base Kernel name, then all partitioned USB drives were failing... vice versa, when using the partition...

So what I did was push this identification into a script called "usbplug" which does the mkdir, tests if the mount succeeds, and does the rm on an empty dir if necessary after failed mount attempt. This way I can try to mount "/dev/sdc" for a partitioned drive, it will fail, and nobody really cares. But additionally, "/dev/sdb" (a FAT32 non-partitioned disk) will work, as will "/dev/sdc1" (a FAT16 partitioned disk).

Now my rules look like the following (and yes, I got a bit carried away and added an auto-run option):
Code:
# Auto-mount USB storage (on add):
ACTION=="add", KERNEL=="sd*", DRIVERS=="usb-storage", NAME="usb-%k", SYMLINK="usb/%k"
ACTION=="add", KERNEL=="sd*", DRIVERS=="usb-storage", RUN+="/etc/udev/scripts/usbplug --mount /dev/usb-%k /media/usb/%k"
ACTION=="add", KERNEL=="sd*", DRIVERS=="usb-storage", RUN+="/etc/udev/scripts/usbplug --autorun /dev/usb-%k", OPTIONS="last_rule"

You will also note that the rule now uses a "NAME" to insure that all USB mounts are grep-able simply with "mount | grep -i usb"... this helps the script avoid looking at my OS partitions (var, root, etc).

Fun stuff.

I wonder why they can get away without a partition table altogether... seems wrong.
# 4  
Old 04-06-2011
two three four reasons.

1) History. FAT is capable of doing this because this is how floppy disks were formatted.
2) Windows tolerates it for reason #1.
3) It may be simpler for standalone things to understand. (I have a flash drive with references to "Flash Disk Tester 2.0" still left in it somewhere from the factory.) Perhaps also easier for a BIOS to boot from. (There are LOTS of very broken USB boot BIOSes out there.)
4) Windows is, or was, terrible at handling partitions on removable drives. I haven't checked lately but it used to be that any partitions beyond the first were ignored. When it does that why bother having a partition table at all?

Last edited by Corona688; 04-06-2011 at 11:12 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fixed mount point for a USB cardreader (Raspberry Pi, UDEV)

Hey all! :) I'm trying to create a fixed mount point for an usb cardreader. I've found a script on a raspberry pi forum which does the following: usb stick is plugged in -> script checks the mount point for data -> script starts copying the files automatically -> script unmounts the... (0 Replies)
Discussion started by: Eomer
0 Replies

2. Programming

Look-up USB mounting point

Hi all, I'm developing a short program to look-up for all devices connected to the computer. Using udev and libusb libraries I achieved some progress but I can not find the way to find the mount point. For instance, given a device that I can retrieve using libusb, I would like to know... (4 Replies)
Discussion started by: Carles Rabaneda
4 Replies

3. Shell Programming and Scripting

udev rules for mounting CDROM

Hi All, I need a simple udev rules in my server Centos 5.4. This rules needs to get trigger my script whenever the cdrom is attached to the server. Could you please provide your suggestion on it. Thanks, Kalai (0 Replies)
Discussion started by: kalpeer
0 Replies

4. Ubuntu

FAQ adding rules in udev for my usb 8G to autorun rsync

Hi, I would like to ask if someone knows and show/point me or simple help me how udev rules work in lucyd, upon my quest and search all the tuts i used is based on old udev since something i read the udev change in lucyd version.. I want to accomplised when i plug my usb 8Gb device and automount... (0 Replies)
Discussion started by: jao_madn
0 Replies

5. AIX

Mounting USB Mass Storage

Hi experts, recently i'm exploring USB with filesystem FAT32 mounting on my aix oslevel 6100-04-02-1007. I tried to google to get solutions but failed. Thus, i post it here hope to get solution. Appreciate :) This is my usb drives: (5 Replies)
Discussion started by: polar
5 Replies

6. Solaris

Mounting USB HD

I am very new to Solaris. The machine I am working with is running Solaris 10. I have a 1.5 TB hard drive plugged into a USB dock plugged into the Solaris machine. I ran 'cfgadm -al' and can see that the usb0/1 is usb-storage that was not there before. How do i mount this drive and format... (3 Replies)
Discussion started by: mcdef
3 Replies

7. Solaris

Amazon S3 storage mounting.

We need to mount an amazon S3 share on windows as well as Solaris servers. Any help is appreciated. Thanks in advance. (5 Replies)
Discussion started by: uxadmin007
5 Replies

8. UNIX for Dummies Questions & Answers

Need help with mounting my USB

My previous post seems to be erased and I didn't get any help. I'm logged as root now but no mounting command seems to work, I've tried: Mount -t vfat /dev/sdc1 /mnt/USB Changing "sdc1" for hda1-7, and sdc1-7, and still nothing. Sometimes i get: "special device not found" and others "device... (4 Replies)
Discussion started by: Dax01
4 Replies

9. Solaris

FAT32 usb external hard drive - how to mount??

Hello ! What is the comand to mount and usb hard disk ? I have Solaris 10 installed! 10nx! (1 Reply)
Discussion started by: daniel.balasa
1 Replies

10. UNIX for Advanced & Expert Users

mounting USB

Hi I was trying to mount my USB flashdrive on solaris 10 and I am getting the message saying that (I have already gone through the previous blogs in the forum) mount: Block device required. I have tried most of the possible ways. #rmformat(gives me the necessary information about my flash... (1 Reply)
Discussion started by: akhil1460
1 Replies
Login or Register to Ask a Question