Product SiteDocumentation Site

3.13. Bind Mounts and File System Mount Order

When you use the bind option of the mount command, you must be sure that the file systems are mounted in the correct order. In the following example, the /var/log directory must be mounted before executing the bind mount on the /tmp directory:
# mount --bind /var/log /tmp
The ordering of file system mounts is determined as follows:
If your configuration requires that you create a bind mount on which to mount a GFS2 file system, you can order your fstab file as follows:
  1. Mount local filesystems that are required for the bind mount.
  2. Bind mount the directory on which to mount the GFS2 file system.
  3. Mount the GFS2 file system.
If your configuration requires that you bind mount a local directory or file system onto a GFS2 file system, listing the file systems in the correct order in the fstab file will not mount the file systems correctly since the GFS2 file system will not be mounted until the GFS2 init script is run. In this case, you should write an init script to execute the bind mount so that the bind mount will not take place until after the GFS2 file system is mounted.
The following script is an example of a custom init script. This script performs a bind mount of two directories onto two directories of a GFS2 filesystem. In this example, there is an existing GFS2 mount point at /mnt/gfs2a, which is mounted when the GFS2 init script runs, after cluster startup.
In this example script, the values of the chkconfig statement indicate the following:
The start and stop values indicate that you can manually perform the indicated action by executing a service start and a service stop command. For example, if the script is named fredwilma, then you can execute service fredwilma start.
This script should be put in the /etc/init.d directory with the same permissions as the other scripts in that directory. You can then execute a chkconfig on command to link the script to the indicated run levels. For example, if the script is named fredwilma, then you can execute chkconfig fredwilma on.

#!/bin/bash
#
# chkconfig: 345 29 73
# description: mount/unmount my custom bind mounts onto a gfs2 subdirectory
#
#
### BEGIN INIT INFO
# Provides: 
### END INIT INFO

. /etc/init.d/functions
case "$1" in
  start)
	# In this example, fred and wilma want their home directories
	# bind-mounted over the gfs2 directory /mnt/gfs2a, which has
	# been mounted as /mnt/gfs2a
	mkdir -p /mnt/gfs2a/home/fred &> /dev/null
	mkdir -p /mnt/gfs2a/home/wilma &> /dev/null
	/bin/mount --bind /mnt/gfs2a/home/fred /home/fred
	/bin/mount --bind /mnt/gfs2a/home/wilma /home/wilma
        ;;

  stop)
	/bin/umount /mnt/gfs2a/home/fred
	/bin/umount /mnt/gfs2a/home/wilma
        ;;

  status)
        ;;

  restart)
        $0 stop
        $0 start
        ;;

  reload)
        $0 start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0