You are not logged in.

#1 2009-08-27 12:40:28

BasiK
Member
Registered: 2009-08-27
Posts: 8

[SOLVED] How to automatically mount USB drives with custom mount point

edit:
Original title was : 'Unable to mount USB disk via /etc/rc.local', but got changed since the /etc/rc.local problem isn't relevant for me anymore.

Hello,

Since I am new to this forum, I'll start off with this :
Thanks to archlinux, its founder and all its contributors, cause this is the operating system (flavour) that annoys me the least.

The root problem :
I want to automount USB storage devices to other places than /media/ and without the need for programs that depend on gnome and the like. As I tried some stuff with hald and such, I didn't really get to a nice and easy to configure solution. Any hints in that direction are always welcome.

For now, automount of known USB storages devices during boot, will do.
So the things I tried and didnt work :

1.
Provide the disk info to /etc/fstab (via the disks UUID and 'auto' filesystem)
Add 'mount /mountpoint' to /etc/rc.local
Result : the mount command in rc.local says '... specify filesystem'
However, after boot, running /etc/rc.local mounts the USB disks correctly.

2.
Provide the disk info to /etc/fstab (via the disks UUID and the correct filesystem)
Add 'mount /mountpoint' to /etc/rc.local
Result : pc doesn't get through boot process and gives me the 'ctrl-d to reboot or root passwd for maintenance'

3.
Provide no disk info in /etc/fstab
Add the full mount line to /etc/rc.local (mount -t fs /dev/disks/by-uuid/MyUUID /MyMountpoint )
Result : don't remember the output of the mount execution, but well, it didn't mount
However, after boot, running /etc/rc.local mounts the USB disks correctly.


Is there something that isn't loaded at the time of rc.local execution that I need for mounting of USB devices ? Or why else is this failing ?

Regards,
BasiK

Last edited by BasiK (2009-08-28 07:22:50)

Offline

#2 2009-08-27 12:55:28

sHyLoCk
Member
From: /dev/null
Registered: 2009-06-19
Posts: 1,197

Re: [SOLVED] How to automatically mount USB drives with custom mount point

Just use /etc/fstab and it will automount your disks. I think you are not specifying a mount point.

Ex:

/dev/sdb1  /mnt ntfs-3g users,rw,auto,noatime 0    0

~ Regards,
sHy
ArchBang: Yet another Distro for Allan to break.
Blog | GIT | Forum (。◕‿◕。)

Offline

#3 2009-08-27 13:06:16

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

Re: [SOLVED] How to automatically mount USB drives with custom mount point

BasiK wrote:

Hello,

Since I am new to this forum, I'll start off with this :
Thanks to archlinux, its founder and all its contributors, cause this is the operating system (flavour) that annoys me the least.

The root problem :
I want to automount USB storage devices to other places than /media/ and without the need for programs that depend on gnome and the like. As I tried some stuff with hald and such, I didn't really get to a nice and easy to configure solution. Any hints in that direction are always welcome.

For now, automount of known USB storages devices during boot, will do.
So the things I tried and didnt work :

1.
Provide the disk info to /etc/fstab (via the disks UUID and 'auto' filesystem)
Add 'mount /mountpoint' to /etc/rc.local
Result : the mount command in rc.local says '... specify filesystem'
However, after boot, running /etc/rc.local mounts the USB disks correctly.

2.
Provide the disk info to /etc/fstab (via the disks UUID and the correct filesystem)
Add 'mount /mountpoint' to /etc/rc.local
Result : pc doesn't get through boot process and gives me the 'ctrl-d to reboot or root passwd for maintenance'

3.
Provide no disk info in /etc/fstab
Add the full mount line to /etc/rc.local (mount -t fs /dev/disks/by-uuid/MyUUID /MyMountpoint )
Result : don't remember the output of the mount execution, but well, it didn't mount
However, after boot, running /etc/rc.local mounts the USB disks correctly.


Is there something that isn't loaded at the time of rc.local execution that I need for mounting of USB devices ? Or why else is this failing ?

Regards,
BasiK

Write a udev rule to mount them when you plug them in, ???, profit?


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

Offline

#4 2009-08-27 13:07:40

BasiK
Member
Registered: 2009-08-27
Posts: 8

Re: [SOLVED] How to automatically mount USB drives with custom mount point

What I forgot to mention, specifying 'auto' as one of the mount options in fstab also breaks the boot process. Because some USB libs aren't loaded yet iirc ?
And yes, I am specifying a mount point. (If I didn't, just running '/etc/rc.local' after boot wouldn't work either I guess.)

Offline

#5 2009-08-27 13:20:24

BasiK
Member
Registered: 2009-08-27
Posts: 8

Re: [SOLVED] How to automatically mount USB drives with custom mount point

Mr.Elendig wrote:

Write a udev rule to mount them when you plug them in, ???, profit?

No experience with udev rules and doesn't seem that straightforward, but worth giving it a try I guess...

Offline

#6 2009-08-27 19:24:53

brenix
Member
From: California
Registered: 2008-03-05
Posts: 185

Re: [SOLVED] How to automatically mount USB drives with custom mount point

I have similar issues, this is due to udev from what I can remember and hasn't really been fixed. The main problem for me is my drives have a auto-sleep/park mode. You could try using sdparm or hdparm if thats the case. As a workaround, I've been using autofs which seems to mount them ok.

Offline

#7 2009-08-28 05:26:55

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: [SOLVED] How to automatically mount USB drives with custom mount point

All I do is make and /etc/fstab entry and mount them at /mnt/sdb1 . I use the GUI file manager pcmanfm or any GUI file manager to mount the drive. I can also just mount it with    mount /mnt/sdb1

This is what my fstab entrys look like. The one thing I had to figure out is setting the user and permissions. As I have it set up it makes all files read-wright for everyone and all directory's read-wright-execute for everyone.

/dev/mmcblk0p1        /mnt/sd        vfat    user,noatime,dmask=000,fmask=111        0    0
/dev/sdb1        /mnt/sdb1    vfat    user,noatime,defaults,dmask=000,fmask=111        0    0
/dev/sdb6        /mnt/sdb6    auto    user,defaults,noatime                0    0
/dev/sdb7        /mnt/sdb7    vfat    user,noatime,dmask=000,fmask=111        0    0

The problem with this method is that I have an external HHD so the settings need to be different for an ext3 filesystem then vfat. This give me some problems but I can work around them. The way you are suppose to get USB mounting done is with some other file and adding a whole bunch of line of rules talking about... free-opendesktop-permissions-bla-bla  maybe after you google a bit more you will read of that way. I like the fstab way better though. The other way is a pain in the ass.

Also, with the fstab entry method, it will auto mount the USB stick on boot  but it will not "Auto" mount Hot. However, you plug in the USB drive hot and it will be recognized by the system and your GUI file manager (or you with the mount command) will be able to mount the drive.

Last edited by hunterthomson (2009-08-28 05:39:24)


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

#8 2009-08-28 07:17:50

BasiK
Member
Registered: 2009-08-27
Posts: 8

Re: [SOLVED] How to automatically mount USB drives with custom mount point

Thanks for the hint hunterthomson, but the pc I will be using it on, is an own-built HTPC/home file server, so there is no way I want to use a graphical file manager to get the usb disks mounted.
I tried to figure out a little about udev rules, and I got to do what I wanted to do, so thx for pointing me in that direction Mr.Elendig.

Btw, I am indeed also using auto-sleep/park disks, but this udev way works perfectly.
I added two rules files to /etc/udev/rules.d/ :

The first for a known usb disk (with its volume uuid), with a named mountpoint under my media dir /symbiosis/ :

[basik@plox ~]$ cat /etc/udev/rules.d/80-usb-utopia.rules
ACTION=="add", KERNEL=="sd[b-z][0-9]", ENV{ID_FS_UUID}=="a59332c2-07ba-4c52-afb5-20e361bdf71a",SYMLINK+="usb-%n", GROUP="storage", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", ENV{ID_FS_UUID}=="a59332c2-07ba-4c52-afb5-20e361bdf71a",RUN+="/bin/mkdir -p /symbiosis/utopia"
ACTION=="add", KERNEL=="sd[b-z][0-9]", ENV{ID_FS_UUID}=="a59332c2-07ba-4c52-afb5-20e361bdf71a", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /symbiosis/utopia", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", ENV{ID_FS_UUID}=="a59332c2-07ba-4c52-afb5-20e361bdf71a", RUN+="/bin/umount -l /symbiosis/utopia", OPTIONS="last_rule"

The second for unknown usb disks, to mount under the same dir. This is simply taken from the archwiki http://wiki.archlinux.org/index.php/Ude … .26_Tricks
Make sure these rules are executed after the ones for specific usb disks.

[basik@plox ~]$ cat /etc/udev/rules.d/usb-disks.rules
KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usb%m", GROUP="storage", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usb%n", GROUP="storage", NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /symbiosis/usb%n"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /symbiosis/usb%n", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /symbiosis/usb%n"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /symbiosis/usb%n", OPTIONS="last_rule"

These may not be the nicest looking udev rules, but it works for what I wanted to do with it.

Offline

#9 2009-08-28 09:13:06

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: [SOLVED] How to automatically mount USB drives with custom mount point

Another option would be autofs. I have been using it for a while now and am sorry I didn't look into it sooner. If you are happy with udev stick with it but autofs is worth looking at.

Offline

#10 2009-08-28 22:05:53

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: [SOLVED] How to automatically mount USB drives with custom mount point

BasiK wrote:

Thanks for the hint hunterthomson, but the pc I will be using it on, is an own-built HTPC/home file server, so there is no way I want to use a graphical file manager to get the usb disks mounted.

hunterthomson wrote:

All I do is mak...
Also, with the fstab entry method, it will auto mount the USB stick on boot  but it will not "Auto" mount Hot. However, you plug in the USB drive hot and it will be recognized by the system and your GUI file manager (or with the mount command) will be able to mount the drive.

Just to clarify. There will never be a situation when you would have to use any GUI anything to do any basic operation.

Last edited by hunterthomson (2009-08-28 22:08:52)


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

Board footer

Powered by FluxBB