Page 5 of 9 FirstFirst ... 34567 ... LastLast
Results 41 to 50 of 84

Thread: Create your own udev rules to control removable devices

  1. #41
    Join Date
    Feb 2008
    Location
    Calgary
    Beans
    115
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Create your own udev rules to control removable devices

    It's working now. The only thing that I've done is that I've rebooted the computer a few times.

  2. #42
    Join Date
    Mar 2008
    Beans
    6

    Re: Create your own udev rules to control removable devices

    Hi, first I will confess that i am a linux noob

    Im having troubles with my EEEPC mod (Internal usb hub + 4gb datatraveler to act as a HD + bluetooth).

    On boot everything works like a charm, the usb mounts as /home as I've configured during the instalation. But when I return from a Suspend, the drive seems to return as a read-only device. I cannot write o create folders on my user Home folder. Please help me figuring out this,

    These are my Fstab, Mtab and the 01-ina.rule created to always mount the pendrive in the same position.

    My FSTAB

    Code:
    # /etc/fstab: static file system information.
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    proc            /proc           proc    defaults        0       0
    # /dev/sda1
    UUID=fc124318-7b33-47e1-ab82-68c8cc6f982a /               ext3    noatime,defaults,errors=remount-ro 0       0
    # /dev/sdc1
    # UUID=5a32cf9c-a43c-4ef8-9c8d-08d866d15024 /home           ext3  noatime,defaults,errors=remount-ro        0       0
    /dev/usf	/home           ext3    rw,users,auto,noatime        0       0
    
    tmpfs     /var/log       tmpfs     defaults,noatime        0 0
    tmpfs     /tmp              tmpfs     defaults,noatime        0 0
    tmpfs     /var/tmp       tmpfs     defaults,noatime        0 0
    THE RULE (/etc/udev/rules.d/01-ina.rules):
    Code:
    # Rules to ensure USB storage devices have persistent names and are mounted
    # at boot.
    
    # USB FIXED
    BUS=="usb", KERNEL=="sd*", SYSFS{serial}=="89900000000000000000007C", NAME="usf", OPTIONS+="last_rule", RUN+="/bin/mount /dev/usf"
    THE MTAB:
    Code:
    /dev/sda1 / ext3 rw,noatime,errors=remount-ro 0 0
    proc /proc proc rw,noexec,nosuid,nodev 0 0
    /sys /sys sysfs rw,noexec,nosuid,nodev 0 0
    varrun /var/run tmpfs rw,noexec,nosuid,nodev,mode=0755 0 0
    varlock /var/lock tmpfs rw,noexec,nosuid,nodev,mode=1777 0 0
    udev /dev tmpfs rw,mode=0755 0 0
    devshm /dev/shm tmpfs rw 0 0
    devpts /dev/pts devpts rw,gid=5,mode=620 0 0
    lrm /lib/modules/2.6.24-12-generic/volatile tmpfs rw 0 0
    securityfs /sys/kernel/security securityfs rw 0 0
    /dev/usf /home ext3 rw,noatime 0 0

  3. #43
    Join Date
    Sep 2007
    Location
    Germany
    Beans
    4
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Create your own udev rules to control removable devices

    Hey, I was going to set up my usb stick like given in the tutorial but I seem to fail at one of the very first steps :/
    I know where my USB stick is (/dev/sdc1) but udevinfo does NOT give me the needed information - I think.
    Do I need it all in SYSFS{}-tags? 'Cause I'm not getting these.
    Here's what udevinfo-output looks like:
    http://nopaste.biz/38639

    EDIT:
    This works:
    Code:
    ATTRS{model}=="Flexi-Drive EC2",ATTRS{vendor}=="Sharkoon",KERNEL=="sd?1",NAME="usbstick1"
    When I add RUN+="/usr/local/bin/usbstick1.sh" it won't run the specified shellscript (it is executable, has a "shebang" and is supposed to copy a file from /home/chosenone to /media/usbstick1)
    Last edited by chosi; March 27th, 2008 at 08:11 PM.

  4. #44
    Join Date
    May 2006
    Beans
    42
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Create your own udev rules to control removable devices

    Hello,

    I tried on Hardy the udev rules way of giving names to removable devices, but no matter what i tried it doesn't work.

    However, simply labeling your drives (follow the excellent tutorial at http://www.debuntu.org/device-partition-labeling) works.

    A new drive with a label appears as /media/<drive label> when you mount it.

    Then you can follow the method proposed by Tirebird in post #20 of this thread if you need more control on the directory where the drive is mounted.

    Hope this helps,
    Ludovic

  5. #45
    Join Date
    Jul 2005
    Beans
    72

    Re: Create your own udev rules to control removable devices

    i am trying to sync my Archos605 when i plug it in. here is the udev that i have created but still cannot seem to get working

    Ubuntu 8.04, kernel 2.6.24-16-rt

    here is my lsusb
    Code:
    lashmoove@UbuntuStudio:~$ lsusb
    Bus 004 Device 008: ID 0e79:1312 Archos, Inc. 
    Bus 004 Device 001: ID 0000:0000  
    Bus 003 Device 001: ID 0000:0000  
    Bus 002 Device 002: ID 1131:1001 Integrated System Solution Corp. KY-BT100 Bluetooth Adapter
    Bus 002 Device 001: ID 0000:0000  
    Bus 001 Device 004: ID 046d:c513 Logitech, Inc. 
    Bus 001 Device 001: ID 0000:0000


    here is my /etc/udev/rules.d/85-my_rule.rules
    Code:
    ATTRS{idVendor}=="0e79", ATTRS{idProduct}=="1312", RUN+="/home/lashmoove/sync_archos"
    and here is my sync_archos
    Code:
    #!/bin/bash
    grsync -e Email
    grsync -e Miro
    grsync -e Pictures
    better stuff here
    Code:
     looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-5':
        KERNELS=="4-5"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{dev}=="189:412"
        ATTRS{configuration}==""
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="80"
        ATTRS{bMaxPower}=="500mA"
        ATTRS{urbnum}=="493"
        ATTRS{idVendor}=="0e79"
        ATTRS{idProduct}=="1312"
        ATTRS{bcdDevice}=="0316"
        ATTRS{bDeviceClass}=="00"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="4"
        ATTRS{devnum}=="29"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="0"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="ARCHOS"
        ATTRS{product}=="a605"
        ATTRS{serial}=="NMP3BALPAS85"
    according to this. my rule is running fine.
    Code:
    lashmoove@UbuntuStudio:~$ udevtest /devices/pci0000:00/0000:00:1d.7/usb4/4-5
    This program is for debugging only, it does not run any program,
    specified by a RUN key. It may show incorrect results, because
    some values may be different, or not available at a simulation run.
    
    parse_file: reading '/etc/udev/rules.d/025_logitechmouse.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/05-options.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/05-udev-early.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/20-names.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/30-cdrom_id.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/40-basic-permissions.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/40-permissions.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/45-fuse.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/45-kvm.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/45-libmtp7.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/45-libnjb.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/50-libpisock9.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/50-virtualbox-ose.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/50-xserver-xorg-input-wacom.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/55-hpmud.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/60-persistent-input.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/60-persistent-storage-tape.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/60-persistent-storage.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/60-symlinks.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/61-persistent-storage-edd.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/65-dmsetup.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/70-persistent-cd.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/70-persistent-net.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/75-cd-aliases-generator.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/75-persistent-net-generator.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/80-programs.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-alsa.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-brltty.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-hdparm.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-hplj10xx.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-hwclock.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-ifupdown.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-my_rule.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/85-pcmcia.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/90-modprobe.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/95-hal.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/95-udev-late.rules' as rules file
    parse_file: reading '/etc/udev/rules.d/kino.rules' as rules file
    import_uevent_var: import into environment: 'MAJOR=189'
    import_uevent_var: import into environment: 'MINOR=390'
    import_uevent_var: import into environment: 'DEVTYPE=usb_device'
    import_uevent_var: import into environment: 'DRIVER=usb'
    import_uevent_var: import into environment: 'DEVICE=/proc/bus/usb/004/007'
    import_uevent_var: import into environment: 'PRODUCT=e79/1312/316'
    import_uevent_var: import into environment: 'TYPE=0/0/0'
    import_uevent_var: import into environment: 'BUSNUM=004'
    import_uevent_var: import into environment: 'DEVNUM=007'
    udevtest: looking at device '/devices/pci0000:00/0000:00:1d.7/usb4/4-5' from subsystem 'usb'
    udev_rules_get_name: rule applied, '4-5' becomes 'bus/usb/004/007'
    udev_db_get_device: found a symlink as db file
    udev_device_event: device '/devices/pci0000:00/0000:00:1d.7/usb4/4-5' already in database, cleanup
    udev_node_add: creating device node '/dev/bus/usb/004/007', major=189, minor=390, mode=0664, uid=0, gid=0
    udevtest: run: 'bash /home/lashmoove/sync_archos'
    udevtest: run: 'socket:/org/freedesktop/hal/udev_event'
    udevtest: run: 'socket:/org/kernel/udev/monitor'
    Last edited by keithacole; May 7th, 2008 at 08:56 PM.
    modded xbox, overclocked cassiopeia, Ubuntu Box, Xubuntu Tablet, Ubuntu Studio in 4u server case, XP on Dell XPS 1210 that needs new battery, Vista Box, vonage, 108MBs wifi, podcast connoisseur, CBR F3(daily ride)...Dad

  6. #46
    Join Date
    Jun 2008
    Beans
    17

    Re: Create your own udev rules to control removable devices

    Same trouble here, running Hardy as well and trying to sync my A604 and disk-on-key devices. udevtest expects nothing by greatness, but udev itself leaves me empty handed.

    I also tried using Upstart, but it seems upstart won't generate an event for a new usb device - you'd have to emit an event using udev.

  7. #47
    Join Date
    Sep 2007
    Beans
    9
    Distro
    Ubuntu 8.04 Hardy Heron

    Talking Re: Create your own udev rules to control removable devices

    This is just a quick post to say Thank You for this excellent guide!

    I have a laptop and move around a lot and use various different USB harddrives, thanks to this guide my I'm no longer pulling my hair out and going mad tyring to sync or in some cases just easily access the drives.


    Thanks a lot!!

  8. #48
    Join Date
    Jun 2008
    Beans
    17

    Re: Create your own udev rules to control removable devices

    Quote Originally Posted by Manslen View Post
    Same trouble here, running Hardy as well and trying to sync my A604 and disk-on-key devices. udevtest expects nothing by greatness, but udev itself leaves me empty handed.

    I also tried using Upstart, but it seems upstart won't generate an event for a new usb device - you'd have to emit an event using udev.
    I made a newbie's mistake, and tried running my command without a full path qualifier. changing it to /bin/myscript solved the problem.

  9. #49
    Join Date
    Jun 2008
    Beans
    17

    Re: Create your own udev rules to control removable devices

    For what it's worth, here is how I got my USB device to automatically be synchronized once I plug it in.

    I am synchronizing my podcast library, located at /home/michael/POD.
    First, I created a mount point:
    Code:
    sudo mkdir /media/A604
    Next, I wrote a small script that attempts to mount the USB device and then run rsync to perform the synchronization.
    Code:
    sudo nano /usr/local/bin/sync-pmp
    The content:
    Code:
    #!/bin/bash
    /bin/mount -t auto /dev/$1 /media/A604
    if [ $? == 0 ]
    then
            rsync -rtuv home/michael/POD --delete /media/A604&
    fi
    don't forget to give it execute permissions.
    Code:
    chmod a+x /usr/local/bin/sync-archos
    What the script does, is attempts to mount the USB device and if it succeeds it runs rsync. The mounting is done on an unknown device name ($1) since I cannot rely on a constant device name (I have several USB devices periodically connected).

    For the udev rule, I followed the first post on this thread to get the device info. I was interested in the node in which the value of KERNEL was sdb (this is the parameter I want to pass over to my script).
    Code:
      looking at device '/block/sdb':
        KERNEL=="sdb"
        SUBSYSTEM=="block"
        DRIVER==""
        ATTR{dev}=="8:16"
        ATTR{range}=="16"
        ATTR{removable}=="1"
        ATTR{size}=="58396275"
        ATTR{stat}=="      62      675     1019      304        0        0        0        0        0      188      304"
        ATTR{capability}=="13"
    I was also interested in a parameter that would uniquely identify my Archos player. udev rules allow you to pick attributes from one parent of the node you are interested in, and I found one.
    Code:
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-1':
        KERNELS=="2-1"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{dev}=="189:131"
        ATTRS{configuration}==""
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="80"
        ATTRS{bMaxPower}=="500mA"
        ATTRS{urbnum}=="453"
        ATTRS{idVendor}=="0e79"
        ATTRS{idProduct}=="130a"
        ATTRS{bcdDevice}=="0316"
        ATTRS{bDeviceClass}=="00"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="2"
        ATTRS{devnum}=="4"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="0"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="ARCHOS"
        ATTRS{product}=="a604wifi"
        ATTRS{serial}=="DFN59TCU1RNE"
    The last two attributes are exactly what I need.

    I then wrote the udev rule.
    Code:
    sudo nano /etc/udev/01-synchronize-pmp.rules
    And the content:
    Code:
    SUBSYSTEM=="block", ACTION=="add", ATTRS{product}=="a604wifi", ATTRS{serial}=="DFN59TCU1RNE", ATTRS{removable}=="1", RUN+="/usr/local/bin/sync-archos %k1"
    Test your settings by plugging in your USB device and then restarting udev.
    Code:
    sudo /etc/init.d/udev restart
    This is my first linux hack/howto, so feel free to point out what I got wrong.
    Last edited by Manslen; June 22nd, 2008 at 08:39 PM.

  10. #50
    Join Date
    Dec 2005
    Beans
    3

    Re: Create your own udev rules to control removable devices

    Just to say a big 'thank you' for this: that was very useful indeed.

    Graham

Page 5 of 9 FirstFirst ... 34567 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •