queeg Posted August 10, 2010 Share Posted August 10, 2010 The problem is that unRAID is only creating devices for usb flash partitions when the device is first detected and doesn't detect changes afterwards. Sounds reasonable but neither ubuntu or windows systems have this limitation (bug). The problem is showing up when mobile phones using Android are being connected to unRAID server and when flash adapters that support removable flash chips are used. Android phones don't allow mounting the internal flash drive until after the usb connection is made. So at the time the usb cable is attached and unRAID scans the device, there is not a partition. When the user manually mounts the flash drive unRAID is not noticing so no partition device is ever created. Since not everyone has a mobile phone running Android I'm demonstrating the problem using this simple flash drive that has removable flash chip. Repro of problem: Scenario A: Insert the flash adapter with flash chip in it. ls /dev/disk/by-id usb-Generic-_Card_Reader_20060413092100000-0:0 usb-Generic-_Card_Reader_20060413092100000-0:0-part1 Note: unRAID creates a device entry for the partition. Scenario B: 1. Insert the flash adapter with flash chip removed. ls /dev/disk/by-id usb-Generic-_Card_Reader_20060413092100000-0:0 2. Insert the chip into the adapter. ls /dev/disk/by-id usb-Generic-_Card_Reader_20060413092100000-0:0 /etc/rc.d/rc.udev restart ls /dev/disk/by-id usb-Generic-_Card_Reader_20060413092100000-0:0 Note: unRAID never recognizes the chip has been inserted so no device for the partition is ever created. Link to comment
queeg Posted August 13, 2010 Author Share Posted August 13, 2010 I still need some help. I'm trying to hack together some code that can detect if a card reader has it's card inserted. I tried doing the hdparm idea at the bottom of this post. It worked but seems like each time it ran (every second or so) the partition device /dev/disk/by-id was getting removed and created again. I also found an older posting about using an open() call to check if the card is inserted. They used sg_dd somehow to be able to do the open() test in a bash shell. Is this possible in unRAID? Can someone help me with the sg_dd syntax? http://www.linuxquestions.org/questions/linux-hardware-18/how-to-detect-insertion-removal-of-flash-card-in-usb-reader-204852/ Excerpt: I worked it out for myself in the end. The SCSI kernel driver returns a "no medium" code when an open() call is made and removable media (e.g. flash card) is not present. So all I need to do is make an open() call, and see what the return code is. I want to work at the bash level, so rather than writing c code to do this, I just used sg_dd from the sg3_utils suite, which does calls open - I grep out the 'no media' error. Of course, this works whether the reader has been mounted or not. ------------------------------------------------ The first idea was this: I found some references on the internet about this problem. One of the solutions suggested was polling the usb devices. The polling itself gets linux to create or remove the device for the partition when it's inserted or removed. My test was just running the while loop below in telnet session while ls /dev/disk/by-id in a second telnet session. Linux created the device entry when I inserted the chip into the flash reader and removed it when I pulled it out. It took a second or so for the change to be detected. Very fast. I also checked out how much cpu time the while loop used by running top in the second session. It used .3% and was hardly noticable. For my usb reader the device name was /dev/sdh. http://www.astahost.com/info.php/multislot-usb-memory-card-readers_t7641.html while true do /sbin/hdparm -z /dev/sdh || sleep 9 sleep 1 done Link to comment
queeg Posted August 18, 2010 Author Share Posted August 18, 2010 I think I'm finally getting a handle on what the problem actually is. It seems to only occur on some card readers. Example: 1. User inserts card reader without any flash chip in it. 2. Linux probes the reader and creates devices for it. It's in step 2 where the problem occurs. Some card readers don't announce how many partitions they support so Linux only creates a device entry for the reader itself. Linux doesn't check for partitions again without explicitly being told to do it. If I can get the device entry for the partition created automatically then I can poll it for when the flash chip actually gets inserted and do the mount/share. How to get it to create the device for the partition automatically? I'm on the trail for this. I found a posting called Card Readers and USB keys using udev with some suggestion for making udev create the device entries for all possible partitions that the card reader supports when the reader is plugged in. I think it would help to have udevinfo installed. Is it somewhere in unRAID? If not, anybody have a download link? Link to comment
graywolf Posted August 18, 2010 Share Posted August 18, 2010 could try from telnet/console find / -name "udev*" -print should be able to determine location if available. Link to comment
queeg Posted August 18, 2010 Author Share Posted August 18, 2010 could try from telnet/console find / -name "udev*" -print should be able to determine location if available. I was running a this but I'll try yours. Is there some way for it to not search down my user shares? find / -print|grep udevinfo Link to comment
BRiT Posted August 18, 2010 Share Posted August 18, 2010 udevinfo is not included in unRAID from my search of the expanded bzroot filesystem. # find /cache/.root/unraid/456/ -type f -name udev\* /cache/.root/unraid/456/etc/udev/udev.conf /cache/.root/unraid/456/sbin/udevd /cache/.root/unraid/456/sbin/udevadm Link to comment
BRiT Posted August 18, 2010 Share Posted August 18, 2010 For what it's worth, even a full Slackware 13.1 / Current distro does not install 'udevinfo'. Link to comment
Joe L. Posted August 18, 2010 Share Posted August 18, 2010 To determine if it is in your search path type which udevinfo As far as keeping the "find" command from searching your disks, use the following additional argument find / -xdev -name "udev*" -print It looks like you missed one or two (also on unRAID 4.5.6) ... find / -xdev -name "udev*" -print /sbin/udevadm /sbin/udevd /lib/udev /etc/udev /etc/udev/udev.conf Link to comment
BRiT Posted August 18, 2010 Share Posted August 18, 2010 Have you tried using the command "udevadm info" instead? Link to comment
queeg Posted August 18, 2010 Author Share Posted August 18, 2010 Have you tried using the command "udevadm info" instead? No, didn't know about it. However, "udevadm info" returns missing option. Link to comment
BRiT Posted August 18, 2010 Share Posted August 18, 2010 That's because you need to give it options as to what to do. Try udevadm info --help to get contextual help if man udevadm doesn't provide anything. # udevadm info --help Usage: udevadm info OPTIONS --query=<type> query device information: name name of device node symlink pointing to node path sys device path property the device properties all all values --path=<syspath> sys device path used for query or attribute walk --name=<name> node or symlink name used for query or attribute walk --root prepend dev directory to path names --attribute-walk print all key matches while walking along the chain of parent devices --device-id-of-file=<file> print major:minor of device containing this file --export-db export the content of the udev database --help Link to comment
queeg Posted August 18, 2010 Author Share Posted August 18, 2010 That's because you need to give it options as to what to do. Try udevadm info --help to get contextual help if man udevadm doesn't provide anything. # udevadm info --help Yea, I'm getting somewhere. udevadm info -a -p $(udevadm info -q path -n /dev/disk/by-id/usb-G*) Link to comment
graywolf Posted August 18, 2010 Share Posted August 18, 2010 could try from telnet/console find / -name "udev*" -print should be able to determine location if available. I was running a this but I'll try yours. Is there some way for it to not search down my user shares? find / -print|grep udevinfo not that I'm aware of since / is the root directory. find would go thru all subdirectories from the starting path you give it. wasn't at machine earlier so couldn't give you location before. did check earlier and udev* had /sbin/udevadm /sbin/udevd and if recall, a conf file in /etc/udev (not at machine again) might check what config info is in the /etc/udev/*.conf file that might help in setting "defaults" although you would have to "update" it with each reboot. Link to comment
queeg Posted August 30, 2010 Author Share Posted August 30, 2010 --- UDEV UDEV UDEV UDEV UDEV UDEV UDEV UDEV--- I'm barely linux savvy and here I am hip deep into udev quicksand. What I want isn't so complicated. I have a card reader, I want linux to create a partition for each of it's cards (1 in this case) even if no card is inserted. All the research says it's possible and even typical to do this by configuring udev. --> If someone on the forum has experience with udev rules in unRAID could you post some examples that worked <-- I have a couple simple questions... 1. Does the machine have to be rebooted for changes to take place? I mean if I add a new file to the /etc/udev/rules.d folder do I have to reboot to have it read by linux? 2. Also, I have another question. I noticed that when I reboot, the contents of the /etc/udev/rules.d gets rewritten and my file never shows up...so where do I put it in unRAID so it will be persistent? I named my file: 71-udevTest.conf This is it's contents: ATTRS{serial}=="20060413092100000*", OPTIONS+="all_partitions,last_rule" It should find the device by it's serial and create all partitions. It seems like my rule isn't being used. ------------some references -------------------------------- http://www.shallowsky.com/blog/linux/udev-cardreaders-update.html http://www.enterprisenetworkingplanet.com/nethub/article.php/10950_3637076_2 http://shallowsky.com/blog/linux/kernel/lucid-udev.html http://reactivated.net/writing_udev_rules.html#builtin https://lists.ubuntu.com/archives/ubuntu-devel/2009-January/027260.html ------------------------------------------------------------------------------- root@Queeg:/etc/udev/rules.d# udevadm info -a -p $(udevadm info -q path -n /dev /disk/by-id/usb-G*) Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0/host15/ta rget15:0:0/15:0:0:0/block/sdg': KERNEL=="sdg" SUBSYSTEM=="block" DRIVER=="" ATTR{range}=="16" ATTR{ext_range}=="256" ATTR{removable}=="1" ATTR{ro}=="0" ATTR{size}=="0" ATTR{alignment_offset}=="0" ATTR{capability}=="53" ATTR{stat}==" 0 0 0 0 0 0 0 0 0 0 0" ATTR{inflight}==" 0 0" looking at parent device '/devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0/ho st15/target15:0:0/15:0:0:0': KERNELS=="15:0:0:0" SUBSYSTEMS=="scsi" DRIVERS=="sd" ATTRS{device_blocked}=="0" ATTRS{type}=="0" ATTRS{scsi_level}=="0" ATTRS{vendor}=="Generic-" ATTRS{model}=="Card Reader " ATTRS{rev}=="1.00" ATTRS{state}=="running" ATTRS{timeout}=="30" ATTRS{iocounterbits}=="32" ATTRS{iorequest_cnt}=="0xde6" ATTRS{iodone_cnt}=="0xde6" ATTRS{ioerr_cnt}=="0xde5" ATTRS{modalias}=="scsi:t-0x00" ATTRS{evt_media_change}=="0" ATTRS{queue_depth}=="1" ATTRS{queue_type}=="none" ATTRS{max_sectors}=="240" looking at parent device '/devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0/ho st15/target15:0:0': KERNELS=="target15:0:0" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0/ho st15': KERNELS=="host15" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0': KERNELS=="2-5:1.0" SUBSYSTEMS=="usb" DRIVERS=="usb-storage" ATTRS{bInterfaceNumber}=="00" ATTRS{bAlternateSetting}==" 0" ATTRS{bNumEndpoints}=="02" ATTRS{bInterfaceClass}=="08" ATTRS{bInterfaceSubClass}=="06" ATTRS{bInterfaceProtocol}=="50" ATTRS{modalias}=="usb:v0BDAp0120d3693dc00dsc00dp00ic08isc06ip50" ATTRS{supports_autosuspend}=="0" ATTRS{interface}=="Bulk-In, Bulk-Out, Interface" looking at parent device '/devices/pci0000:00/0000:00:13.2/usb2/2-5': KERNELS=="2-5" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="CARD READER" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="80" ATTRS{bMaxPower}=="500mA" ATTRS{urbnum}=="17801" ATTRS{idVendor}=="0bda" ATTRS{idProduct}=="0120" ATTRS{bcdDevice}=="3693" ATTRS{bDeviceClass}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="2" ATTRS{devnum}=="6" ATTRS{version}==" 2.00" ATTRS{maxchild}=="0" ATTRS{quirks}=="0x0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Generic" ATTRS{product}=="USB2.0-CRW" ATTRS{serial}=="20060413092100000" looking at parent device '/devices/pci0000:00/0000:00:13.2/usb2': KERNELS=="usb2" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="e0" ATTRS{bMaxPower}==" 0mA" ATTRS{urbnum}=="131" ATTRS{idVendor}=="1d6b" ATTRS{idProduct}=="0002" ATTRS{bcdDevice}=="0206" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="2" ATTRS{devnum}=="1" ATTRS{version}==" 2.00" ATTRS{maxchild}=="6" ATTRS{quirks}=="0x0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Linux 2.6.32.9-unRAID ehci_hcd" ATTRS{product}=="EHCI Host Controller" ATTRS{serial}=="0000:00:13.2" ATTRS{authorized_default}=="1" looking at parent device '/devices/pci0000:00/0000:00:13.2': KERNELS=="0000:00:13.2" SUBSYSTEMS=="pci" DRIVERS=="ehci_hcd" ATTRS{vendor}=="0x1002" ATTRS{device}=="0x4396" ATTRS{subsystem_vendor}=="0x1043" ATTRS{subsystem_device}=="0x8389" ATTRS{class}=="0x0c0320" ATTRS{irq}=="19" ATTRS{local_cpus}=="f" ATTRS{local_cpulist}=="0-3" ATTRS{modalias}=="pci:v00001002d00004396sv00001043sd00008389bc0Csc03i20" ATTRS{enable}=="1" ATTRS{broken_parity_status}=="0" ATTRS{msi_bus}=="" ATTRS{companion}=="" looking at parent device '/devices/pci0000:00': KERNELS=="pci0000:00" SUBSYSTEMS=="" DRIVERS=="" root@Queeg:/etc/udev/rules.d# Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.