5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
25 # Copyright 2016 Nexenta Systems, Inc.
28 .
/lib
/svc
/share
/fs_include.sh
29 .
/lib
/svc
/share
/net_include.sh
31 # Make sure that the essential libraries can be found.
32 LD_LIBRARY_PATH
=/lib
; export LD_LIBRARY_PATH
33 STMSBOOTUTIL
=/lib
/mpxio
/stmsboot_util
35 BOOTDEVICES
=$SAVEDIR/boot-devices
36 RECOVERFILE
=$SAVEDIR/recover_instructions
37 DEVFSADM
=/usr
/sbin
/devfsadm
38 DUMPADM
=/usr
/sbin
/dumpadm
55 EEPROM
=/usr
/sbin
/eeprom
56 BOOTADM
=/usr
/sbin
/bootadm
57 SVCADM
=/usr
/sbin
/svcadm
58 REBOOT
=/usr
/sbin
/reboot
62 cecho
"\nERROR: stmsboot: $1"
64 # display recovery instructions - the first call logs to the service
65 # log and the second call displays on the console.
68 shcat
$RECOVERFILE >/dev
/msglog
2>&1
69 cecho
"These instructions were also logged to the file $RECOVERFILE\n"
73 # root ("/") is already mounted read only by the kernel.
74 # Remount the root read-write.
78 HASZFSROOT
=`$DF -g / |grep zfs`
81 # In single-user maintenance mode, we don't have a writable
82 # root partition, so we _cannot_ use devlinks. Therefore we
83 # have to do some dancing - first mount the physical path
84 # read-write, then re-run $STMSBOOTUTIL to get the real
85 # devlink mapping, and then re-mount the root slice. Of course,
86 # if we all used ZFS this wouldn't be such a pain!
87 exec < $vfstab; readvfstab
/
88 # ZFS root environments should _not_ have an entry for /
89 # in their /etc/vfstab.
90 if [ -n "$special" ]; then
91 # sanity check for ZFSRoot _and_ / in /etc/vfstab
92 if [ -n "$HASZFSROOT" ]; then
93 # ERROR - this would cause a failure later
94 # so let root know about it now and provide
95 # a chance to handle it before filesystem/usr
96 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"
99 ISPHYS
=`echo $special |$AWK '/^\/dev\/dsk/ {print}'`;
100 if [ -z "$ISPHYS" ]; then
101 # a metadevice, /dev/vx
103 $MOUNT -o remount
,rw
$new_special / >/dev
/msglog
2>&1
105 new_special
=`$STMSBOOTUTIL -m $special`
106 if [ "$new_special" = "NOT_MAPPED" ]; then
107 # this is a bad state to be in, exit
108 cecho
"Error: Your root device is not mapped."
111 checkopt
"llock" $mntopts
113 [ -n "$otherops" ] && mntopts
="${mntopts},${otherops}"
114 RVAL
=`$MOUNT -m -F $fstype -o $mntopts $new_special \
115 $mountp >/dev/msglog 2>&1`
116 # if we've got active-active paths to our rootvp and
117 # the first path returned by $STMSBOOTUTIL is not the
118 # same as the one we booted from, then we need some
119 # handwaving due to restrictions in the ufs module
120 # (see the remountfs() function in
121 # $SRC/uts/common/fs/ufs/ufs_vfsops.c)
122 if [ $?
-eq 0 ]; then
123 # now re-run $STMSBOOTUTIL to get the real
124 # mapping for this device
125 new_special
=`$STMSBOOTUTIL -m $special`
126 # mount root for real
127 $MOUNT -o remount
,rw
$new_special / \
130 for device
in `$CAT $BOOTDEVICES`; do
131 new_special
="/devices${device}"
132 $MOUNT -m -F $fstype -o $mntopts \
133 $new_special $mountp >/dev
/msglog
2>&1
134 if [ $?
-eq 0 ]; then
136 ISROOTDEVPATH
=`$ECHO $device | \
137 $AWK -F":" '{print $1}'`
141 if [ -n "$RVAL" ]; then
142 cecho
"Error: Unable to remount your root device"
148 if [ -z "$HASZFSROOT" ]; then
149 cecho
"stmsboot: Error: your root slice is invalid"
152 cecho
"stmsboot: Root is on ZFS"
158 # mount /usr read only
162 exec < $vfstab; readvfstab
"/usr"
164 if [ -n "$mountp" ]; then
170 new_special
=`$STMSBOOTUTIL -m $special`
175 # Must use -o largefiles here to ensure the read-only
176 # mount does not fail as a result of having a large
177 # file present on /usr.
179 if [ "$mntopts" = "-" ]; then
180 mntopts
='ro,largefiles'
182 checkopt largefiles
$mntopts
183 if [ "$option" != "largefiles" ]; then
184 mntopts
="largefiles,$mntopts"
188 if [ "$option" != "ro" ]; then
189 mntopts
="ro,$mntopts"
192 # Requesting logging on a read-only mount
193 # causes errors to be displayed, so remove
194 # "logging" from the list of options.
195 checkopt logging
$mntopts
196 if [ "$option" = "logging" ]; then
201 # In case of a manual restart of the service, mount
202 # will emit messages if /usr is already mounted.
203 # So redirect the output to /dev/null.
204 $MOUNT -m -F $fstype -o $mntopts $new_special /usr \
207 if [ $ret_val -eq 0 ]; then
215 # update system dump configuration
218 # Disable device-in-use checking (done in libdiskmgt).
219 # Without disabling this check, the configuration of dump device
220 # would fail as the device-in-use code incorrectly concludes that
221 # the device is in use and hence prevents configuration of the dump
226 DUMPISZFS
=`$AWK -F"=" '/DUMPADM_DEVICE/ {print $2}' /etc/dumpadm.conf|$EGREP zvol`
227 if [ -z "$DUMPISZFS" ]; then
228 set -- `$DUMPADM -u 2>&1 | $EGREP 'cannot use /dev.* as dump device'`
230 newname
=`$STMSBOOTUTIL -m $4`
231 if [ $?
-eq 0 ]; then
232 if $DUMPADM -d $newname > /dev
/msglog
2> /dev
/console
; then
233 cecho
"stmsboot: dump configuration \
236 mpxio_error
"failed to configure \
237 the dump device.\nold \
238 dump device name: $4"
244 # make sure we can get to it, force zfs to load fully
245 $LS $DUMPISZFS >>/dev
/null
2>&1
246 cecho
"stmsboot: dump on ZFS, no dumpadm update required"
251 # Update bootpath for x86 here when we are enabling mpxio on root
254 cur_bootpath
=`$STMSBOOTUTIL -b`
255 if [ $?
-ne 0 ]; then
256 cecho
"stmsboot: ERROR! Unable to retrieve bootpath property\n"
260 # Since on x64 platforms the eeprom command doesn't update the
261 # kernel, the file /boot/solaris/bootenv.rc and the kernel's
262 # bootpath variable have a good chance of differing. We do some
263 # extra handwaving to get the correct bootpath variable setting.
265 ONDISKVER
=`$AWK '/bootpath/ {print $3}' /boot/solaris/bootenv.rc|\
267 if [ "$ONDISKVER" != "$cur_bootpath" ]; then
268 cur_bootpath
="$ONDISKVER"
272 for path
in $cur_bootpath; do
273 mapped
=`$STMSBOOTUTIL -p $path`
274 if [ "$mapped" != "NOT_MAPPED" ]; then
275 if [ "$mapped" != "$path" ]; then
276 NEWBOOTPATH
=`echo "$path " | \
277 $SED -e"s|$path|$mapped|"`" $NEWBOOTPATH"
279 NEWBOOTPATH
="$NEWBOOTPATH $path"
283 # now strip off leading and trailing space chars
284 new_bootpath
=`echo $NEWBOOTPATH`
285 $EEPROM bootpath
="$new_bootpath"
286 cecho
"stmsboot: bootpath has been updated"
290 # Now do the actual work
293 # NOTE: If the first attempt to run the service has failed due to an
294 # expected error, users should be able to manually rerun the service.
296 # First mount /usr read only. This must be done to run
297 # utilities such as fsck and devfsadm.
298 # In the case of a manual rerun of the service, mounting of /usr here
299 # fails if /usr already happens to be mounted. It is better that we
300 # do not mount /usr if already mounted, but there seems to be no
301 # apparent way to check whether /usr is mounted or not as we mount
302 # /usr without making an entry into /etc/mnttab. So instead of
303 # explicitly checking for mount failures, we just do a sanity check
304 # by looking for some file (in this case devfsadm) in /usr.
307 if [ ! -s $DEVFSADM ]; then
308 mpxio_error
"failed to mount the /usr filesystem."
312 if mpxio_mount_root
; then
314 cecho
"stmsboot: configuring devices"
317 if [ -n "$ISROOTDEVPATH" ]; then
318 ISROOTDEV
=`$STMSBOOTUTIL -o $ISROOTDEVPATH`
321 # update /etc/vfstab to reflect device name changes
322 $STMSBOOTUTIL -u >/dev
/msglog
2>&1
323 if [ $?
-eq 0 ]; then
324 $CP /etc
/vfstab
/etc
/vfstab.old
325 # handle active-active paths, where the probe order
326 # for the hba reports a different path to what the
327 # boot-device variable gives us
328 if [ -n "$ISROOTDEV" ]; then
329 ROOTDEVCHK
=`grep $ISROOTDEV /etc/vfstab`
330 if [ $?
-ne 0 ]; then
331 # we got a different path for root
332 exec < $SAVEDIR/vfstab.new
; readvfstab
/
333 FILEDEV
=`$ECHO $special | \
334 $SED -e"s,/dev/dsk/,," -e"s,s[0-9]*,,"`
335 $SED -e"s,$FILEDEV,$ISROOTDEV,g" < \
336 $SAVEDIR/vfstab.new
> /etc
/vfstab
339 $CP $SAVEDIR/vfstab.new
/etc
/vfstab
341 $RM $SAVEDIR/vfstab.new
343 cecho
"stmsboot: vfstab has been updated"
348 if [ "$MACH" = "i386" ]; then
349 # only update bootpath here for x86
352 cecho
"stmsboot: now regenerating boot archive"
353 $BOOTADM update-archive
355 mpxio_error
"failed to update /etc/vfstab."
358 $SVCADM disable system
/device
/mpxio-upgrade
360 if [ $usrmounted -eq 1 ]; then
361 cecho
"stmsboot: rebooting the system now."
365 mpxio_error
"failed to mount the root filesystem."