LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-28-2014, 01:20 PM   #1
Gil@LQ
Member
 
Registered: Apr 2010
Location: India /Hyderabad
Distribution: RedHat, CentOS
Posts: 273

Rep: Reputation: 1
udev rules for mounting usb to custom mount points


Hi,

i'm looking for few auto dev rules to automount usb devices, written below rule after some google.

Quote:
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"
ACTION=="add", ENV{mount_options}="relatime"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},user,utf8,umask=000"
ENV{dir_name}="%E{ID_FS_LABEL}"
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
ACTION=="remove", RUN+="/bin/umount -l /media/%E{dir_name}"
ACTION=="remove", RUN+="/bin/rm -rf /media/%E{dir_name}"
LABEL="media_by_label_auto_mount_end"
working perfectly, the way it works is if you connect an usb, it creates an dir with name of its lable, lets say "8gb" and mounts the device on it , so finally you'll see my usb mounted on "/media/8gb" now i want with specific names lets say, "data", so i modified my rule as below.
Quote:
ENV{dir_name}="data"
problem i experiencing is if i insert any external hdd, with two partitions, it is mounting both partions on "/media/data"
but i want it like "/media/data1" and "/media/data2". for that i should your range. like we use creating multiple files "touch file{1..10}, so it will create "file1, file2 ... file10"

i tried modifing rule as
Quote:
ENV{dir_name}=data{1..2}
if above thing works, my first partions will be mounted on "data1" and second partition on "data2" and so on ... but it is not working like that.

please help me with correct solution.

thanks in advance.
 
Old 10-29-2014, 05:46 AM   #2
brebs
Member
 
Registered: May 2013
Posts: 89

Rep: Reputation: Disabled
Here's a more elegant method.
 
Old 10-30-2014, 04:47 PM   #3
Gil@LQ
Member
 
Registered: Apr 2010
Location: India /Hyderabad
Distribution: RedHat, CentOS
Posts: 273

Original Poster
Rep: Reputation: 1
thanks brebs,

though it didnt solve my issue completely, gave me an idea to change my rule to get my work done.

Thanks
 
Old 10-30-2014, 08:54 PM   #4
mikefantomas
LQ Newbie
 
Registered: Oct 2014
Posts: 1

Rep: Reputation: Disabled
Add "%n" at the end of your mount point, it adds the number of partition

Quote:
ENV{dir_name}="data%n"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Mounting 2 identical USB drives to different mount points darkduck Linux - Newbie 6 05-12-2014 05:11 PM
custom udev rules not working amboxer21 Programming 1 12-28-2013 06:10 PM
[SOLVED] Mounting USB-storage devices using udev-rules markush Slackware 6 10-11-2012 06:25 PM
slackware 12.0, udev rules for usb-dev works, but mounting does not work correct paalmarker Linux - General 5 03-30-2010 01:51 AM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 03:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration