LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-03-2019, 09:28 AM   #1
triley831
Member
 
Registered: Feb 2017
Posts: 34

Rep: Reputation: Disabled
Automount USB Drive for regular user


I have a requirement to setup something that will automount an external USB drive for a regular user without any intervention by the user, to a specific mount point.

Is there anyone that could suggest at least a jumping off point for me? I've tried google searching but not finding anything helpful.

We're using RHEL 7.5

Thank you.
 
Old 01-03-2019, 09:36 AM   #2
jsbjsb001
Registered User
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,440

Rep: Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782
Quote:
Originally Posted by triley831 View Post
I have a requirement to setup something that will automount an external USB drive for a regular user without any intervention by the user, to a specific mount point.

Is there anyone that could suggest at least a jumping off point for me? I've tried google searching but not finding anything helpful.

We're using RHEL 7.5

Thank you.
Are you sure about what I've highlighted in bold? And looking at your posting history, you don't seem to get back to us, and just ask a question without responding back. You also seem to be asking at least a few questions about RHEL, where you have been told before that if you are paying for it, the best place to ask is Red Hat themselves. Why don't you do this ?

While the following manual page for fstab would require the drive to be plugged in when your system starts, you may wish to review the following command;

Code:
man fstab
 
Old 01-03-2019, 09:44 AM   #3
triley831
Member
 
Registered: Feb 2017
Posts: 34

Original Poster
Rep: Reputation: Disabled
I thought we could only go to Redhat if there was some kind of problem. Not that they would show us how to do something we don't yet know how to do.

Yes, I've google searched this, nothing seems to really match what we're trying to do.

The requirement is for some military person to attach a drive to a system, where it will automount at /media, then they run a program that offloads some data from the system onto that drive. Now right here is part of the problem. I know that in Rhel 7 it now automounts to /run/media/user/some-hardware-ID-#? - not sure what this value is that appears when the drive is plugged in. T I know that I'm probably going to have to request that our software be changed, just trying to have my ducks in a row before that.
 
Old 01-03-2019, 09:47 AM   #4
jsbjsb001
Registered User
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,440

Rep: Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782Reputation: 1782
Quote:
Originally Posted by triley831 View Post
I thought we could only go to Redhat if there was some kind of problem.
...
Another post that doesn't make any sense... if you paying for it, a part of that subscription INCLUDES technical support. How is this not technical support ?

Look at the man page I posted before, and do another (proper) search.
 
Old 01-03-2019, 09:57 AM   #5
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 11,529

Rep: Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335
I have this set up in fstab
Code:
/dev/sdb1	 /mnt/hd	  auto	      noauto,relatime,diratime,user,exec,dev,suid,nofail     0   0
You can't automount at boot time because root mounts it, which means no luser can write. A lot of the options cater for a usb key, I've highlighted the ones that control this.
So as you boot, it's not mounted. Every user that matters needs to have a line in ~/.bash_profile or some login script like 'mount /dev/sdb1' or /mount '/mnt/hd' for my example, and it mounts on login.
Maybe you could execute the mount command as user nobody in rc.local if you're good with su.

There's a disadvantage, that if you suspend without unmounting, sdb1 exists in /proc/mounts, so when you restart, that drive is discovered, and re-labelled sdc1 :-/. I'd have to stick something in the suspend/resume stuff to handle that, but frankly I never bothered. I just work around it.
 
1 members found this post helpful.
Old 01-03-2019, 10:28 AM   #6
triley831
Member
 
Registered: Feb 2017
Posts: 34

Original Poster
Rep: Reputation: Disabled
Thank you for your response business_kid. Does the above mean though, that any drive connected to the system will be sdb1?
 
Old 01-04-2019, 04:26 AM   #7
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 11,529

Rep: Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335Reputation: 1335
No. The second drive connected, which in my case is the first external drive would be mounted by that. You simply mount the one you want. It is common to list disks in fstab by id (as I did) or by uuid, in which case it's better to add a comment explaining what partition it is. If you have 2 external disks, and want them each to appear in the same spots when mounted, uuid would be better.
 
1 members found this post helpful.
Old 01-04-2019, 07:41 AM   #8
triley831
Member
 
Registered: Feb 2017
Posts: 34

Original Poster
Rep: Reputation: Disabled
Our problem is that we have to be able to mount any USB drive out there in the world as the same mount. So I don't think UUID would work.
 
Old 01-17-2019, 10:36 AM   #9
triley831
Member
 
Registered: Feb 2017
Posts: 34

Original Poster
Rep: Reputation: Disabled
I did wind up going to RedHat for a solution to this. In case it helps someone else in the future, they had me solve this issue by creating a new udev rule. The exact format they provided is below:

in /etc/udev/rules.d Create a new file called 80-udisks-rules
The contents of this file should be exactly....

#UDISKS_FILESYSTEM_SHARED
#==1: mount filesystem to a shared directory (/media/VolumeName)
#==0: mount filesystem to a private directory (/run/media/$USER/VolumeName)
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDSIKS_FILESYSTEM_SHARED}="1"

Then enter these commands if you don't want to reboot:

udevadm control --reload-rules
udevadm trigger --type=devices --action-change

Now, when a USB drive is plugged into our system, it mounts to /media, instead of /run/media. It's left me with a permissions issue so I'm probably going to create a new post for that.

Cheers
 
Old 01-19-2019, 03:26 PM   #10
Mike_Walsh
Member
 
Registered: Jul 2017
Location: King's Lynn, UK
Distribution: Nowt but Puppies....
Posts: 460

Rep: Reputation: 245Reputation: 245Reputation: 245
Looks familiar.

Several of our members over at the Murga-linux 'Puppy' forum were having this same problem; possibly exacerbated by Puppy's 'running-as-root' behaviour. Pup uses a row of icons. bottom left of the desktop, to represent the various drives, etc, attached to the system. Trouble was, every time you re-boot, drives were getting re-detected differently, and mounted to different points.....playing havoc where anyone had something sym-linked from an auto-mounted partition. And for some reason, USB HDDs appeared to be more problematic than a standard USB flash drive...

One of our members, who runs Ubuntu alongside Puppy, adapted a 'udev-rules' script he uses there.....and added some extra stuff to it. Which works nicely. I have a Seagate Expansion external Desktop drive @ 3 TB, from where several things are sym-linked into the system at boot. Pup kept mounting the drive in different places; drove me crazy!

I now have this mounted at /SeaDesk (the name I chose for ID-ing it), and sym-link from this permanent mount-point.

/root/udev/mkrule:-

Code:
#!/bin/bash
#
#    Make a udev rule and mount script for a usb drive, and trigger
#
#    Usage ./mkrule /dev/sdX <Convenient USB Device Name i.e.: WD1600z>
#	 Do NOT use spaces, slashes, asterisks, or other weird characters in device name.
#
if (( $# != 2 )); then
    echo
    echo "    Usage: ./mkrule /dev/sdX <Convenient USB Device Name i.e.: WD1600z> "
	echo
	echo "    Do NOT use spaces, slashes, asterisks, or other weird characters "
    echo "	in device name. "
    echo
    exit 0
fi

cp /root/udev/mnt-template /root/udev/mnt-$2
USBThumb=$1	# We could just use $1 throughout, but this lends itself to customization
DevName="$2"

##### Create new udev rules file for the USB device #####
rulespath="/etc/udev/rules.d/70-$DevName.rules"

manufacturer=$(udevadm info -a -p $(udevadm info -q path -n $USBThumb) | grep -m 1 "manufacturer" | sed -e 's/^[ \t]*//') 
product=$(udevadm info -a -p $(udevadm info -q path -n $USBThumb) | grep -m 1 "product" | sed -e 's/^[ \t]*//')
serial=$(udevadm info -a -p $(udevadm info -q path -n $USBThumb) | grep -m 1 "serial" | sed -e 's/^[ \t]*//')

echo SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", "$manufacturer", "$product", "$serial", SYMLINK+="$DevName-%n", RUN+="/root/udev/mnt-$DevName" > $rulespath
echo "" >> $rulespath
	
#  Reload rules and trigger 	
udevadm control --reload-rules
udevadm trigger
##### done #####
/root/udev/mnt-Seadesk:-

Code:
#! /bin/bash
#
#######  USB flash mount point cleanup and re-mount.   #######
#
MyName=$(echo $0 | rev | cut -d '/' -f1 | rev)
DevName=${MyName:4}

MyDevs=$(ls /dev/"$DevName"*)
MountPoints=$(ls -d /$DevName/*)

IFS=$'\n'      

for j in $MountPoints
do
    umount /"$DevName"$j
    rm -r /"$DevName"$j
done

for j in $MyDevs
do
    NewDir=$(echo $j |  cut -d '/' -f3)
    mkdir -p /"$DevName"/$NewDir		# force creation of directory tree.
    mount $j /"$DevName"/$NewDir
done

sleep 5 # needed to prevent repeating
/etc/udev/rules.d/70-SeaDesk.rules:-

Code:
SUBSYSTEMS=="usb", DRIVERS=="usb", ENV{DEVTYPE}=="partition", ATTRS{manufacturer}=="Seagate", ATTRS{product}=="Expansion Desk", ATTRS{serial}=="NA8X0JHL", SYMLINK+="SeaDesk-%n", RUN+="/root/udev/mnt-SeaDesk"
(Remember; /root is the user's 'home' directory in Pup, 'cos Pup is intended as a single-user system.)

Works nicely; keeps the drive always mounted in the same spot. Just what I needed...


Mike.

Last edited by Mike_Walsh; 01-19-2019 at 03:36 PM.
 
1 members found this post helpful.
Old 01-19-2019, 04:41 PM   #11
yelirt5
LQ Newbie
 
Registered: Jan 2019
Posts: 19

Rep: Reputation: Disabled
That looks promising. But what about permissions? Who can write to the USB drive?

Even though RedHat helped us with our requirement to mount at /media, it left us with another problem. Our software runs as one user, the operators use another account which is very limited. So the drive mounts at /media, owned by that limited user. What they do is, select a button on the software that invokes an rsync from the software account user's home directory and writes it to the drive at /media. What I recently discovered is that the software user doesn't have permission to write to the drive, given that's it owned by the operator user account.
 
Old 01-20-2019, 06:37 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,774

Rep: Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537Reputation: 2537
Well, you have at least 2 options

1. add user to relevant group & give group write access - low security

2. make rsync job suid & root owned (or sgid + relevant grp) - a bit higher security
NB: rsync job in this case should not be in user's home dir but eg /usr/local/sbin or similar...
 
1 members found this post helpful.
  


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
how to automount usb drives with user owner and user r/w permissions mike11 Linux - Newbie 1 11-19-2009 02:59 PM
[SOLVED] Automount LUKS encrypted USB disk as regular user gargamel Slackware 11 10-31-2009 05:13 AM
Unable to Automount ISO image unless automount is running in foreground! swests Linux - General 4 05-22-2009 12:47 AM
Only root can automount CD drive and USB thumb drive km4hr Red Hat 3 03-25-2009 12:30 PM
CentOS 5.2 Automount isos in fstab \other methods that work?automount iso Frankly3D Linux - General 6 07-13-2008 12:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration