#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
#
# Make sure that the essential libraries can be found.
ISROOTDEV=""
{
cecho "\nERROR: stmsboot: $1"
#
# display recovery instructions - the first call logs to the service
# log and the second call displays on the console.
#
shcat $RECOVERFILE >/dev/msglog 2>&1
cecho "These instructions were also logged to the file $RECOVERFILE\n"
}
#
# root ("/") is already mounted read only by the kernel.
# Remount the root read-write.
#
{
HASZFSROOT=`$DF -g / |grep zfs`
RVAL=""
# In single-user maintenance mode, we don't have a writable
# root partition, so we _cannot_ use devlinks. Therefore we
# have to do some dancing - first mount the physical path
# read-write, then re-run $STMSBOOTUTIL to get the real
# devlink mapping, and then re-mount the root slice. Of course,
# if we all used ZFS this wouldn't be such a pain!
exec < $vfstab; readvfstab /
# ZFS root environments should _not_ have an entry for /
# ERROR - this would cause a failure later
# so let root know about it now and provide
# a chance to handle it before filesystem/usr
cecho "stmsboot: System has ZFS Root *and* an entry for / in /etc/vfstab\nstmsboot: Please remove the / entry from /etc/vfstab and then run\n# svcadm clear mpxio-upgrade"
exit 1
fi
else
# this is a bad state to be in, exit
cecho "Error: Your root device is not mapped."
exit 1
fi
mntopts='remount'
RVAL=`$MOUNT -m -F $fstype -o $mntopts $new_special \
# if we've got active-active paths to our rootvp and
# the first path returned by $STMSBOOTUTIL is not the
# same as the one we booted from, then we need some
# handwaving due to restrictions in the ufs module
# (see the remountfs() function in
if [ $? -eq 0 ]; then
# now re-run $STMSBOOTUTIL to get the real
# mapping for this device
# mount root for real
$MOUNT -o remount,rw $new_special / \
else
new_special="/devices${device}"
$new_special $mountp >/dev/msglog 2>&1
if [ $? -eq 0 ]; then
# success, break out
ISROOTDEVPATH=`$ECHO $device | \
break;
fi
done
cecho "Error: Unable to remount your root device"
exit 1;
fi
fi
fi
else
cecho "stmsboot: Error: your root slice is invalid"
exit 1
else
cecho "stmsboot: Root is on ZFS"
fi
fi
}
#
# mount /usr read only
#
{
exec < $vfstab; readvfstab "/usr"
ret_val=0
;;
;;
*)
;;
esac
#
# Must use -o largefiles here to ensure the read-only
# mount does not fail as a result of having a large
# file present on /usr.
#
mntopts='ro,largefiles'
else
fi
fi
# Requesting logging on a read-only mount
# causes errors to be displayed, so remove
# "logging" from the list of options.
fi
fi
# In case of a manual restart of the service, mount
# will emit messages if /usr is already mounted.
$MOUNT -m -F $fstype -o $mntopts $new_special /usr \
ret_val=$?
fi
fi
return $ret_val
}
# update system dump configuration
{
# Disable device-in-use checking (done in libdiskmgt).
# Without disabling this check, the configuration of dump device
# would fail as the device-in-use code incorrectly concludes that
# the device is in use and hence prevents configuration of the dump
# device.
export NOINUSE_CHECK
if [ -n "$4" ]; then
newname=`$STMSBOOTUTIL -m $4`
if [ $? -eq 0 ]; then
cecho "stmsboot: dump configuration \
has been updated."
else
mpxio_error "failed to configure \
the dump device.\nold \
dump device name: $4"
return 1
fi
fi
fi
else
# make sure we can get to it, force zfs to load fully
$LS $DUMPISZFS >>/dev/null 2>&1
cecho "stmsboot: dump on ZFS, no dumpadm update required"
fi
return 0
}
# Update bootpath for x86 here when we are enabling mpxio on root
{
if [ $? -ne 0 ]; then
cecho "stmsboot: ERROR! Unable to retrieve bootpath property\n"
exit 1
fi
# Since on x64 platforms the eeprom command doesn't update the
# kernel, the file /boot/solaris/bootenv.rc and the kernel's
# bootpath variable have a good chance of differing. We do some
# extra handwaving to get the correct bootpath variable setting.
fi
NEWBOOTPATH=""
for path in $cur_bootpath; do
mapped=`$STMSBOOTUTIL -p $path`
else
fi
fi
done
# now strip off leading and trailing space chars
new_bootpath=`echo $NEWBOOTPATH`
cecho "stmsboot: bootpath has been updated"
cecho ""
}
# Now do the actual work
{
# NOTE: If the first attempt to run the service has failed due to an
# expected error, users should be able to manually rerun the service.
#
# First mount /usr read only. This must be done to run
# utilities such as fsck and devfsadm.
# In the case of a manual rerun of the service, mounting of /usr here
# fails if /usr already happens to be mounted. It is better that we
# do not mount /usr if already mounted, but there seems to be no
# apparent way to check whether /usr is mounted or not as we mount
# explicitly checking for mount failures, we just do a sanity check
# by looking for some file (in this case devfsadm) in /usr.
#
if [ ! -s $DEVFSADM ]; then
mpxio_error "failed to mount the /usr filesystem."
return
fi
if mpxio_mount_root; then
# create /dev links
cecho "stmsboot: configuring devices"
fi
$STMSBOOTUTIL -u >/dev/msglog 2>&1
if [ $? -eq 0 ]; then
# handle active-active paths, where the probe order
# for the hba reports a different path to what the
# boot-device variable gives us
if [ $? -ne 0 ]; then
# we got a different path for root
exec < $SAVEDIR/vfstab.new; readvfstab /
fi
else
fi
cecho ""
cecho "stmsboot: vfstab has been updated"
if update_dumpconf; then
# update svm configuration to reflect new names
[ -x $METADEVADM ]; then
$METADEVADM -r >/dev/msglog 2>&1
fi
fi
# only update bootpath here for x86
fi
cecho "stmsboot: now regenerating boot archive"
else
mpxio_error "failed to update /etc/vfstab."
fi
if [ $usrmounted -eq 1 ]; then
cecho "stmsboot: rebooting the system now."
fi
else
mpxio_error "failed to mount the root filesystem."
fi
}