You are not logged in.

#1 2024-06-13 00:09:47

wpkzz
Member
Registered: 2020-01-10
Posts: 47

How to automagically mount external drives in custom directories?

I have some directories as mountpoints that look more or less like this:

/media/usb1
/media/usb2
/media/usb3
/media/usb4

/media/ntfsdisk1
/media/ntfsdisk2

/media/cdromo

I also have entries in fstab that look like this:

/dev/sdc1               /media/usb1 auto            noauto,user,rw  0 0
/dev/sdc2               /media/usb2 auto            noauto,user,rw  0 0
/dev/sdc3               /media/usb3 auto            noauto,user,rw  0 0
/dev/sdc4               /media/usb4 auto            noauto,user,rw  0 0

UUID=706E58A16E5861C0   /media/discoAnaPaula    ntfs-3g noauto,x-systemd.automont,x-systemd.mount-timeout=2,rw,exec     0 0
/dev/sdc1               /media/discontfs1        ntfs-3g noauto,users,rw,exec    0 0
/dev/sdc2               /media/discontfs2       ntfs-3g noauto,users,rw,exec    0 0

My question is two fold:
Can I use some automounting ( like the one provided in thunar  ) that instead of creating something unpalatable like

/run/media/usr/myself/someweirdname/somecrazytag/

uses instead the mountpoints I defined?
Or maybe that automatically creates an alias or a link?

And the other one is, the media with ntfs format is rather picky: without using some desktop enviroment, as user is always a pain to mount the disks.
Either done as root, in which case I cannot move or erase files or anything, just read them, or using some desktop mounter, which creates also a very strange set of
permissions, and the aforementioned, difficult to type long mountpoint.

I use fluxbox and very little extra tools on top or beneath.

I searched a while on the forums about this, but the similar questions seem rather old (2011 or 2009) and they seem to be before systemd. I also checked the
list in the wiki, but it is rather bare, not specifying which tools are better for what.

Like always, thanks in advance for your time.


Moyocoyani, Tloque Nahuaque.

Offline

#2 2024-06-13 01:29:11

dakota
Member
Registered: 2016-05-20
Posts: 415

Re: How to automagically mount external drives in custom directories?

If the drives are properly listed in your fstab, won't this work?

mount -a

Personally, I just use an alias.

Plug in my thumb drive, press Alt-F1 to open a terminal (I also use fluxbox), then type "mount_usb" to execute the alias that is defined in my .bashrc file. Of course, my setup is pretty simple, so that might not work for you.

alias mount_usb='sudo mount -o uid=<myUserName>,gid=<myUserGroup>,fmask=113,dmask=002 /dev/sdd1 /mnt/usb'

Cheers,


"Before Enlightenment chop wood, carry water. After Enlightenment chop wood, carry water." -- Zen proverb

Offline

#3 2024-06-13 06:20:12

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,307

Re: How to automagically mount external drives in custom directories?

The default mount location for udisks user mounts is /run/media/$USER/<label> - "/myself/someweirdname/somecrazytag/" is made up bullshit.

And the other one is, the media with ntfs format is rather picky: without using some desktop enviroment, as user is always a pain to mount the disks.
…
I use fluxbox and very little extra tools on top or beneath.

Please post your xinitrc (assumign you'reusing startx/xinit) and see https://wiki.archlinux.org/title/NTFS-3 … ermissions

Then elaborate on the scenario:
Do you seek to mount persistent drives when booting, some specific drives (eg. on access), random usb keys when plugging them into the system or what happens when you click on a device node in thunar?
You can make udisks mount to /media instead of /run/media/$USER, https://wiki.archlinux.org/title/Udisks#Mount_to_/media
You can use fstab to control the desktination specific devices.
You can use https://wiki.archlinux.org/title/Udisks#Mount_helpers to mount random things.

And wrt. the permissions:
non-degenerated real filesystems will adhere to the permissions on the filesystem, regardless who mounts them how.
NTFS can be made to behave this way, see the previous link.
File Allocation Tables etc. can be controlled to default to specific UIDs, GIDs when mounted by udisks and permissions, see /etc/udisks2/mount_options.conf.example

Offline

#4 2024-06-17 18:58:27

wpkzz
Member
Registered: 2020-01-10
Posts: 47

Re: How to automagically mount external drives in custom directories?

Let us see:
here is my (that is, the one in my home directory) complete xinitrc:

exec startfluxbox

But maybe it was meant the other, the general one in /etc/X11/xinit. That one is this:

#!/bin/sh
userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps
if [ -f $sysresources ]; then

    xrdb -merge $sysresources

fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then

    xrdb -merge "$userresources"

fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# start some nice programs

if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 done
 unset f
fi

twm &
xclock -geometry 50x50-1+1 &
xterm -geometry 80x50+494+51 &
xterm -geometry 80x20+494-0 &
exec xterm -geometry 80x66+0+0 -name login

Now let me elaborate:
I have some three usb pendrives with different format (vfat, ntfs), and also a pair external HDD, one is NTFS and the other partioned into four ext4 filesystems. Also I have some SD cards and the laptop
has a reader integrated, which the kernel identifies as also some usb drive.
I do not use them daily. I plug them occasionaly, in different order, not all at once, and sometimes some friend wants me to use one of hers.

As you preciselly pointed, if I run thunar under fluxbox (or maybe if I decide to use xfce it does automatically), they get mounted in /run/media/$USER/<label>.
Which, I find not palatable as I tend to point them "by writting", and not "by clicking".
If I mount them manually then I have more control, but, alas, I cannot use the best of both worlds (automonting, and simple command line interface).
The NTFS are the worse: they get mounted with only root being able to copy files or delete files in them. From the command prompt I have to either use sudo or login as root to mount them or dismount them.
I shall read more patiently the links provided.

Thanks.


Moyocoyani, Tloque Nahuaque.

Offline

#5 2024-06-17 19:18:06

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,307

Re: How to automagically mount external drives in custom directories?

Your xinitrc is broken (see the last link below and the second note on what to include at least) - the one in /etc becomes inert if you've one in your $HOME

You can use /etc/fstab w/ the UUIDs or LABELs of the devices and automount them into random locations w/ "noauto,x-systemd.automount" in the options so they'll automagically be mounted whenever you access the mountpoint (regardless of where that is)

Offline

Board footer

Powered by FluxBB