17621SJames.McPherson@Sun.COM#!/bin/ksh93 -p 27621SJames.McPherson@Sun.COM# 37621SJames.McPherson@Sun.COM# CDDL HEADER START 47621SJames.McPherson@Sun.COM# 57621SJames.McPherson@Sun.COM# The contents of this file are subject to the terms of the 67621SJames.McPherson@Sun.COM# Common Development and Distribution License (the "License"). 77621SJames.McPherson@Sun.COM# You may not use this file except in compliance with the License. 87621SJames.McPherson@Sun.COM# 97621SJames.McPherson@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107621SJames.McPherson@Sun.COM# or http://www.opensolaris.org/os/licensing. 117621SJames.McPherson@Sun.COM# See the License for the specific language governing permissions 127621SJames.McPherson@Sun.COM# and limitations under the License. 137621SJames.McPherson@Sun.COM# 147621SJames.McPherson@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each 157621SJames.McPherson@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167621SJames.McPherson@Sun.COM# If applicable, add the following below this CDDL HEADER, with the 177621SJames.McPherson@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying 187621SJames.McPherson@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner] 197621SJames.McPherson@Sun.COM# 207621SJames.McPherson@Sun.COM# CDDL HEADER END 217621SJames.McPherson@Sun.COM# 227621SJames.McPherson@Sun.COM# 23*10661SXun.Ni@Sun.COM# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247621SJames.McPherson@Sun.COM# Use is subject to license terms. 257621SJames.McPherson@Sun.COM# 267621SJames.McPherson@Sun.COM 277621SJames.McPherson@Sun.COM# 287621SJames.McPherson@Sun.COM# mkbootmedia - create bootable Solaris ISO image 297621SJames.McPherson@Sun.COM# 307621SJames.McPherson@Sun.COM 317621SJames.McPherson@Sun.COMreadonly PROG=$0 327621SJames.McPherson@Sun.COMMKISOFS=/usr/bin/mkisofs 337621SJames.McPherson@Sun.COMELTORITO=boot/grub/stage2_eltorito # relative to $MEDIA_ROOT 34*10661SXun.Ni@Sun.COMSPARCBOOT=boot/hsfs.bootblock 35*10661SXun.Ni@Sun.COMCAT=/usr/bin/cat 367621SJames.McPherson@Sun.COMCP=/usr/bin/cp 377621SJames.McPherson@Sun.COMRM=/usr/bin/rm 38*10661SXun.Ni@Sun.COMUNAME=/usr/bin/uname 39*10661SXun.Ni@Sun.COMMACH=`$UNAME -p` 40*10661SXun.Ni@Sun.COMBOOTBLOCK= 41*10661SXun.Ni@Sun.COMGREP=/usr/bin/grep 427621SJames.McPherson@Sun.COM 437621SJames.McPherson@Sun.COM# for gettext 447621SJames.McPherson@Sun.COMTEXTDOMAIN=SUNW_OST_OSCMD 457621SJames.McPherson@Sun.COMexport TEXTDOMAIN 467621SJames.McPherson@Sun.COM 477621SJames.McPherson@Sun.COM 487621SJames.McPherson@Sun.COMfunction usage 497621SJames.McPherson@Sun.COM{ 507621SJames.McPherson@Sun.COM gettext "Usage:\n${PROG##*/} [-v] [-l <label>] <media-root> <iso>\n" 517621SJames.McPherson@Sun.COM gettext "Options:\n -l <label>\n Label/volume name of the ISO image.\n" 527621SJames.McPherson@Sun.COM gettext " -v\n Verbose. Multiple -v options increase verbosity.\n" 537621SJames.McPherson@Sun.COM echo; 547621SJames.McPherson@Sun.COM} 557621SJames.McPherson@Sun.COM 567621SJames.McPherson@Sun.COM 577621SJames.McPherson@Sun.COM# 587621SJames.McPherson@Sun.COM# Main 597621SJames.McPherson@Sun.COM# 607621SJames.McPherson@Sun.COMLABEL= 617621SJames.McPherson@Sun.COMVERBOSITY=0 627621SJames.McPherson@Sun.COM 637621SJames.McPherson@Sun.COMwhile getopts ':l:v' opt 647621SJames.McPherson@Sun.COMdo 657621SJames.McPherson@Sun.COM case $opt in 667621SJames.McPherson@Sun.COM l) LABEL=$OPTARG 677621SJames.McPherson@Sun.COM ;; 687621SJames.McPherson@Sun.COM v) (( VERBOSITY += 1 )) 697621SJames.McPherson@Sun.COM ;; 707621SJames.McPherson@Sun.COM :) gettext "Option -$OPTARG missing argument.\n" 717621SJames.McPherson@Sun.COM usage 727621SJames.McPherson@Sun.COM exit 1 737621SJames.McPherson@Sun.COM ;; 747621SJames.McPherson@Sun.COM *) gettext "Option -$OPTARG invalid.\n" 757621SJames.McPherson@Sun.COM usage 767621SJames.McPherson@Sun.COM exit 2 777621SJames.McPherson@Sun.COM ;; 787621SJames.McPherson@Sun.COM esac 797621SJames.McPherson@Sun.COMdone 807621SJames.McPherson@Sun.COMshift 'OPTIND - 1' 817621SJames.McPherson@Sun.COM 827621SJames.McPherson@Sun.COMif (( $# != 2 )) 837621SJames.McPherson@Sun.COMthen 847621SJames.McPherson@Sun.COM usage 857621SJames.McPherson@Sun.COM exit 1 867621SJames.McPherson@Sun.COMfi 877621SJames.McPherson@Sun.COM 887621SJames.McPherson@Sun.COMMEDIA_ROOT=$1 897621SJames.McPherson@Sun.COMISOIMAGE=$2 907621SJames.McPherson@Sun.COM 917621SJames.McPherson@Sun.COMif [ ! -z `echo $ISOIMAGE | $GREP "^/tmp"` ]; then 927621SJames.McPherson@Sun.COM gettext "ISO images will not be created on /tmp.\nPlease choose a different output location.\n" 937621SJames.McPherson@Sun.COM exit 3 947621SJames.McPherson@Sun.COMfi 957621SJames.McPherson@Sun.COM 967621SJames.McPherson@Sun.COM# Verify $MEDIA_ROOT is a Solaris install media (Solaris 10 Update 1 or later) 977621SJames.McPherson@Sun.COMif [[ ! -d $(echo "$MEDIA_ROOT"/Solaris*/Tools/Boot) ]]; then 987621SJames.McPherson@Sun.COM gettext "$MEDIA_ROOT is not Solaris install media.\n" 997621SJames.McPherson@Sun.COM exit 1 1007621SJames.McPherson@Sun.COMfi 1017621SJames.McPherson@Sun.COM 1027621SJames.McPherson@Sun.COM# If no label specified use the Solaris_* version under $MEDIA_ROOT 1037621SJames.McPherson@Sun.COMif [[ -z "$LABEL" ]]; then 1047621SJames.McPherson@Sun.COM LABEL=$(echo "$MEDIA_ROOT"/Solaris*) 1057621SJames.McPherson@Sun.COM LABEL=${LABEL##*/} 1067621SJames.McPherson@Sun.COMfi 1077621SJames.McPherson@Sun.COM 1087621SJames.McPherson@Sun.COM# If $ISOIMAGE exists, verify it's writable. 1097621SJames.McPherson@Sun.COMif [[ -e "$ISOIMAGE" && ! -w "$ISOIMAGE" ]]; then 1107621SJames.McPherson@Sun.COM gettext "$ISOIMAGE exists but is not writable.\n" 1117621SJames.McPherson@Sun.COM exit 1 1127621SJames.McPherson@Sun.COMfi 1137621SJames.McPherson@Sun.COM 114*10661SXun.Ni@Sun.COM# If we're on an x86/x64 system, we need to have the El Torito file 115*10661SXun.Ni@Sun.COM# modified with some boot information (-boot-info-table option). 116*10661SXun.Ni@Sun.COM# If the image isn't writable, we can't continue 117*10661SXun.Ni@Sun.COM# UltraSPARC systems (sun4u, sun4v etc) don't use El Torito 118*10661SXun.Ni@Sun.COMif [[ "$MACH" = "i386" && ! -w "$MEDIA_ROOT/$ELTORITO" ]]; then 1197621SJames.McPherson@Sun.COM gettext "$MEDIA_ROOT/$ELTORITO is not writable.\n" 1207621SJames.McPherson@Sun.COM exit 1 1217621SJames.McPherson@Sun.COMfi 1227621SJames.McPherson@Sun.COM 1237621SJames.McPherson@Sun.COM# Check that we've got mkisofs installed 1247621SJames.McPherson@Sun.COMif [[ ! -f "$MKISOFS" || ! -x "$MKISOFS" ]]; then 1257621SJames.McPherson@Sun.COM gettext "Cannot find $f\n" 1267621SJames.McPherson@Sun.COM exit 1 1277621SJames.McPherson@Sun.COMfi 1287621SJames.McPherson@Sun.COM 1297621SJames.McPherson@Sun.COM 1307621SJames.McPherson@Sun.COM# Determine mkisofs' verbose flag depending on $VERBOSITY. 1317621SJames.McPherson@Sun.COMcase $VERBOSITY in 1327621SJames.McPherson@Sun.COM0) VERBOSE_FLAG=-quiet 1337621SJames.McPherson@Sun.COM ;; 1347621SJames.McPherson@Sun.COM1) VERBOSE_FLAG= # mkisofs' default verboseness 1357621SJames.McPherson@Sun.COM ;; 1367621SJames.McPherson@Sun.COM*) VERBOSE_FLAG= 1377621SJames.McPherson@Sun.COM i=$VERBOSITY 1387621SJames.McPherson@Sun.COM while ((i > 0)) 1397621SJames.McPherson@Sun.COM do 1407621SJames.McPherson@Sun.COM VERBOSE_FLAG="-v $VERBOSE_FLAG" 1417621SJames.McPherson@Sun.COM (( i -= 1 )) 1427621SJames.McPherson@Sun.COM done 1437621SJames.McPherson@Sun.COM ;; 1447621SJames.McPherson@Sun.COMesac 1457621SJames.McPherson@Sun.COM 1467621SJames.McPherson@Sun.COM# Since mkisofs below will modify the file $ELTORITO in-place, save a copy 1477621SJames.McPherson@Sun.COM# of it first. Use trap to restore it when this script exits (including 1487621SJames.McPherson@Sun.COM# when user hits control-C). 149*10661SXun.Ni@Sun.COM 150*10661SXun.Ni@Sun.COMif [[ "$MACH" = "i386" ]] 151*10661SXun.Ni@Sun.COMthen 152*10661SXun.Ni@Sun.COM BOOTBLOCK=$MEDIA_ROOT/$ELTORITO 153*10661SXun.Ni@Sun.COM ELTORITO_SAVE=/tmp/${ELTORITO##*/}.$$ 154*10661SXun.Ni@Sun.COM $CP "$MEDIA_ROOT/$ELTORITO" "$ELTORITO_SAVE" || exit 1 155*10661SXun.Ni@Sun.COM trap '"$CP" "$ELTORITO_SAVE" "$MEDIA_ROOT/$ELTORITO" 2>/dev/null; 156*10661SXun.Ni@Sun.COM "$RM" -f "$ELTORITO_SAVE"' EXIT 157*10661SXun.Ni@Sun.COMelse 158*10661SXun.Ni@Sun.COM # sun4u/sun4u1/sun4v et al 159*10661SXun.Ni@Sun.COM BOOTBLOCK=$MEDIA_ROOT/$SPARCBOOT 160*10661SXun.Ni@Sun.COM SPARCBOOT_SAVE=/tmp/hsfs.bootblock.$$ 161*10661SXun.Ni@Sun.COM $CP "$MEDIA_ROOT/$SPARCBOOT" "$SPARCBOOT_SAVE" || exit 1 162*10661SXun.Ni@Sun.COM trap '"$CP" "$MEDIA_ROOT/$SPARCBOOT" "$SPARCBOOT_SAVE" 2>/dev/null; 163*10661SXun.Ni@Sun.COM "$RM" -f $SPARCBOOT_SAVE"' EXIT 164*10661SXun.Ni@Sun.COMfi 1657621SJames.McPherson@Sun.COM 1667621SJames.McPherson@Sun.COM# Call mkisofs to do the actual work. 1677621SJames.McPherson@Sun.COM# Note: the "-log-file >(cat -u >&2)" and "2>/dev/null" below is a trick 1687621SJames.McPherson@Sun.COM# to filter out mkisofs's warning message about being non-conforming 1697621SJames.McPherson@Sun.COM# to ISO-9660. 170*10661SXun.Ni@Sun.COM# We do some funky architecture-specific stuff here so that we can 171*10661SXun.Ni@Sun.COM# actually create a bootable media image for UltraSPARC systems 172*10661SXun.Ni@Sun.COM 173*10661SXun.Ni@Sun.COMsparc_ISOARGS="-G $BOOTBLOCK -B ... -joliet-long -R -U" 174*10661SXun.Ni@Sun.COMi386_ISOARGS="-b boot/grub/stage2_eltorito -boot-info-table " 175*10661SXun.Ni@Sun.COMi386_ISOARGS="$i386_ISOARGS -boot-load-size 4 -c .catalog -d -N " 176*10661SXun.Ni@Sun.COMi386_ISOARGS="$i386_ISOARGS -no-emul-boot -r -relaxed-filenames" 177*10661SXun.Ni@Sun.COMif [[ "$MACH" = "i386" ]] 178*10661SXun.Ni@Sun.COMthen 179*10661SXun.Ni@Sun.COM ISOARGS=$i386_ISOARGS 180*10661SXun.Ni@Sun.COMelse 181*10661SXun.Ni@Sun.COM ISOARGS=$sparc_ISOARGS 182*10661SXun.Ni@Sun.COMfi 183*10661SXun.Ni@Sun.COM 1847621SJames.McPherson@Sun.COM$MKISOFS -o "$ISOIMAGE" \ 1857621SJames.McPherson@Sun.COM -allow-leading-dots \ 186*10661SXun.Ni@Sun.COM $ISOARGS \ 187*10661SXun.Ni@Sun.COM -l -ldots \ 1887621SJames.McPherson@Sun.COM -R -J \ 189*10661SXun.Ni@Sun.COM -V "$ISOLABEL" \ 1907621SJames.McPherson@Sun.COM $VERBOSE_FLAG \ 191*10661SXun.Ni@Sun.COM -log-file >($CAT -u >&2) \ 1927621SJames.McPherson@Sun.COM "$MEDIA_ROOT" 2>/dev/null 193