...
If it is configured with file system(s) to that should be mounted at boot there are special considerations for two solutions dpending on whether the file systems should be fscked ...
/etc/fstab (fsck not possible)
/etc/fstab is used in the usual way with some special considerations:
- LABEL or UUID must be used . This is in case the /dev/sd[a-z]+ name assigned by udev changes from boot to boot.
- The options must include _netdev. This ensures that mounting is deferred until the networking daemons (including open-iscsi) are running.
- The sixth field (fs_passno) must be set to 0. This disables fsck when mounting via fstab is processed, necessary because the devices are not created until later, when the open-iscsi boot script runs.
/etc/fstab-iscsi (fsck possible)
Create /etc/fstab-iscsi, based on this sample. The UUID can be found using the blkid command while the iSCSI-backed device is present:
# This is the configuration file for /etc/init.d/mountscsi.sh
# This file follows the same format as /etc/fstab.
# First column: it is strongly recommended that UIDs or LABELs are used.
# dump column: values may be omitted; if they are present they are ignored.
# pass column: 0 disables fsck; any other value (conventionally 1) enables it.
# <special> <mount point> <type> <options> <dump> <pass>
UUID=ff17c31e-eaff-4b49-b5f9-39ec81892e70 /mnt/hd/iSCSI jfs defaults 1
Install /etc/init.d/mountscsi.sh
by creating the file with read and execute permission for root and writeable only by root (sorry about the formatting; apparently I can't drive Confluence WIKI) ....
No Format |
---|
#! /bin/bash ### BEGIN INIT INFO # Provides: mountiscsi # Required-Start: open-iscsi # Required-Stop: # Default-Start: S # Default-Stop: # Short-Description: Mounts file systems based on iSCSI-backed devices # Description: Mounts file systems based on iSCSI-backed devices. # As far as practicable, does with /etc/fstab-iscsi what # mountall.sh does |
...
with /etc/fstab.
# In this version only ext* and JFS file systems are
# supported with fsck before mount.
### END INIT INFO
# Author: Charles Atkinson <c@charlesmatkinson.org>
. /lib/init/vars.sh
. /lib/lsb/init-functions
regex='^#|^$'
shopt -s extglob
do_start () {
log_begin_msg "Mounting iscsi-backed filesystems"$'\n'
my_fstab=/etc/fstab-iscsi
[[ -r $my_fstab ]] || { log_failure_msg "Cannot read $my_fstab" exit 1; }
# For each line of my fstab
mount_fail=0
line_n=0
while read -r special mountpoint type options dump pass spurious
do
((line_n++))
[[ $special =~ $regex ]] && continue
[[ $pass = '' ]] && pass=$dump
if [[ $spurious != '' ]]; then
log_warning_msg "Spurious data on line $line_n of $my_fstab: $spurious"
continue
fi
# Normalise the special value
if [[ $special =~ ^LABEL= || $special =~ ^UUID= ]]; then
buf=$(findfs "$special" 2>&1)
if (($?>0)); then
log_warning_msg "Cannot find the file system corresponding to '$special'"
continue
fi
special_norm=$buf
elif [[ $special =~ ^/dev/ ]]; then
buf=$(readlink --canonicalize -- "$special" 2>&1)
if (($?>0)); then
log_warning_msg "Problems running readlink for $special: $buf"
continue
fi
special_norm=$buf
else
log_warning_msg "Invalid special on $my_fstab, line $line_n: $special"
continue
fi
#echo "DEBUG: special:$special, mountpoint:$mountpoint,type:$type,options:$options, pass:$pass" >&2
# Check for existing mounts
mounted_flag=0
while read -r pm_fs_spec pm_mountpoint _
do
if [[ $pm_fs_spec = $special_norm ]]; then
mounted_flag=1
log_warning_msg "$special_norm is already mounted on $pm_mountpoint"
fi
done < <(cat /proc/mounts)
# Run file system check if possible and indicated
if ((mounted_flag==0)); then
fsck_flag=0
case $type in
ext* )
tune2fs_out=$(tune2fs -l "$special_norm" 2>&1)
if (($?>0)); then
log_warning_msg "Can't list $special_norm file system parameters: $tune2fs_out"
continue
fi
buf=${tune2fs_out##*Filesystem state:*( )}
filesystem_state=${buf%%$'\n'*}
[[ $filesystem_state != clean ]] && fsck_flag=1
#echo "DEBUG: filesystem_state:$filesystem_state" >&2
buf=${tune2fs_out##*Maximum mount count:*( )}
max_mount_count=${buf%%$'\n'*}
buf=${tune2fs_out##*Mount count:*( )}
mount_count=${buf%%$'\n'*}
((mount_count>max_mount_count)) && fsck_flag=1
#echo "DEBUG: max_mount_count:$max_mount_count, mount_count:$mount_count" >&2
buf=${tune2fs_out##*Check interval:*( )}
check_interval=${buf%% *}
#echo "DEBUG: check_interval:$check_interval" >&2
if ((check_interval>0)); then
buf=${tune2fs_out##*Last checked:*( )}
last_checked=${buf%%$'\n'*}
#echo "DEBUG: last_checked:$last_checked" >&2
last_checked_secs=$(date "--date=$last_checked" +%s)
now=$(date +%s)
#echo "DEBUG: last_checked_secs:$last_checked_secs, now:$now" >&2
(((now-last_checked_secs)>check_interval)) && fsck_flag=1
fi
;;
jfs )
jfs_tune_out=$(jfs_tune -l "$special_norm")
if (($?>0)); then
log_warning_msg "Can't list file system parameters: $jfs_tune_out"
continue
fi
buf=${jfs_tune_out##*JFS state:*([[:space:]])}
jfs_state=${buf%%$'\n'*}
#echo "DEBUG: jfs_state:$jfs_state" >&2
[[ $jfs_state != clean ]] && fsck_flag=1
;;
esac
if ((fsck_flag==1)); then
# fsck option -p is OK for fsck.ext[234] and for jfs_fsck`
fsck -Tp "$special_norm"
fi
fi
# Mount
mount -t $type -o $options $special $mountpoint || mount_fail=1
done < <(cat "$my_fstab")
if ((mount_fail==0)); then
exit 0
else
exit 1
fi
}
case "$1" in
start)
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop|"")
# No-op
;;
*)
echo "Usage: mountiscsi.sh start" >&2
exit 3
;;
esac |
... and creating the required symlinks:
update-rc.d mountiscsi.sh defaults
That will generate two "do not match LSB Default" warnings which can be ignored.
Normal operations
In normal operations the client/initiator should be shut down before the server/target. Doing otherwise will result in a delayed shutdown by the client/initiator.
...