LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-25-2015, 09:50 AM   #1
adrianmariano
Member
 
Registered: Dec 2004
Distribution: Ubuntu Yakkety
Posts: 188

Rep: Reputation: 15
automounting of usb devices through command line


I prefer to do things from the command line, and so when I plug in a usb device, I don't want to have to click on an icon or open some kind of "explorer" window to access the device. I have been using a udev script which runs pmount to mount devices. With the latest ubuntu update, my script doesn't work properly all the time. I don't know why...and these scripts are a pain to debug because I can't get detailed error information about what has failed. (Note that I do not use the ubuntu desktop environment. I use fvwm.)

So before I try to mess with my script, I thought I'd investigate whether there's something out there already that I should be using instead. Ideally I'd like to be able to plug in usb hard drives or memory sticks and have the device appear with a name based on the volume label (converted to lower case), e.g. /media/<vol_label>. I'd like to be able to unmount it without sudo. Some kind of subtle notification that the device is mounted and ready would be nifty, but not necessary. (I was thinking maybe a message that appears and then fades away, or perhaps a small window that disappears if I click on it anywhere.)
 
Old 09-25-2015, 10:16 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
This is what I use for 'easy' usb devices.
Code:
sudo apt-get install udisks2
Plugin your external storage and open a terminal>

Code:
sudo blkid -c /dev/null
...
/dev/sdb1: LABEL="internal" UUID="126a6de5-fd6a-4727-8d7e-57d93fa41fd5" TYPE="ext4"
/dev/sdc1: LABEL="external" UUID="3f4087c1-649e-4f30-aa4c-648eb5750cfc" TYPE="ext4"
Your UUIDs will be different but in the same format.
is all we're interested in since those are the "extra storage devices" I am choosing to use, so I only included my sd[bc]1 partitions here. Your output will have more than that, so isolate/identify your device(s) and make a note of it/them.

Now for sdb1 use, I use:
Command:
Code:
/usr/bin/udisks --mount /dev/sdb1 /media/jj/internal
and it must be at /media/<your_username>/<whatever_here>

Now for sdc1 use, I use:
Command:
Code:
/usr/bin/udisks --mount /dev/sdc1 /media/jj/external
and <whatever_here> doesn't even have to exist!

Full read-write, everything.
No /etc/fstab entries necessary.

Enjoy the goodness.

And as an added "bonus"... <wait for it>...
Survives reboot.

Good Luck.

Last edited by Habitual; 09-25-2015 at 02:21 PM.
 
Old 10-06-2015, 11:18 AM   #3
adrianmariano
Member
 
Registered: Dec 2004
Distribution: Ubuntu Yakkety
Posts: 188

Original Poster
Rep: Reputation: 15
Unless I'm missing something, udisks, as used this way, is equivalent to pmount. It doesn't automatically mount devices that are plugged in, the way I want. I don't want to have to hunt around to figure out the device path. Also unmounting with udisks is annoying because you have to do it by device instead of being able to use the mount point, so I think I prefer pmount.

When I use udev to mount these devices automatically using pmount then, because udev doesn't run as the user, the user is not able to unmount the device, so it's necessary to use sudo to unmount. I imagine the same thing would happen with udisks, since it would also be run by udev, and hence as a different user.

It seems like there must be some more complete solutions out there to the problem of *automatically* mounting pluggable devices in.
 
Old 10-06-2015, 11:28 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Mine mount auto-magically upon insertion using udisks2 as described above.
The only thing I omitted is I am a member of a few system groups.
I notice 46(plugdev) in
Code:
id $USER
Good luck!
 
Old 10-07-2015, 10:58 AM   #5
adrianmariano
Member
 
Registered: Dec 2004
Distribution: Ubuntu Yakkety
Posts: 188

Original Poster
Rep: Reputation: 15
I'm confused. Above you said you issue the command "/usr/bin/udisks --mount /dev/sdb1 /media/jj/internal". That's not automagic. I want devices to mount themselves, without my having to enter a command, when they are plugged in. Does udisks do this for you?
 
Old 10-07-2015, 11:56 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by adrianmariano View Post
I'm confused. Above you said you issue the command "/usr/bin/udisks --mount /dev/sdb1 /media/jj/internal". That's not automagic. I want devices to mount themselves, without my having to enter a command, when they are plugged in. Does udisks do this for you?
Yes it does.
Sorry, those commands were for my "Session and Startup".
I have never used them in the console and my USBs automount just fine, as they are all inserted if/when I boot.
If I remove one and re-connect it (without rebooting) it auto mounts, in that location every single time, with any intervention from me.

Sorry if I wasn't clear(er).
 
Old 10-07-2015, 12:34 PM   #7
adrianmariano
Member
 
Registered: Dec 2004
Distribution: Ubuntu Yakkety
Posts: 188

Original Poster
Rep: Reputation: 15
Hmmm. I have mounted an unmounted my device with "udisks --mount /dev/sdb1" and "udisks --unmount /dev/sdb1" and if I subsequently plug it in, nothing happens automatically. If I want it mounted I still have to issue the udisks command again. (Note that I didn't reboot after installing udisks.)
 
Old 10-07-2015, 02:46 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Perhaps the Ubuntu wiki can help?
https://help.ubuntu.com/community/Au...ountPartitions
 
Old 10-07-2015, 03:02 PM   #9
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
http://www.monperrus.net/martin/auto...dev+and+pmount
 
Old 10-12-2015, 01:04 PM   #10
adrianmariano
Member
 
Registered: Dec 2004
Distribution: Ubuntu Yakkety
Posts: 188

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Teufel View Post
This is actually similar to what I'm currently doing. There are two main problems with it:

1. To unmount I have to use 'sudo pumount ....' because the devices are not mounted owned by the user.

2. If the device is improperly unplugged it can generate hundreds of millions of failed unmount attempts with associated log messages. My system filled up the root filesystem generating these error messages (multiple gigabytes worth), and then things didn't work so well (as you'd expect). I wonder if using "pumount -l" in the udev rules might solve this second problem, though.
 
Old 10-12-2015, 02:27 PM   #11
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
The thing is you can automatically mount device on attach event, it isn't too difficult, however you cannot automatically unmount it: when device unplugged it can be detected, but you can't unmount device that already detached. There is nothing to unmount. It causes an errors. Options that intended for suppress errors and force device unmounting doesn't works stable and predictable.
 
Old 10-12-2015, 02:39 PM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
udisks2 is sounding better and better.
 
Old 10-12-2015, 04:22 PM   #13
adrianmariano
Member
 
Registered: Dec 2004
Distribution: Ubuntu Yakkety
Posts: 188

Original Poster
Rep: Reputation: 15
Uh, what he said has nothing to do with udisks. You'll get in trouble there if you unplug a device without unmounting it first. However, I think it is, in fact, possible to unmount devices that have been unplugged. The problem is when you unplug a device that is "active". When you try to unmount such a device you get the message that the device is busy. I believe this is how I ended up with gigabytes of error messages. I wonder if udisks handles this in a different way than pumount.

I'm not asking that devices automatically unmount themselves. I just want to be able to unmount them without using sudo. It's annoying to have to use sudo and type in the password to unmount devices.

From what I can tell, udisks does not do automounting. Various people have written scripts (udiskie, bashmount, udisksvm, udisks-glue(?)) to use udisks to perform automounting.
 
Old 10-12-2015, 05:16 PM   #14
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
you can use sudo without having to type password every time.
just set NOPASSWD option in /etc/sudoers file
However you still need sudo since umount is priveleged command.
 
Old 10-12-2015, 05:38 PM   #15
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Well, I'm done telling you the same thing over and over only to be disregarded.
It works, as I have said. automatically. Every disk, every time.

unmounting requires sudo, but that can be programmitcally allowed via sudoers.

End Transmission.

Last edited by Habitual; 10-12-2015 at 06:30 PM.
 
  


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
LXer: How to measure the speed of SATA devices from the command line on Linux LXer Syndicated Linux News 1 04-04-2013 03:05 AM
usb/cd automounting but access through command line stu_mueller Slackware 5 04-24-2008 03:17 AM
Automounting CD/DVD and USB devices Tux-Slack Slackware 16 06-26-2007 03:04 PM
KDE - automounting devices as user Bruno07 Linux - Hardware 1 02-07-2007 03:25 AM
automounting usb devices with usbmount works well but i have one problem mechmg93 Debian 9 10-23-2005 08:24 AM

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

All times are GMT -5. The time now is 07:45 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