Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
auto mount usb to directory by label
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
thekeymaker
Tux's lil' helper
Tux's lil' helper


Joined: 15 Aug 2010
Posts: 104

PostPosted: Mon Jul 09, 2012 2:29 pm    Post subject: auto mount usb to directory by label Reply with quote

I am a little confused on how to go about this, so I figured if anyone has done this, they might have some advice.

I have a media server, and on it the media files I want to share are under the path:

/share

It’s a directory I made to keep everything organized. Under this directory, besides my media, I also have the following directories:

/share/usb
/share/cd-dvd

I would like to be able to insert a usb flash drive into the media server and have udev populate it in /dev, but I would like to also have it show up with a directory of the drives label under /share/usb. So, for example, if I were to plug in two flash drives labeled Flash1 and Flash2, they would be mounted respectfully like so:

/share/usb/Flash1
/share/usb/Flash2

Plus I would like the data to by synced all the time so I could just pull the drive out when I was done with it. The same would apply to the cd-dvd drive.

What would be the best way to go about this?

I could write udev rules to make the usb’s always mount in /dev to /dev/usb-by-label/ and then bind that location to /share/usb, but is there a better way?

What do you think?

As always, thank you to all who participate!
Back to top
View user's profile Send private message
thekeymaker
Tux's lil' helper
Tux's lil' helper


Joined: 15 Aug 2010
Posts: 104

PostPosted: Mon Jul 09, 2012 4:02 pm    Post subject: Reply with quote

After doing some more research I think this might be the best option. I haven't got to try this yet, but here is my rough put together version.

Add udev rule:
ACTION=="add", BUS==”usb”, KERNEL==”sd[a-z]*", SYMLINK+="media/%k" RUN+="script %k" ## run script and pass %k in as argument

This should, from what I have read, take any usb device and mount it to /dev/media/%k. Then I would run the script that would essentially do this:

#!/bin/bash
mkdir /share/usb/$1
mount -o sync /dev/media/$1 /share/usb/$1

And then I would also need another rule and script to delete the directory once it was removed.

Can anyone think of anything better?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum