Page 1 of 1

Auto mounting / connecting USB disks

Posted: 17 Jan 2012, 20:36
by Adfra
Hi! I have browsed the forums and web but can't seem to find a pretty solution to automount usb disks.

Challange:
Everytime I reconnect a USB device I first need to "connect" the device through the Settings in the webfrontend. Ideally I'd like to have this plug & play - You insert the USB drive and it becomes available instantly under /home/storage/extern/[drivename]

Solution options I have found/tried:
1.) Autofs - Seems to be the way to go but is not supported by the standard kernel of the B3. As such even apt-get install autofs fails. Compiling a new kernel seems a bit daunting...

2.)am-utils - Looks like it should do the job as a module but appears hard to configure (?)

3.)Other options mentioned in the forum like USBmount and iv.... have been touched/developed last in 2007 so seem out of date.

Long story short, how do I best set this up? Do I REALLY need to recompile my kernel?

On the side: Why would you not automount usb drives by default anyway as in Windows??? Especially since the computer detects and identifies the drives correctly. (How good would be a checkbox next to each drive that just says "Automount?", you just tick the box and all mounting is done for you going fwd...)

Thanks
Frank

Re: Auto mounting / connecting USB disks

Posted: 30 Apr 2012, 23:08
by Adfra
[Bump] ...nobody - c'mon surely this is doable on the B3?

Re: Auto mounting / connecting USB disks

Posted: 01 May 2012, 01:41
by Adfra
Alright... after 2 hours of research step 1 is solved - the autofs4 module is installed without recompiling the entire kernel. (That doesn't necessarily mean the USB auto mount will be working though...)

NO GUARANTEES THIS WORKS!!! But...

install the autofs module as described in the following links (I had to read both to get it):

http://forum.excito.net/viewtopic.php?p=7877

and

http://www.pixelbeat.org/docs/rebuild_k ... odule.html (for Fedora, but works almost 1:1)

If you run into issues check with

Code: Select all

dmesg | less
for the last couple of errors and if the error is that the vermagic string is wrong, set the version of your kernel exactly by editing the Makefile file in nano. Then you have to run through the entire make sequence again.

Anyway, have attached the autofs4.ko for kernel version 2.6.39.4-9
In theory you should be able to download and then do an insmod /your/downloaded/dir/autofs4.ko and it might work.

Maybe one of the pro's can comment what the risks of that procedure are... I am not sure.

Cheers
Frank

Re: Auto mounting / connecting USB disks

Posted: 01 May 2012, 07:37
by Gordon
Well, the issue here would be the reliability of the source of this file (i.e. You).

But yes, you are correct that the kernel source holds an error that causes the version magic to be incorrect. This is controlled by the Makefile and you should change that directly after pulling in the source (before doing anything else that will cause the wrong version to be stamped in generated scripts).

Re: Auto mounting / connecting USB disks

Posted: 01 May 2012, 15:25
by ryz
You could change the version when doing the make menuconfig since it is an configuration setting.
"General Setup -> Local version"

Re: Auto mounting / connecting USB disks

Posted: 24 Jan 2013, 11:46
by virus
Hi!
Need please some help by adding autofs into b3...
I installed autofs with errors and tried to fix them, but its wont work.
(im using google/ forum.excito search =>
http://forum.excito.net/viewtopic.php?p=7877
and
http://www.pixelbeat.org/docs/rebuild_k ... odule.html
but i dont know whats to do)

Than i tried to install amd from am-utils, but thats to complex for me. :oops:

I need to mount my esata (Dockingstation) only when i access this device (unmount time 2 seconds e.g.).
I`m edit the minidlna.conf

Code: Select all

media_dir=A,/home/storage/extern
media_dir=V,/home/storage/extern
media_dir=P,/home/storage/extern
media_dir=A,/home/storage/music
media_dir=V,/home/storage/video
media_dir=P,/home/storage/pictures
Now i can mount the esata on Webpage and start a scan with

Code: Select all

minidlna -R (more infos in debug mode "-d"
...
The scanner dont like one special bluray folder by scanning my HDDs, this one Bluray folder freez my B3. I moved this 20GB folder and the scan finished with no errors.

Now i need an Automounter thats start an "minidlna -R" on mounting too (e.g. command in fstab).
So please can anyone tell me step by step whats to do to get autofs running on an up to date b3?
I know how to configure autofs, thats not the problem...

Thank you very very well!
(sorry for my bad english!) :?


EDIT:
Hi Community,

is this way right?

Code: Select all

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.gz  (cat /proc/version says  2.6.39.4-11)
tar xzf linux-2.6.39.4.tar.gz
cd linux-2.6.39.4
cp /proc/config.gz .
gunzip config.gz
cp config .config
nano .config

# changes
CONFIG_AUTOFS_FS=m
CONFIG_AUTOFS4_FS=m

$ make modules
$ mkdir /lib/modules/2.6.39.4-11/kernel/fs/autofs  
$ mkdir /lib/modules/2.6.39.4-11/kernel/fs/autofs4
$ cp -v fs/autofs/autofs.ko /lib/modules/2.6.39.4-11/kernel/fs/autofs/autofs.ko (there is no file autofs.ko)
$ cp -v fs/autofs4/autofs4.ko /lib/modules/2.6.39.4-11/kernel/fs/autofs4/autofs4.ko (copy this file ok)

$ depmod -a                 (OK)
$ modprobe autofs4      (FATAL: Error inserting autofs4 (/lib/modules/2.6.39.4-11/kernel/fs/autofs4/autofs4.ko): Invalid module format) [WHATS WRONG HERE?]

$ /etc/init.d/autofs restart
Stopping automounter: done.
Starting automounter: done.

Maybe someone can help me to find my mistake...?!...

Thanks a lot!

Re: Auto mounting / connecting USB disks

Posted: 06 Feb 2014, 04:59
by lymon
Not an answer to the autofs problem, but maybe for others that are looking for a different way to automount USB/FLASH drives...

I use a udev rule to automount USB/FLASH drives without the need of autofs.

unfortunately the forum doesn't let me post the rule I am using...as my 'post looks too spamy for a new user'

Re: Auto mounting / connecting USB disks

Posted: 07 Feb 2014, 15:32
by Binkem
OK Lymon,

Now you're a normal user. Please post your stuff :)

Martijn

Re: Auto mounting / connecting USB disks

Posted: 10 Feb 2014, 02:56
by lymon
> Now you're a normal user. Please post your stuff

I tried, but I still can't post the code...still 'too spamy'

Re: Auto mounting / connecting USB disks

Posted: 10 Feb 2014, 09:11
by RandomUsername
+1 for using udev, it's very flexible. Long time ago before online backups I had a udev rule that, when I plugged in my external hard drive, it automatically triggered a script that backed up my /home/storage to the drive and then dismounted it again.

Re: Auto mounting / connecting USB disks

Posted: 10 Feb 2014, 15:32
by Binkem
Sorry Lymon,

The button on the moderator panel doesn't seem to work as I intend it to do. I guess you have to make some more posts and gain a normal usewr status.

Martijn

Re: Auto mounting / connecting USB disks

Posted: 11 Feb 2014, 05:25
by Gordon
I figured I'd take a look at that udev option and found some blog hinting this same solution for Arch Linux. I adapted the code to match the usual behaviour when mounting the disk through the B2|3 admin pages and made some modifications to support a USB cdrom device and use Windows character encoding on vfat.

Code: Select all

# /etc/udev/rules.d/10-automount.rules
 
# start at sdb to ignore the system hard drive
KERNEL!="sd[b-z]*", GOTO="automount_end"

# verify that the device contains media
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="automount_end"
 
# set some defaults
ENV{mount_path}="/home/storage/extern"
ENV{mount_options}="relatime"
ENV{file_system_type}="auto"

# import 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}="usb-%k"
 
# filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="$env{mount_options},codepage=850,iocharset=iso8859-1"

# can't use auto when mounting these file systems
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{file_system_type}="ntfs-3g"
ACTION=="add", ENV{ID_FS_TYPE}=="iso9660", ENV{file_system_type}="iso9660"

# create mountpoint and mount the filesystem
ACTION=="add", RUN+="/bin/mkdir -p '%E{mount_path}/%E{dir_name}'", RUN+="/bin/mount -t %E{file_system_type} -o %E{mount_options} /dev/%k '%E{mount_path}/%E{dir_name}'"
 
# clean up after device removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '%E{mount_path}/%E{dir_name}'", RUN+="/bin/rmdir '%E{mount_path}/%E{dir_name}'"
 
# exit
LABEL="automount_end"
Note that if you have an esata drive connected you should change the range [b-z] on the 4th line to [c-z]

Re: Auto mounting / connecting USB disks

Posted: 11 Feb 2014, 08:15
by lymon
yes, that's similar to the rule that I use.
Works like a charm

Re: Auto mounting / connecting USB disks

Posted: 11 Feb 2014, 14:46
by Gordon
I Agree. Worked just fine in the tests that I did (do not own a USB cdrom drive myself, so that part is kind of open). Must note though that pulling a USB device out before properly dismounting it, is not a really wise thing to do if you wrote any data to it while it was connected.