Linux NFS Remote Filesystem
Post # 67 permalink Topic #67 by mreschke on 2008-05-20 21:59:05 (viewed 974 times)

Linux has several protocols to share and access files on your LAN. NFS is the most common solution, but does not allow windows computer to connect to your NFS file sharing server. If you want a windows client to connect to your linux server over a LAN, setup Samba. See Linux Networking with Samba and Samba in Ubuntu. For best results your linux server should have both NFS and Samba running, so linux clients can use NFS and windows clients can use Samba.

NFS Server[-][- -][++]

  1. Install NFS Server
    1. For Debian Based Systems sudo apt-get install nfs-common nfs-kernel-server
    2. For ArchLinux sudo pacman -S nfs-utils rpcbind
  2. Create and Export NFS Shares
    1. Edit /etc/exports _
      /etc/exports
      /home 192.168.1.0/255.255.255.0(sync,no_subtree_check,no_root_squash,rw,insecure)
      
    2. Export everything in /etc/exports with sudo exportfs -a

NFS Client[-][- -][++]

  1. Install NFS Client
    1. For Debian Based Systems sudo apt-get install nfs-common
    2. For ArchLinux sudo pacman -S nfs-utils rpcbind
  2. Mount the NFS Shares
    1. Manual Mount with sudo mount yourserver:/home /mnt/somefolder
    2. Auto mount on boot by editing /etc/fstab with yourserver:/home /mnt/somefolder nfs nolock,defaults 0 0

Export NFS folder with other mounts in it[-][- -][++]

Best described with an example. I have 2 hard drives. One is a 1.5TB main drive (actually 3x750GB raid5), the other is a single 2TB drive which holds downloads, movies and backups. I want everything to show up in /nwq. The main drive is mounted to /nwq. Inside nwq I have blank folders /nwq/admin/mnt/deezteez, /nwq/pub/downloads, /nwq/pub/movies. I mount the 2TB drive to /nwq/admin/mnt/deezteez. Now instead of making a symbolic soft link from /nwq/admin/mnt/deezteez/pub/movies to /nwq/pub/movies (because links are not accepted everywhere), I use bind mounts. So I mount --bind /nwq/admin/mnt/deezteez/pub/movies to /nwq/pub/movies and same with downloads. So now /nwq/pub/movies and /nwq/pub/downloads seem like regular folders in /nwq. Which is absolutely perfect, just what I want, no links.

Now I want to have a single NFS export of /nwq and everything in it, including the bound folder mounts. By default NFS will not export mounted folders. So when I mount the /nwq over NFS from the client computer, /nwq/pub/movies and downloads are empty and so is /nwq/admin/mnt/deezteez. To solve this problem, you need to export each mounted folder with the nohide option.
Notice what I call /nwq above is actually /home, /nwq is just a link to /home for legacy and shorthand purposes

/etc/exports on NFS Server
#mReschke
#Found nohide is what I want to show folders of mounted drives, like deezteez
/home                   192.168.12.0/255.255.255.0(sync,no_subtree_check,no_root_squash,rw,insecure)
/home/admin/mnt/deezteez 192.168.12.0/255.255.255.0(sync,no_subtree_check,no_root_squash,rw,insecure,nohide)
/home/pub/downloads 192.168.12.0/255.255.255.0(sync,no_subtree_check,no_root_squash,rw,insecure,nohide)
/home/pub/movies 192.168.12.0/255.255.255.0(sync,no_subtree_check,no_root_squash,rw,insecure,nohide)
/home/admin/bak/systems 192.168.12.0/255.255.255.0(sync,no_subtree_check,no_root_squash,rw,insecure,nohide)

/etc/fstab on NFS Server
# /nwq was on /dev/md1 during installation
UUID=e30921a3-6d0a-4d2e-b7c2-c497a85b8514 /home           ext4    defaults,acl    0       2
# deezteez 2TB drive (no raid)
UUID=e267bbde-eebe-4b09-958f-b4f9258de937 /home/admin/mnt/deezteez ext4    defaults,acl    0       3
/home/admin/mnt/deezteez/pub/downloads /home/pub/downloads bind defaults,bind 0 0
/home/admin/mnt/deezteez/pub/movies /home/pub/movies bind defaults,bind 0 0
/home/admin/mnt/deezteez/admin/bak/systems /home/admin/bak/systems bind defaults,bind 0 0

/etc/fstab on NFS Client
#Mount qserver
qserver:/home /nwq nfs nolock,defaults 0 0

Resources[-][- -][++]