Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SCRIPT] autofs: browse nfs via a samba-like workgroup
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
-jk-
n00b
n00b


Joined: 18 Jan 2006
Posts: 2

PostPosted: Sat Jul 23, 2011 5:49 pm    Post subject: [SCRIPT] autofs: browse nfs via a samba-like workgroup Reply with quote

Background:
Before I used smbnetfs/fusesmb to share directories between 2 linux PCs. But the performance was quite low about 24-32Mb on a 1Gb netlink.
So I tested nfs and it was much faster 160Mb==20MB (near the max throughput of my hdds).
But I didn't wanted to hardlink all my exports (we are all lazy bastards ^^) and wrote this autofs script instead. May it be useful for others, too.

0.
You need avahi installed on both client & server
Code:
emerge net-dns/avahi -a

and autofs on the client
Code:
emerge net-fs/autofs -a


1.
on server
/etc/avahi/services/nfs.service:
Code:
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
       <type>_nfs._tcp</type>
       <port>2049</port>
</service>
</service-group>


on client
/etc/autofs/auto.nfs:
Code:
#!/bin/bash

protocol="IPv4"
opts="-fstype=nfs,hard,intr,timeo=5,rw"

NFS_HOSTS=`avahi-browse -tkrp _nfs._tcp`

EXPORTS=""

for line in $NFS_HOSTS; do
        NFS_HOST=(`echo ${line} | tr ';' '\n'`)

        if [ "${NFS_HOST[0]}" != "=" ]; then
                continue;
        fi

        PRT=${NFS_HOST[2]}
        if [ "$PRT" != "$protocol" ]; then
                continue;
        fi

        HOSTNAME=${NFS_HOST[3]}
        HOSTIP=${NFS_HOST[7]}

        NFS_EXPORTS=`showmount --no-headers -e $HOSTIP | sed 's/ .*//g'`
        for expline in $NFS_EXPORTS; do
                EXPORT=${expline[0]}
                BASENAME=`basename $EXPORT`
                EXPORTS="${EXPORTS}$EXPORT $HOSTIP $HOSTNAME $BASENAME \n"
        done
done

echo -e $EXPORTS | \
        awk -v opts="$opts" -- '
        BEGIN   { ORS=""; first=1 }
                { if (first) { print opts; first=0 }; if ($2) {print " \\\n\t/" tolower($3) "/" $4, $2 ":" $1} }
        END     { if (!first) print "\n"; else exit 1 }
        '
Code:
chmod +x /etc/autofs/auto.nfs


/etc/auto.master:
Code:
...
/var/autofs/nfs    /etc/autofs/auto.nfs   --timeout=30
...


2.
So now you can already browse your nfs `workgroup` via /var/autofs/nfs/foobar/$host/$exports. The `foobar` string/directory is a hack, you can put anything into it (it isn't used in the auto.nfs script!), but needed to get it working.
For easier usage you can now:
Code:
ln -s /var/autofs/nfs/workgroup/ /mnt/nfs

The advantage is we can even use tab-completion with it!

3.
Profit.


Last edited by -jk- on Mon Jul 25, 2011 9:53 am; edited 1 time in total
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sun Jul 24, 2011 1:22 pm    Post subject: Reply with quote

haven't tried it yet, but it looks really interesting, eventually avahi used for something!
_________________
The End of the Internet!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum