xref: /titanic_41/usr/src/cmd/fs.d/zfs/bootinstall/bootinstall.sh (revision bce835f2166e1510cc776830775859ba3e49c1ce)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27PATH="/usr/bin:/usr/sbin:${PATH}"; export PATH
28ARCH=$(uname -p)
29KARCH=$(uname -m)
30
31if [ "$ARCH" != "i386" -a "$ARCH" != "sparc" ] ; then
32	echo "Unknown architecture: $ARCH"
33	exit 1
34fi
35
36POOL="$1"
37DEV=$(echo "$2" | sed -e 's+/dsk/+/rdsk/+')
38
39if [ -z "${POOL}" -o -z "${DEV}" ]; then
40	echo "Invalid usage"
41	exit 1
42fi
43
44CURPOOL=$(df -k / | awk 'NR == 2 {print $1}' | sed 's,/.*,,')
45
46if [ "$CURPOOL" != "$POOL" ] ; then
47	echo "Modified pool must be current root pool"
48	exit 1
49fi
50
51#
52#
53
54if [ "${ARCH}" = "i386" ]; then
55	STAGE1=/boot/grub/stage1
56	STAGE2=/boot/grub/stage2
57	/sbin/installgrub ${STAGE1} ${STAGE2} ${DEV}
58	if [ $? != 0 ]; then
59		echo "Failure installing GRUB on ${DEV}"
60		exit 1
61	fi
62else
63	BOOTBLK=/usr/platform/${KARCH}/lib/fs/zfs/bootblk
64	/usr/sbin/installboot -F zfs ${BOOTBLK} ${DEV}
65	if [ $? != 0 ]; then
66		echo "Failure installing boot block on ${DEV}"
67		exit
68	fi
69fi
70
71exit 0
72