LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices

Reply
 
LinkBack Search this Thread
Old 06-17-2008, 05:57 AM   #1
predatorz
Member
 
Registered: Mar 2007
Posts: 58

Rep: Reputation: 15
Question Force External USB HDD to mount to certain folder


Hi,

I tried Google but unable to find anything conclusive on this, or perhaps my google skill sucks.

Is there a way in linux to force external USB HDD to automount to a certain folder when it is plugged into a linux machine?

Thanks for any help.
 
Old 06-17-2008, 06:05 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,843

Rep: Reputation: 122Reputation: 122
Define the mount in /etc/fstab. If your distro (which is?...) automounts devices, it should still mount to where you specify in /etc/fstab. That is at least the case in Slackware 12.1.
 
Old 06-17-2008, 08:34 AM   #3
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 5,995

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
The name of the USB disk will change (sdb sdc sdd etc.), according to what other USB devices you have plugged in or uplugged.
This makes it difficult to sort out with fstab, unless you define it as LABEL=<label> or UUID=<uuid> (see man fstab )

The other way to go about this would be to write a udev rule to handle where the disk is mounted.
See here: http://www.reactivated.net/writing_udev_rules.html (the are examples towards the end)
 
Old 06-17-2008, 08:37 PM   #4
predatorz
Member
 
Registered: Mar 2007
Posts: 58

Original Poster
Rep: Reputation: 15
Thanks, i will go and read up.
 
Old 06-18-2008, 11:26 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 112Reputation: 112
If you are using udev, you can do it with a udev rule. Specifically, check for the device ID when it is plugged in, and if it is THIS device (and no other) mount it HERE. You can force the exact mount you want with a script that is invoked from the udev rule.

To give an example, I have a USB pen drive that is not properly detected by udev. So I wrote this rule to identify it:
Code:
SUBSYSTEMS=="usb",  SYSFS{product}=="USB Flash Memory", KERNEL=="sd?1", NAME="%k", MODE="0666", SYMLINK+="flashmem%n", RUN+="/etc/udev/scripts/penmount.sh flashmem%n pendrive%n"
The rule specifically looks for a usb device that identifies itself as "USB Flash Memory" which is how my PNY Technologies pen drive identifies itself. When the device is identified, a script named penmount.sh is invoked:

Code:
#!bin/bash
if [ "$ACTION" == "add" ]; then
mkdir /media/"$2"
mount -t vfat -o rw,user,auto,sync,noatime,umask=0 /dev/"$1" /media/"$2"
chmod 777 /media/"$2"
else
umount /media/"$2"
rmdir /media/"$2"
fi
This script actually mounts the drive.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
External ubuntu install on external USB HDD th3_tr00p3r Linux - Newbie 1 05-11-2008 02:56 PM
mount External HDD - USB ruwanindika Fedora 6 02-22-2008 08:10 AM
manual mount - external usb hdd (ubuntu) tripled2006 Linux - General 1 01-15-2007 10:08 AM
External USB HDD, mount problem, wierd behaviour. kniwor Slackware 5 08-18-2006 11:15 PM
How to mount External Hdd Jekkaman Slackware 8 12-30-2005 12:09 AM


All times are GMT -5. The time now is 07:00 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration