Attaching a directory to a different part of the tree at boot time

Most machines on the network access a certain directory via an nfs share. However the machine on which the directory is actually located cannot use the nfs share. In order that the directory should appear to be in the same place on every machine it was necessary to force the file server to remap the directory to a different place on its own directory tree.

Content revision history:
Article first written, spring 2004

Deployed on a system running SuSE GNU/Linux 8.1:

During system boot, the mount utility uses the fstab file to decide how the various block devices should be arranged within the overall directory tree. However this method of mounting does not allow a directory to be relocated within the tree so that it now appears in two different places. The mount program can do this sort of relocation but not via the fstab file.

Instead a short script was created:

#! /bin/sh
#
# LSB compatible service control script; see http://www.linuxbase.org/spec/
# 
### BEGIN INIT INFO
# Provides:          remount_local_fs
# Required-Start:    $syslog $local_fs
# Required-Stop:     
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Short-Description: Remount certain directories
# Description:       Remount certain directories so that they appear to be,
#       on the server at the same locations in the filesystem that they 
#       appear to be on the clients.
### END INIT INFO

. /etc/rc.status

rc_reset
case "$1" in
    start)
        echo "Providing new mount points for certain local file systems"

		mount   --bind   /PublicSpaces/FS2   /mnt/FS2
;; stop) echo "Removing new mount points for certain local file systems" umount  --bind   /mnt/FS2
;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac rc_exit
Penguin tangled in boot laces
If the boots don't fit, they're probably not yours.

This script exists on machine 192.168.0.31.The two directories mentioned in the script, /PublicSpaces/FS2 and /mnt/FS2, must also exist on that same machine.

When this script is executed on machine 192.168.0.31, the directory /PublicSpaces/FS2 will also be accessible as /mnt/FS2 and hence will appear to be in the same place as it is on all the other networked machines that mount the directory through fstab. The above script was called “remount_local_fs” and it was placed into the /etc/init.d directory. Next it is necessary to create symbolic links to this script and place them in the appropriate /etc/init.d/rcX.d directories.

The creation of the symbolic links should NOT be done manually. Instead the YaST program should be used to create them since this will ensure that they are given the correct place in the sequence.

To create the symbolic links, start YaST and choose: system — run-level editor — run-level properties. This should display a list of all the possible scripts, including the one just created. Now choose which run levels it should be started in. In this case we want it to be active in run-levels 2, 3 and 5 so those three boxes should be checked. Finally, choose the option to finish the changes and YaST will create the necessary symbolic links in the three directories: /etc/init.d/rc2.d, /etc/init.d/rc3.d and /etc/init.d/rc5.d. With these changes made, the directory is correctly relocated every time the system boots.

For completeness of this information, the fstab line used on the OTHER machines reads:

192.168.0.31:/PublicSpaces/FS2   /mnt/FS2   nfs   rw,hard,intr   0  0

Thus all machines see the shared directory at /mnt/FS2.

 

Navigation: (site map) learn linux home pagetechnical articles