LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   automount USB on Debian? (https://www.linuxquestions.org/questions/linux-software-2/automount-usb-on-debian-4175629420/)

killmasta93 05-10-2018 02:45 PM

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

frankbell 05-10-2018 07:43 PM

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.

killmasta93 05-10-2018 11:22 PM

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

ondoho 05-11-2018 03:00 AM

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.

killmasta93 05-11-2018 08:39 AM

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

ondoho 05-11-2018 01:59 PM

i think you want a udev rule.
search for articles on how to write udev rules; maybe this: http://dt.iki.fi/udev/

AwesomeMachine 05-11-2018 06:27 PM

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.

killmasta93 05-11-2018 10:09 PM

Quote:

Originally Posted by ondoho (Post 5853374)
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 :(

killmasta93 05-11-2018 10:10 PM

Quote:

Originally Posted by AwesomeMachine (Post 5853450)
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.

ondoho 05-12-2018 12:48 AM

"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.

Timothy Miller 05-12-2018 02:11 AM

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)?

killmasta93 05-13-2018 04:18 PM

Quote:

Originally Posted by Timothy Miller (Post 5853547)
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.

killmasta93 05-13-2018 04:25 PM

Quote:

Originally Posted by ondoho (Post 5853530)
"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)


All times are GMT -5. The time now is 01:47 PM.