From Wiki-UX.info

Wiki-UX / Common Internet File System / How to mount CIFS shares during system boot
Jump to: navigation, search

How to mount CIFS shares during system boot

Abstract

This article explains how to create an init rc script to mount custom CIFS shares during system boot on a HP-UX 11i Operating Environment. Alternative, you can modify the /etc/fstab to declare the entries but this discourage because it may block the system boot due to network problems.

Procedure

1. Copy the following initialization script under /sbin/init.d/cifsmount.

#!/sbin/sh
#
# @(#)B.11i
#
# NOTE:    This script is not configurable!  Any changes made to this
#          script will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
 
#
# Automatically mount CIFS remote shares during system boot.
#
 
# Allowed exit values:
#       0 = success; causes "OK" to show up in checklist.
#       1 = failure; causes "FAIL" to show up in checklist.
#       2 = skip; causes "N/A" to show up in the checklist.
#           Use this value if execution of this script is overridden
#           by the use of a control variable, or if this script is not
#           appropriate to execute for some other reason.
#       3 = reboot; causes the system to be rebooted after execution.
#       4 = background; causes "BG" to show up in the checklist.
#           Use this value if this script starts a process in background mode.
 
# Input and output:
#       stdin is redirected from /dev/null
#
#       stdout and stderr are redirected to the /etc/rc.log file
#       during checklist mode, or to the console in raw mode.
 
PATH=/usr/sbin:/usr/bin:/sbin
export PATH
 
# NOTE: If your script executes in run state 0 or state 1, then /usr might
#       not be available.  Do not attempt to access commands or files in
#       /usr unless your script executes in run state 2 or greater.  Other
#       file systems typically not mounted until run state 2 include /var
#       and /opt.
 
rval=0
 
# Check the exit value of a command run by this script.  If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.
 
set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1  # script FAILed
        fi
}
 
case $1 in
'start_msg')
        echo "Mounting the CIFS remote file systems"
        ;;
 
'stop_msg')
        echo "Unmounting the CIFS remote file systems"
        ;;
 
'start')
 
        # source the system configuration variables
        if [ -f /etc/rc.config.d/cifsmount ] ; then
                . /etc/rc.config.d/cifsmount
        else
                echo "ERROR: /etc/rc.config.d/cifsmount defaults file MISSING"
        fi
 
        # Check to see if this script is allowed to run...
        if [ "$CIFS_MOUNT" != 1 ]; then
                rval=2
        else
 
        # Execute the commands to mount the CIFS shares
	# Example:
	# cifsmount -s -U <username> -D <domain> -P <password> -I <ip address> <remote share> <mount point>cifsmount -s -U <username> -D <domain> -P <password> -I <ip address> <remote share> <mount point>
 
        fi
        ;;
 
'stop')
        # source the system configuration variables
        if [ -f /etc/rc.config.d/cifsmount ] ; then
                . /etc/rc.config.d/cifsmount
        else
                echo "ERROR: /etc/rc.config/cifsmount defaults file MISSING"
        fi
 
        # Check to see if this script is allowed to run...
        if [ "$CIFS_MOUNT" != 1 ]; then
                rval=2
        else
 
        # Execute the commands to unmount the CIFS shares
        # Use "cifsmount -a" if your current CIFS installation support this flag
	# else use "umount <mount point>
	# cifsmount -a
 
        fi
        ;;
 
*)
        echo "usage: $0 {start|stop|start_msg|stop_msg}"
        rval=1
        ;;
esac
 
exit $rval

2. Set the recommeded permissions of the rc script.

# chown bin:bin /sbin/init.d/cifsmount
# chmod 0555 /sbin/init.d/cifsmount

3. Create a "system configuration variable" file that containts the startup control variable. Set the required permissions.

# echo "CIFS_MOUNT=1" > /etc/rc.config.d/cifsmount
# chown bin:bin /etc/rc.config.d/cifsmount
# chmod 0444 /etc/rc.config.d/cifsmount

4. Modify the script "start" case option to add your remote CIFS shares.

.
.
.
'start')
 
        # source the system configuration variables
        if [ -f /etc/rc.config.d/cifsmount ] ; then
                . /etc/rc.config.d/cifsmount
        else
                echo "ERROR: /etc/rc.config.d/cifsmount defaults file MISSING"
        fi
 
        # Check to see if this script is allowed to run...
        if [ "$CONTROL_VARIABLE" != 1 ]; then
                rval=2
        else
 
        # Execute the commands to mount the CIFS shares
	# Example:
	# cifsmount -s -U <username> -D <domain> -P <password> -I <ip address> <remote share> <mount point>cifsmount -s -U <username> -D <domain> -P <password> -I <ip address> <remote share> <mount point>
	cifsmount -s -U myusername -D mydomain.com -P myPassWord -I 192.168.0.100 //shares/myshare /cifs_share1
	cifsmount -s -U myusername -D mydomain.dom -P myPassword -I 192.168.0.101 //shares/myshare /cifs_share2
 
        fi
        ;;
.
.
.

5. Modify the script "stop" case option to add your remote CIFS shares umount.

.
.
.
'stop')
        # source the system configuration variables
        if [ -f /etc/rc.config.d/cifsmount ] ; then
                . /etc/rc.config.d/cifsmount
        else
                echo "ERROR: /etc/rc.config/cifsmount defaults file MISSING"
        fi
 
        # Check to see if this script is allowed to run...
        if [ "$CIFS_MOUNT" != 1 ]; then
                rval=2
        else
 
        # Execute the commands to unmount the CIFS shares
        # Use "cifsmount -a" if your current CIFS installation support the flag
	# else use "umount <mount point>
	# cifsmount -a
 
	umount /cifs_share1
	umount /cifs_share1
 
        fi
        ;;
.
.
.

6. Soft link the the cifsmount script to a proper startup sequence, normally under /sbin/init.d/rc3.d. Use the reverse numbering scheme to link the stop version. Remember to use the [ 1000 - Start value ] formula to choose the killing script secuence number.

For example, to mount the CIFS during the init 3 transition just after starting the NFS server, use the following method:

# ls /sbin/rc3.d/*
/sbin/rc3.d/S100nfs.server     /sbin/rc3.d/S823hpws_tomcat    /sbin/rc3.d/S870hpsmhd
/sbin/rc3.d/S200tps.rc         /sbin/rc3.d/S823hpws_webmin    /sbin/rc3.d/S990dtlogin.rc
/sbin/rc3.d/S800cmcluster      /sbin/rc3.d/S823hpws_webproxy  /sbin/rc3.d/S99prngd.rc
/sbin/rc3.d/S823hpws_apache    /sbin/rc3.d/S823hpws_xmltools

The script will be run between "S100nfs.server" and "S200tps.rc" initialization script, for example, using the S150 sequence.

# ln -s /sbin/init.d/cifsmount /sbin/rc3.d/S150cifsmount

The killing script when transition to init 2 will be K850 (1000 - 150).

# ln -s sbin/init.d/cifsmount /sbin/rc2.d/K850cifsmount

That way, the overall file system layout for the script will be:

# find /sbin -name "*cifsmount" -exec ll {} \;
-r-xr-xr-x   1 bin        bin           4426 Aug 26 12:59 /sbin/init.d/cifsmount
lrwxrwxrwx   1 root       sys             21 Aug 26 14:22 /sbin/rc2.d/K850cifsmount -> sbin/init.d/cifsmount
lrwxrwxrwx   1 root       sys             22 Aug 26 14:22 /sbin/rc3.d/S150cifsmount -> /sbin/init.d/cifsmount

Authors

This page was last modified on 30 July 2010, at 03:16. This page has been accessed 4,019 times.