Announcement

Collapse
No announcement yet.

HOWTO: BIND mounts and NFS exporting of combined directories

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HOWTO: BIND mounts and NFS exporting of combined directories

    I have a media server with four hard drives. There are 3 relevant partitions for this setup.

    Partition "A" contains 8 subdirectories of various sorts.
    Partition "B" contains videos other than movies in 7 subdirectories.
    Partition "C" contains only movies and has 20 subdirectories.

    They all also contain some files in their root directory

    I wish to export all these partitions via NFS and their subdirectories with a single export I call "shared" and have all of the partitions subdirectories available. Since I access this data through numerous services (Roku, media computers, DLNA devices) the directory structure is critical. I don't want to combine all the partitions using formatting (raid, LVM or btrfs) for data backup and loss prevention reasons.

    SymLinking directories works using SAMBA but is problematic for NFS so I want to use bind mounts for stability.

    The three partitions are mounted, then you bind the mounts and export them. The tree structure I desire:

    /shared --> All partition "A" files and subdirectories
    --> /Videos
    --> All partition "B" files and subdirectories
    --> /Movies
    -->All partition "C" files and subdirectories

    The reason really stems from the Roku box. The "Channel" I use to watch my recorded movies and TV Shows is called RoksBox. It streams directly from the media server, but you can only link it to one primary directory for videos, one for music, and one for photos. It can navigate subdirectories fine but only one primary directory for videos. So if I have Videos and Movies in different locations, I can only use one. Basically - the primary video directory is Videos with Movies, TV Shows, Family Videos, etc under it. This allows the RoxsBox to access all the vids. I like all the subdirectories because I have several hundred (so far ) video files and some structure is helpful.

    The computers aren't a problem because they're all linux, so they can handle what ever setup I use - although mounting four or five NFS shares on five computers is tasking. The DLNA server is more configurable than RoksBox so it's really not a factor - it'll do pretty much whatever I want too.

    On the server:

    Mount the three partitions:
    in /etc/fstab:
    Code:
    /dev/sdc  /mnt/movies  btrfs  defaults,space_cache,compress  0    2
    /dev/sda6 /mnt/videos  btrfs  defaults,space_cache,compress  0    2
    /dev/sda5 /mnt/shared  ext4  rw,data=writeback,noatime,errors=remount-ro 0  2

    Create mount points for bind mounts

    The trick here is to remember your directories will be will be remounted so the mount point directories have to mimic the target structure;
    Code:
    sudo mkdir /media
    sudo mkdir /mnt/shared/Videos
    sudo mkdir /mnt/videos/Movies
    Bind mounts
    in /etc/fstab:
    Code:
    #
    # BIND mounts for NFS shares
    #
    /mnt/shared /media bind bind
    /mnt/videos /media/Videos bind bind
    /mnt/movies /media/Videos/Movies bind bind
    This creates my desired structure:
    /media/Videos/Movies contains /mnt/movies,
    /media/Videos contains /mnt/videos and the Movies subdirectory as above,
    /media contains /mnt/shared and the two subdirectories above.

    Now to get all this properly exported via NFS you have to

    Export all the bind subdirectories
    and the "root" bind directory separately:
    in /etc/exports (not relevant options replaced with ... ):
    Code:
    /media 192.168.1.0/255.255.255.0(rw,fsid=0,nohide...)
    /media/Videos 192.168.1.0/255.255.255.0(rw,nohide...)
    /media/Videos/Movies 192.168.1.0/255.255.255.0(rw,nohide...)
    The real important bit here is the fsid=0 which tells the server that this is the "root" file system of the /media exports.

    On the NFS Client:
    You need only mount the "root" export and all the subdirectories follow with it automagically!
    in /etc/fstab:
    Code:
    server://media /shared nfs auto,intr,users,rw,rsize=32768,wsize=32768 0    0
    Now I can keep my stuff well organized and point the Roku RoksBox channel at /media/Videos like before and my other computers need only a single mount to access all the files and directories.

    Please Read Me
Working...
X