You are not logged in.

#1 2017-11-24 08:42:17

Blowfish
Member
Registered: 2017-11-24
Posts: 5

what is the recommended way to automount external hard drive ?

Hello,

I'm new to Arch and have been working on it for a few weeks up to now.
So far i got most things working, but there is still a long list of things that need to be done.

Recently i tried to automount my external hard drive whenever i plug it in.
I found the udev wiki page and went on to make a rule for it, which failed (the corresponding folder in /media was created, but i couldn't access the drive, so it probably didn't mount in there).

Anyway, now i am rather confused as what the differences with th
Then i found out about a way with Udisks + a daemon, which if i understood that correctly also uses udev somehow?
And also there is fstab, but i would still have to type in mount /dev/* (which wouldn't be that troublesome, but it would be nice for it to happen without my input).
Anyway, after looking more into it i got more confused as for what the right way would be.

What exactly are the differences between udev/ udisks2 and what is the standard approach on solving this?

Offline

#2 2017-11-24 08:59:53

kflak
Member
Registered: 2017-09-23
Posts: 52

Re: what is the recommended way to automount external hard drive ?

I'm using udiskie. Works like a charm :-)
https://www.archlinux.org/packages/comm … y/udiskie/

Offline

#3 2017-11-24 09:00:55

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,410

Re: what is the recommended way to automount external hard drive ?

How did your rule look like? What filesystem are you using on your hard drive?

Differences between udev and udisks is the wrong approach,  they are used for different, but interlinked purposes. udev is the general device manager of the kernel it notifies userspace if new hardware (this is anything, from wifi cards, keyboard etcetc. as well as hard disks) becomes present, udisks is an utility that reacts on these notifications created by udev and will handle mounting of hard drives as they become present according to some defined rules.

By creating an udev rule "you" are listening for that event  as well and run a command in reaction to it.

Since there are no "standards" in Arch, you should decide what you want to do. If your goal is minimal interaction from your side then utilizing udisks is likely the most fruitful approach, since it also automatically handles potential filesystem mount options etc. If you want to learn how all of this works at a lower level, figuring out correct udev rules to make them do what you want is also something you can do.

Offline

#4 2017-11-24 09:03:20

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: what is the recommended way to automount external hard drive ?

Closest thing to a standard approach is to just let your gui filemanager handle it, usually using udisks2


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#5 2017-11-24 09:19:40

Blowfish
Member
Registered: 2017-11-24
Posts: 5

Re: what is the recommended way to automount external hard drive ?

filesystem is ntfs, my rule looked like this (i found it on the german archwiki):

/etc/udev/rules.d/10-my-media-automount.rules

# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:
#
# /etc/udev/rules.d/10-my-media-automount.rules

# start at sdb to ignore the system hard drive
KERNEL!="sd[b-z]*", GOTO="my_media_automount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"

# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"

# get the label if present, otherwise assign one based on device/partition
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# create the dir in /media and symlink it to /mnt
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"

# global mount options
ACTION=="add", ENV{mount_options}="relatime"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat) 
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"

# automount ntfs filesystems using ntfs-3g driver
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"

# clean up after device removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"

# exit
LABEL="my_media_automount_end"

I would like to solve the issue with my udev rule, as my reason to switching to arch + i3wm rather than using ubuntu etc. was to force myself to learn how to solve these problems and learn whats going on on a lower level.
so i'm trying to do as much manually as possible, which is rather frustrating at times.

Offline

#6 2017-11-24 13:57:47

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 4,645

Re: what is the recommended way to automount external hard drive ?

Blowfish wrote:

so i'm trying to do as much manually as possible, which is rather frustrating at times.

If you're trying to do as much manually as possible, why automount at all?


How to post. A sincere effort to use modest and proper language and grammar is a sign of respect toward the community.

Offline

#7 2017-11-24 14:31:48

Blowfish
Member
Registered: 2017-11-24
Posts: 5

Re: what is the recommended way to automount external hard drive ?

Well, manually setting something up is one thing, but in this case i would just type in the same commands over and over again.
I guess that is fine since i dont plug/unplug usb devices that often, but now that this issue arose it would be nice to solve it.

Btw. I figured out mount doesn't work in udev, so i followed the instructions of the wiki and set MountFlag=shared.
But now i'm getting a 'transport endpoint is not connected' error.
Which is, ironically, exactly the issue that is supposed to be fixed with the change i made....

Last edited by Blowfish (2017-11-24 14:32:10)

Offline

#8 2017-11-24 14:34:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: what is the recommended way to automount external hard drive ?

Blowfish wrote:

Well, manually setting something up is one thing, but in this case i would just type in the same commands over and over again.

That's what shell functions or aliases are for.  I have a functions called `mnt` and `umnt`, guess what they do.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2017-11-24 14:48:20

Blowfish
Member
Registered: 2017-11-24
Posts: 5

Re: what is the recommended way to automount external hard drive ?

Right, i forgot about aliases, but i guess that would work nicely for now.
As for scripting, i haven't looked into that yet.
But it is on my list of things to do anyway, might as well figure it out now.

Thanks for your help.

Since V1del answered my main question, should i declare this as solved?

Offline

#10 2017-11-24 15:13:16

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,407
Website

Re: what is the recommended way to automount external hard drive ?

The automount thing with udev hasn't worked for a few years now, when systemd decided to remove the ability to run long running processes (such as mount). The wiki tells you exactly that.

The simplest solution is user mounts in /etc/fstab. More complex approaches like udisks are only useful if you use many different devices or quirky filesystems like ntfs.


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#11 2017-11-24 22:25:54

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: what is the recommended way to automount external hard drive ?

Alad wrote:

The simplest solution is user mounts in /etc/fstab. More complex approaches like udisks are only useful if you use many different devices or quirky filesystems like ntfs.

I think most who use their machines for work in an office setting would need automount as a convenience feature, simply because passing a USB thumbdrive is a fairly common way of distributing files that are either too big to easily send online or too sensitive to be risked online (in my work context, exam scripts).


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#12 2017-11-24 22:40:57

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,407
Website

Re: what is the recommended way to automount external hard drive ?

Also a convenient way for anyone to plug in their sticks to your unattended workstation and copy whatever files they like... Anyway, I did mention "many different devices".


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#13 2017-11-24 23:32:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: what is the recommended way to automount external hard drive ?

ngoonee wrote:

I think most who use their machines for work in an office setting would need automount as a convenience feature, simply because passing a USB thumbdrive is a fairly common way of distributing files

I fail to see the connection between these two points.  I use my machine in this way, and I don't have any sort of automounting.  You seem to have a false dichotomy as a hidden premise here: that one must either use fstab entries (thus not being well suited to passing random flash drives around) or use automounting.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#14 2017-11-25 02:25:06

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,130

Re: what is the recommended way to automount external hard drive ?

One crucial thing to decide, I think, is who is doing the mounting. Should it be mounted (manually or otherwise) by root? Or should it be by the user plugging in the device? For random USB keys, I want one thing. For the external drive I use for system backup, I want something else. (Though the difference here isn't automounting or not - I don't automount either.)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#15 2017-11-25 23:17:36

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: what is the recommended way to automount external hard drive ?

Alad wrote:

Also a convenient way for anyone to plug in their sticks to your unattended workstation and copy whatever files they like... Anyway, I did mention "many different devices".

If your workstation is unattended and unlocked the risks are much more than plugging a USB drive in, since it's probably also connected to a network.

Also, I think the likelihood of any individual in my office actually knowing how to do anything with a Linux machine is... fairly small. Especially when it's on a tiling wm.

Trilby wrote:
ngoonee wrote:

I think most who use their machines for work in an office setting would need automount as a convenience feature, simply because passing a USB thumbdrive is a fairly common way of distributing files

I fail to see the connection between these two points.  I use my machine in this way, and I don't have any sort of automounting.  You seem to have a false dichotomy as a hidden premise here: that one must either use fstab entries (thus not being well suited to passing random flash drives around) or use automounting.

I mentioned convenience feature. No dichotomy here, it's just that manual mounting can be (for some) annoying.

That being said, my auto-mount currently does get annoying in that it auto-mounts immediately after I finish running parted on a partiion.... I do that much less than I grab a colleague's thumbdrive though.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#16 2017-11-25 23:24:06

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,130

Re: what is the recommended way to automount external hard drive ?

ngoonee wrote:

Also, I think the likelihood of any individual in my office actually knowing how to do anything with a Linux machine is... fairly small. Especially when it's on a tiling wm.

Even without a tiling wm .... wink

Somebody might steal my laptop (or the uni's PC), but I doubt very much they'd know what to make of the OS. (Probably the IT people would but if IT want to steal data, access to **my** files is the least of anybody's problems.)

Last edited by cfr (2017-11-25 23:24:37)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#17 2017-11-26 19:09:15

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: what is the recommended way to automount external hard drive ?

cfr wrote:
ngoonee wrote:

Also, I think the likelihood of any individual in my office actually knowing how to do anything with a Linux machine is... fairly small. Especially when it's on a tiling wm.

Even without a tiling wm .... wink

Somebody might steal my laptop (or the uni's PC), but I doubt very much they'd know what to make of the OS. (Probably the IT people would but if IT want to steal data, access to **my** files is the least of anybody's problems.)

Actually a stock Gnome/KDE desktop is pretty usable to most people who haven't seen Linux before. The basic 'let's look for a file explorer and a browser' workflow is quite intuitive, and those big buttons do help focus the attention.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#18 2017-11-26 19:58:09

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: what is the recommended way to automount external hard drive ?

Blowfish wrote:

Since V1del answered my main question, should i declare this as solved?

Please do.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#19 2017-11-27 00:11:50

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,130

Re: what is the recommended way to automount external hard drive ?

ngoonee wrote:
cfr wrote:
ngoonee wrote:

Also, I think the likelihood of any individual in my office actually knowing how to do anything with a Linux machine is... fairly small. Especially when it's on a tiling wm.

Even without a tiling wm .... wink

Somebody might steal my laptop (or the uni's PC), but I doubt very much they'd know what to make of the OS. (Probably the IT people would but if IT want to steal data, access to **my** files is the least of anybody's problems.)

Actually a stock Gnome/KDE desktop is pretty usable to most people who haven't seen Linux before. The basic 'let's look for a file explorer and a browser' workflow is quite intuitive, and those big buttons do help focus the attention.

My colleagues think I use OS X because the panel is at the top.

Browser, yes. Obvious, trivial. Firefox has a Welsh interface, but I have a number of colleagues who'd be fine with that and everyone knows Firefox anyway. Chromium is probably even easier and is also right there.

File explorer, less so. I haven't bothered to install Dolphin as the only thing I ever did with it before was quit after it opened automatically when I didn't want it to. Konsole is effectively my file manager. (Well, KDE claims it is gwenview, but that's hardly an obvious choice and it displays only image files and not all of those.)

I agree that a default Gnome/KDE would be easier. But, although I like the bells and whistles of a DE, my bells and whistles are maybe a bit odd. I guess it is a little weird to want Plasma but not a file manager. Fine, I'm weird.

And note that I'm not claiming this is any kind of protection. Just that a tiling WM would probably not be needed to stump most of my colleagues. (Some of my students would be a different matter.)

I should add that I trust my colleagues and actually regard them as a security feature in the places I work, since the physical security of these rooms is questionable, to say the least. (Theoretically, access is restricted. Practically, access is essentially restricted to everybody.)

Last edited by cfr (2017-11-27 00:22:16)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#20 2017-11-27 00:38:11

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: what is the recommended way to automount external hard drive ?

Closing


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB