Page 8 of 9 FirstFirst ... 6789 LastLast
Results 71 to 80 of 84

Thread: Create your own udev rules to control removable devices

  1. #71
    Join Date
    Dec 2011
    Beans
    1

    Re: Create your own udev rules to control removable devices

    How about a rules for ignoring a device, I came up with

    ATTRS{model}=="TOSHIBA 674338", OPTIONS="ignore_device"

    but this didn't work.

    Any ideas how to prevent disk of the format /dev/sda from being detected,
    i.e. to not create /dev/sda /dev/sdaX and all the symlinks in /dev/disk?

    Using ubuntu 11.04

  2. #72
    Join Date
    Jun 2007
    Beans
    322

    Re: Create your own udev rules to control removable devices

    At least for USB drives can't this be done easier by using UUIDs?

    I'll try and post results...
    Intel C2D E7200 || Intel DG33FB mobo || 4 GB RAM || 64 bit Lucid/ Precise Desktops || WD Caviar Black 1TB, Green 2TB; Corsair Force 3 60GB
    Dell U2412M || Palit Sonic GT 240 (OC'd NVidia card) || Logitech Quickcam Connect || Acer 3300U Scanner

  3. #73
    Join Date
    Jun 2007
    Beans
    322

    Re: Create your own udev rules to control removable devices

    Quote Originally Posted by shreepads View Post
    At least for USB drives can't this be done easier by using UUIDs?

    I'll try and post results...
    Yup, works fine...

    1. Run in the terminal
    Code:
    sudo blkid
    2. Connect the USB drive and let it automount.

    3. Run in the terminal
    Code:
    sudo blkid
    4. Note the UUID(s) of the new partition(s) listed, which would be the one(s) on the USB drive.

    5. Create a suitable mount point(s)
    Code:
    cd /media
    sudo mkdir SS4GB1
    sudo chgrp plugdev SS4GB1
    6. Edit fstab and add an entry like so (tweak any settings you like)
    Code:
    UUID=<insert UUID from above without quotes>                                 /media/SS4GB1    vfat   auto,noexec,rw,users,nodev,nosuid,noatime,flush     0        2
    Now you can leave it plugged in at boot, 'Remove Safely', plug it back in while running, remove as another user etc etc and it is always on /media/SS4GB1 (err.. except when it is ejected of course! )
    Intel C2D E7200 || Intel DG33FB mobo || 4 GB RAM || 64 bit Lucid/ Precise Desktops || WD Caviar Black 1TB, Green 2TB; Corsair Force 3 60GB
    Dell U2412M || Palit Sonic GT 240 (OC'd NVidia card) || Logitech Quickcam Connect || Acer 3300U Scanner

  4. #74
    Join Date
    Dec 2006
    Beans
    57

    Re: Create your own udev rules to control removable devices

    Yep, UUIDs would be much cleaner I think.

  5. #75
    Join Date
    Jun 2007
    Beans
    322

    Re: Create your own udev rules to control removable devices

    Quote Originally Posted by mattydee View Post
    Yep, UUIDs would be much cleaner I think.
    Only one problem, it holds up the boot sequence if the USB stick isn't plugged in and you need to hit 'S' to skip trying to mount it.

    I guess that can be fixed by adding "nofail" to the fstab mount options...
    Intel C2D E7200 || Intel DG33FB mobo || 4 GB RAM || 64 bit Lucid/ Precise Desktops || WD Caviar Black 1TB, Green 2TB; Corsair Force 3 60GB
    Dell U2412M || Palit Sonic GT 240 (OC'd NVidia card) || Logitech Quickcam Connect || Acer 3300U Scanner

  6. #76
    Join Date
    Dec 2006
    Beans
    57

    Re: Create your own udev rules to control removable devices

    Quote Originally Posted by shreepads View Post
    Only one problem, it holds up the boot sequence if the USB stick isn't plugged in and you need to hit 'S' to skip trying to mount it.

    I guess that can be fixed by adding "nofail" to the fstab mount options...
    Good point. Wouldn't you have the same problem using udev rules anyway? The system would try to mount the same (disconnected) USB device at boot from the udev created device node (EDIT: except in this case it wouldn't be created so the system would try to mount from a device node that doesn't exist), so you'd still need the nofail option. Unless I'm missing something.
    Last edited by mattydee; September 12th, 2012 at 06:11 AM.

  7. #77
    Join Date
    Jun 2007
    Beans
    322

    Re: Create your own udev rules to control removable devices

    Quote Originally Posted by mattydee View Post
    Good point. Wouldn't you have the same problem using udev rules anyway? The system would try to mount the same (disconnected) USB device at boot from the udev created device node (EDIT: except in this case it wouldn't be created so the system would try to mount from a device node that doesn't exist), so you'd still need the nofail option. Unless I'm missing something.
    Yup, makes sense... But I won't be trying it out using udev, far too complicated!
    Intel C2D E7200 || Intel DG33FB mobo || 4 GB RAM || 64 bit Lucid/ Precise Desktops || WD Caviar Black 1TB, Green 2TB; Corsair Force 3 60GB
    Dell U2412M || Palit Sonic GT 240 (OC'd NVidia card) || Logitech Quickcam Connect || Acer 3300U Scanner

  8. #78
    Join Date
    Apr 2010
    Beans
    19

    Re: Create your own udev rules to control removable devices

    After many hours of reading and experimenting I have come to an acceptable solution for mounting my external USB hard drive. I am posting it here in the hopes it will help others.
    Some background: I am running Ubuntu 10.04.4 Server and therefore have no GUI installed nor do I want one. This is the reasoning behind getting UDEV to work for me. I have an external USB hard drive in an enclosure that is going to store cloned images of the workstations in my network. I wanted to produce a UDEV rule that would at least mount the USB drive for me as I am a former Windows user and tend to be lazy.
    My solution had to overcome some difficulties. First I could not run the mount command from within the UDEV rule so I had to use a script. Second the script has to be run with root privileges.
    I created a UDEV rule as follows
    Code:
     
     SUBSYSTEM=="usb", ATTR{serial}=="###########", ACTION=="add", WAIT_FOR="/dev/sdx1", RUN+="/usr/bin/sudo /home/user/udev_mount_MyDrive.sh"
    The WAIT_FOR key was needed because the mount script would simple silently fail. I believe this is related to something I read about UDEV terminating processes.
    The script file is a simple mount command such as:
    Code:
     
    mount /dev/sdx1 /my/mount/dir
    To execute the script without entering a password I added the user to the sudoers file for this mount script. I changed the permission on the mount script so root has rwx and others have no permissions. This has worked for me but I do have a concern. From what I've been able to decipher from the Ubuntu teams scripts they use the serial id to create the drive letter and thus this should keep working correctly. I could be wrong on that as I have only had time to examine a few UDEV rules.

  9. #79
    Join Date
    Dec 2006
    Beans
    57

    Re: Create your own udev rules to control removable devices

    Nattereri:

    You shouldn't be writing a script to mount that drive. You can use udev rules if you want, but as shreepads and I discussed, using UUIDs is probably a cleaner option.

    If you use UUID, the only thing you have to modify is /etc/fstab. For example, you would add the entry:
    Code:
    UUID=DE8A05A28A057873    /home-files     ntfs-3g nofail,uid=1000,gid=1001,fmask=113,dmask=002   0       0
    replacing the UUID with the one from your drive of course. To find out the UUID of your drive, use the command blkid. In this example, I set the permissions using the uid,gid, fmask and dmask options because it's an NTFS drive, but your situation my differ. The important option here is the nofail one, as discussed above. Refer to man fstab for more info.

    Not sure if I'm missing something, but again: you really shouldn't be writing scripts and adding users to sudo to mount drives when you can use /etc/fstab.

    EDIT: I guess what I missed was the fact that you want the drive to mount automagically after plugging it in, correct?
    Last edited by mattydee; September 24th, 2012 at 02:03 AM.

  10. #80
    Join Date
    Apr 2010
    Beans
    19

    Re: Create your own udev rules to control removable devices

    mattydee:
    Yes I want it to automagically mount after pluggin it in. I did not read about fstab and maybe I should investigate it. I knew about the drives failing on boot and that is why I went with the udev route. But maybe I could use a combination of the two to eliminate the root mounting problem and just execute mount -a. A more elegant solution and less files laying around to secure.

Page 8 of 9 FirstFirst ... 6789 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
  •