Results 1 to 10 of 12

Thread: Editing fstab for conditional nfs mounting

Hybrid View

  1. #1
    Join Date
    May 2010
    Beans
    75
    Distro
    Ubuntu 12.04 Precise Pangolin

    Editing fstab for conditional nfs mounting

    I shall explain my situation below. I have set up a small network of 3 computers in our lab with ubuntu 11.04 (32 bit). I am using nfs for file sharing. The server is set up such that when the clients boot up, server's home will be mounted as the home of the clients also. For this I have added the following:

    1) in server's /etc/exports:
    Code:
    /home clientIP(rw,sync,no_subtree_check)
    2) then restarted the nfs kernel server.

    3) Next is the contents of client's /etc/fstab:
    Code:
    # /etc/fstab: static file system information.
    #
    # Use 'blkid -o value -s UUID' to print the universally unique identifier
    # for a device; this may be used with UUID= as a more robust way to name
    # devices that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    proc            /proc           proc    nodev,noexec,nosuid 0       0
    # / was on /dev/sda6 during installation
    UUID=a33e6c76-f42f-4953-b93c-172160321ab2 /               ext4    errors=remount-ro 0       1
    # /boot was on /dev/sda1 during installation
    UUID=c05b9b15-ebcf-4945-b08d-34fede0e4273 /boot           ext4    defaults        0       2
    # /home was on /dev/sda7 during installation
    UUID=04d92ef1-6118-4ca2-8cee-77a69f2363dd /home           ext4    defaults        0       2
    # swap was on /dev/sda5 during installation
    UUID=8c09ada0-0d3c-44ed-a036-e96c04b08502 none            swap    sw              0       0
    /dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0
    
    # mount point for localhome
    UUID=04d92ef1-6118-4ca2-8cee-77a69f2363dd    /localhome    ext4    defaults    0    2
    
    #nfs mount from server
    server,sIP:/home    /home    nfs    nfsvers=3,_netdev,exec,dev,suid,rw    0       0
    ........................................

    The idea is to mount the home folder from server for all the users (user identification is made by suid option and new users are created with same uis and gid on both the server and the clients). Also in case the server is down or nfs mounting fails, the client(s) will mount the local home. And that's where the problem comes and I am at a loss what to do. If server is online, things work fine. For all users, the home will mount from the server. Also I have tested that anything saved locally can be accessed from the localhome. But in case server is down and i am trying to boot the clients, the following happens:
    1) The system will boot and the user login screen appears.
    2) After you login to a user with user name and password, the desktop does not come. Instead the following error messages will appear one by one:






    .........................
    And then the desktop is blank. I can not do anything!

    Now I know why these are coming. Because of the condition in fstab, if server is offline, nfs mounting of home fails. As such there is no home directory for the user 'installer' and the .ICEauthority is not available. If I go to recovery mode and do sudo mount -a it tells me: "mount.nfs: No route to host". I was thinking is there a way to write a script or program the boot or add an option in fstab such that:
    Try mouning home from server (by nfs mount).
    If home mounting from server (using nfs) fails, then mount the home folder from "UUID=04d92ef1-6118-4ca2-8cee-77a69f2363dd" which is mounted on the /home locally using the code below:
    [CODE]
    # /home was on /dev/sda7 during installation
    UUID=04d92ef1-6118-4ca2-8cee-77a69f2363dd /home ext4 defaults 0 2
    [CODE]
    I hope I have been able to explain my problem. Please help me quickly, anyone. Thanks in advance.
    Last edited by sd@ksu; February 24th, 2012 at 03:49 PM.

  2. #2
    Join Date
    Dec 2011
    Location
    The Netherlands
    Beans
    1,087
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Editing fstab for conditional nfs mounting

    I'd do it like this:
    Code:
    #!/bin/bash
    
    mount -t nfs server.local:/homeshare /home
    if [ $! != 0 ]
    then
      mount /<path_to_local_home_drive_or_partition> /home
    fi
    "Everything that has a beginning, has an end." --an unexpectedly wise wallpaper

  3. #3
    Join Date
    May 2010
    Beans
    75
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Editing fstab for conditional nfs mounting

    @ roelforg:
    Do yo want me to add these lines in my fstab ? Or a seperate script file ? Where do I keep that script file then so that it runs when the system boots ? I am relatively new in Linux, please pardon my ignorance.

  4. #4
    Join Date
    Dec 2011
    Location
    The Netherlands
    Beans
    1,087
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Editing fstab for conditional nfs mounting

    It's a bash script; make it run at boot right after the network has been started.
    Info about running at boot should be on the wiki.
    "Everything that has a beginning, has an end." --an unexpectedly wise wallpaper

  5. #5
    Join Date
    May 2010
    Beans
    75
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Editing fstab for conditional nfs mounting

    Can you please guide me to that page ?

  6. #6
    Join Date
    Dec 2011
    Location
    The Netherlands
    Beans
    1,087
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Editing fstab for conditional nfs mounting

    "Everything that has a beginning, has an end." --an unexpectedly wise wallpaper

  7. #7
    Join Date
    Jan 2013
    Beans
    1

    Re: Editing fstab for conditional nfs mounting

    Quote Originally Posted by roelforg View Post
    I'd do it like this:
    Code:
    #!/bin/bash
    
    mount -t nfs server.local:/homeshare /home
    if [ $! != 0 ]
    then
      mount /<path_to_local_home_drive_or_partition> /home
    fi
    For those ending up here in the future: that should be $? not $!

    (I am mounting a disk on through different mean (ntfs/cifs) depending on whether the Ubuntu is running natively or under a VM (in which it has no access to the partition. I managed to get it to work with the information from this topic, thanks!)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •