Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Featured

Remounting Active NFS Filesystems

Submitted by on January 23, 2013 – 12:57 pm

Here’s a scenario: you have an NFS client mounting a filesystem from server1. You need to migrate this data to NFS server2 and remount the filesystem from the client to point to the new server. The problem is that there is a user application on the client system that uses the NFS mount, preventing you from unmounting it.

The process described below will not always work. It relies on temporarily halting the processes that use the NFS mount and whether or not an application can handle a pause depends on the application. But it may be worth a try: if it works and you are migrating multiple filesystems, this approach can save your customers a lot of downtime.

In this example we have /mnt/tmp NFS-mounted from NetApp. We need to move it to EMC NFS server. I added an entry for the EMC Celerra to the fstab, but, for now, left it commented out:

[root@copland ~]# grep netapp /etc/fstab

//netapp04/tmp              /mnt/tmp    cifs    credentials=/root/cifs_credentials,auto
#celerra01:/netapp04_tmp /mnt/tmp        nfs     defaults        0 0

Running df shows that /mnt/tmp is currently mounted on NetApp:
[root@copland ~]# df -hP | grep netapp

//netapp04/tmp     8.0G  6.7G  1.4G  83% /mnt/tmp

To simulate a user process accessing a filesystem, we will start an infinite loop for a find command running against the /mnt/tmp filesystem:
[root@copland ~]# while [ 1 ] ; do find /mnt/tmp -type f -exec ls -als {} ; ; done < /dev/null > /dev/null 2>&1 &
[1] 28902

Note the PID: we will use it later. Running lsof for /mnt/tmp shows the find command running:
[root@copland ~]# lsof /mnt/tmp
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
find    28903 root  cwd    DIR   0,22        0 803308 /mnt/tmp/Test/6009398

Notice that the PID reported by lsof (28903) is for the child process (the find command itself). The PID shown above (28902) is for the while loop. We will need to pause both of them:
[root@copland ~]# kill -STOP 28902 28903

Hitting the enter key will show that the while loop we started earlier has been stopped:
[root@copland ~]#
[1]+  Stopped                 while [ 1 ]; do
    find /mnt/tmp -type f -exec ls -als {} ;;
done < /dev/null > /dev/null 2>&1

Now we will update the fstab to switch the target NFS server for the /mnt/tmp mountpoint:
[root@copland ~]# grep netapp /etc/fstab

#//netapp04/tmp              /mnt/tmp    cifs    credentials=/root/cifs_credentials,auto
celerra01:/netapp04_tmp /mnt/tmp        nfs     defaults        0 0

The next step is to do a lazy unmount and remount for /mnt/tmp:
[root@copland ~]# umount -l /mnt/tmp ; mount /mnt/tmp

Running the df command for /mnt/tmp shows that now it is mounted on the EMC NFS server:
[root@copland ~]# df -hP | grep netapp
celerra01:/netapp04_tmp 9.9G  9.1G  772M  93% /mnt/tmp

The last step is to resume the while loop with the find command it was running. The process picks up where it left of without having any indication that we switched storage on it:
[root@copland ~]# kill -CONT 28902 28903

As mentioned before, this approach may not work for just any application. You will need to test this process with your user applications before trying to implement the method on a production system.

Print Friendly, PDF & Email

Leave a Reply