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 05-10-2018, 02:45 PM   #1
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Rep: Reputation: Disabled
automount USB on Debian?


Hi,
I was wondering if someone could shed some light on what im trying to do.
I was reading many tutorials others say though fstab and udev. Im trying to automount the usb to /media/usb2 automatically when the usb connects.
This is what i go so far
on fstab
Code:
/dev/disk/by-label/mylabelname        /media/usb2        ntfs    defaults,noauto        0       0
then created a rule on udev called 11-externalusb.rules


Code:
SUBSYSTEMS=="block", ENV{ID_FS_LABEL}=="mylabelname", RUN+="/bin/mount /dev/disk/by-label/mylabelname"
then to test it i run mount -a

but it im getting and error on the fstab any ideas?

Thank you
 
Old 05-10-2018, 07:43 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,272
Blog Entries: 28

Rep: Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123Reputation: 6123
Try changing "noauto" to "auto."

This is a shot in the dark: I know "auto" works on boot, but I've never tested it on a system that's already booted.
 
Old 05-10-2018, 11:22 PM   #3
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks for the reply, unfortunately did not work i tried this

added on fstab

Quote:
UUID=7462E08062E04886 /media/usb2 ntfs noauto,nofail,x-systemd.automount,x-systemd.idle-timeout=2,x-systemd.device-timeout=2
then reloaded
Quote:
systemctl daemon-reload && systemctl restart local-fs.target
it does mount it automatic when the usb gets connected but the issue is that i can't unmount it manually before unplugging the usb

Thank you
 
Old 05-11-2018, 03:00 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
what do you desire?
  1. that a usb stick is recognized by the file manager, and you can "just click on it"?
  2. or that an external USB hard drive is mounted on system boot?
your current approach is for 2., not 1.
 
Old 05-11-2018, 08:39 AM   #5
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks for the reply, the idea is that the usb will be doing backups weekly. so when i connect the usb to the Debian machine should automatic mount the usb to the folder. Then a script i created will execute the backup to that usb and finally it will unmounted it, then the next day i remove it.

Thank you
 
Old 05-11-2018, 01:59 PM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
i think you want a udev rule.
search for articles on how to write udev rules; maybe this: http://dt.iki.fi/udev/
 
Old 05-11-2018, 06:27 PM   #7
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I don't see why this wouldn't work in fstab
Quote:
UUID=UUID mount_point ntfs defaults,auto 0 0
and put in the script to unmount it when it's done.
 
Old 05-11-2018, 10:09 PM   #8
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
i think you want a udev rule.
search for articles on how to write udev rules; maybe this: http://dt.iki.fi/udev/
Thanks for the reply i saw the guide and tried but no luck this what i did created a rule

Code:
nano /etc/udev/rules.d/11-externalusb.rules
and inside added this
Code:
ACTION=="add", SUBSYSTEM=="usb", \
ATTRS{idVendor}=="125f", ATTRS{idProduct}=="cb10", \
ATTR{serial}=="2622209520150023", \
RUN+="/media/usbmount"
then created a file called usbmount

Code:
mount /media/usb2
then restarted udev
Code:
/etc/init.d/udev restart
when i reconnect the usb no luck to auto mount it
 
Old 05-11-2018, 10:10 PM   #9
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AwesomeMachine View Post
I don't see why this wouldn't work in fstab and put in the script to unmount it when it's done.
the issue for that is that only applies if it gets rebooted the server the idea is that the usb is going to be disconnect and reconnected every week. and it has to be noauto instead of auto because if the usb is not attached its going to get stuck on fstab.
 
Old 05-12-2018, 12:48 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
"no luck" doesn't really cut it, sorry.
udev rules are tricky and require testing; you can't just jump in with your full-blown solution, you have to start with a test script, use the udev monitoring utility etc. etc.
do some research, and spend a little more time on this.
ultimately, it is definitely possible to use udev to achieve what you want. 100% sure of that.

comments on your attempt:
- an executable script should not be in /media. put it in ~/bin or /usr/local/bin instead.
- not sure which distro you use, but shouldn't you be using systemd commands (instead of init.d...)?

good luck.

if you ask for more help, post a full report of what you did, commands issued and output received.
 
Old 05-12-2018, 02:11 AM   #11
Timothy Miller
Moderator
 
Registered: Feb 2003
Location: Arizona, USA
Distribution: Debian, EndeavourOS, OpenSUSE, KDE Neon
Posts: 4,001
Blog Entries: 26

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
Did you ever try just adding the users option so that users can mount/unmount and changing the rights on the script so it runs as your user (thus having it automounted as yourself so you can unmount it)?
 
Old 05-13-2018, 04:18 PM   #12
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Timothy Miller View Post
Did you ever try just adding the users option so that users can mount/unmount and changing the rights on the script so it runs as your user (thus having it automounted as yourself so you can unmount it)?
Thanks for the reply, the user is only going to connect the usb and the rsync does automatic the backup.
 
Old 05-13-2018, 04:25 PM   #13
killmasta93
LQ Newbie
 
Registered: Jun 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
"no luck" doesn't really cut it, sorry.
udev rules are tricky and require testing; you can't just jump in with your full-blown solution, you have to start with a test script, use the udev monitoring utility etc. etc.
do some research, and spend a little more time on this.
ultimately, it is definitely possible to use udev to achieve what you want. 100% sure of that.

comments on your attempt:
- an executable script should not be in /media. put it in ~/bin or /usr/local/bin instead.
- not sure which distro you use, but shouldn't you be using systemd commands (instead of init.d...)?

good luck.

if you ask for more help, post a full report of what you did, commands issued and output received.
Thanks for the reply, as i have tried for the past month and could not get it working, as for the commands in the above post all other tutorials are the same and none of them worked the only one which was was adding this to fstab

Code:
UUID=7462E08062E04886 /media/usb2 ntfs noauto,nofail,x-systemd.automount,x-systemd.idle-timeout=2,x-systemd.device-timeout=2
But the issue as i said before i cant unmount safely. the distro im using is Debian Jessie, and the script is rsync which was duly noted as i changed the location to what you recommended. All I ask is what am i doing wrong from the above commands on post (number 8)
 
  


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
Which .deb do I add to a 'standard iso' Debian install to get usb disks to automount tpprynn Linux - Software 6 10-29-2013 04:52 AM
HAL automount permissions differs between USB HD and USB memory stick Olaus Slackware 5 06-28-2010 06:34 PM
9.04 usb automount rsmereka Ubuntu 2 08-25-2009 12:12 PM
USB Automount: /media/USB Disk morxy Linux - Hardware 3 10-20-2006 08:08 AM
USB automount delta_simon Linux - Software 2 04-09-2005 04:36 AM

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

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