diff --git a/Makefile b/Makefile index 15ff791..17bc0cd 100644 --- a/Makefile +++ b/Makefile @@ -31,12 +31,12 @@ DESTDIR=$(BUILDSEND_MP) all: -INSTALLS=anon.dtrace.conf anon.system build_image.sh build_zfs_send.sh \ +INSTALLS=anon.dtrace.conf anon.system build_miniroot.sh build_zfs_send.sh \ data/access.log data/boot data/etc data/filelist.ramdisk data/kernel \ data/known_extras data/mdb data/platform disk_help.sh install_help.sh \ install_image.sh src/takeover-console.c Makefile net_help.sh README.md \ build_iso.sh digest find-and-install.sh kayak-menu.sh config-menu.sh \ - usbgen.sh ipcalc dialog src/passutil.c \ + build_usb.sh ipcalc dialog src/passutil.c \ loader.conf.local rpool-install.sh \ sample/000000000000.sample sample/menu.lst.000000000000 @@ -58,7 +58,7 @@ anon.dtrace.conf: cat /kernel/drv/dtrace.conf $@.tmp > $@ rm $@.tmp -MINIROOT_DEPS=build_image.sh anon.dtrace.conf anon.system \ +MINIROOT_DEPS=build_miniroot.sh anon.dtrace.conf anon.system \ install_image.sh disk_help.sh install_help.sh net_help.sh $(BUILDSEND_MP)/kayak_$(VERSION).zfs.bz2: build_zfs_send.sh @@ -95,17 +95,14 @@ $(DESTDIR)/tftpboot/kayak/miniroot.gz: $(BUILDSEND_MP)/miniroot.gz $(DESTDIR)/tftpboot/kayak/miniroot.gz.hash: $(BUILDSEND_MP)/miniroot.gz digest -a sha1 $< > $@ -build_image.sh: - VERSION=$(VERSION) ./build_image.sh - -build_zfs_send.sh: - VERSION=$(VERSION) ./build_zfs_image.sh +build_miniroot.sh: + VERSION=$(VERSION) ./build_miniroot.sh $(BUILDSEND_MP)/miniroot.gz: $(MINIROOT_DEPS) if test -n "`zfs list -H -t snapshot $(BUILDSEND)/root@fixup 2>/dev/null`"; then \ - VERSION=$(VERSION) DEBUG=$(DEBUG) ./build_image.sh $(BUILDSEND) fixup ; \ + VERSION=$(VERSION) DEBUG=$(DEBUG) ./build_miniroot.sh $(BUILDSEND) fixup ; \ else \ - VERSION=$(VERSION) DEBUG=$(DEBUG) ./build_image.sh $(BUILDSEND) begin ; \ + VERSION=$(VERSION) DEBUG=$(DEBUG) ./build_miniroot.sh $(BUILDSEND) begin ; \ fi $(DESTDIR)/var/kayak/kayak/$(VERSION).zfs.bz2: $(BUILDSEND_MP)/kayak_$(VERSION).zfs.bz2 @@ -171,7 +168,8 @@ install-iso: bins kbd.list install-tftp install-web BUILDSEND_MP=$(BUILDSEND_MP) VERSION=$(VERSION) ./build_iso.sh install-usb: install-iso - ./usbgen.sh $(BUILDSEND_MP)/$(VERSION).iso $(BUILDSEND_MP)/$(VERSION).usb-dd /tmp + ./build_usb.sh $(BUILDSEND_MP)/$(VERSION).iso \ + $(BUILDSEND_MP)/$(VERSION).usb-dd clean: rm -f takeover-console passutil mount_media ipcalc dialog zpool_patch \ diff --git a/build_iso.sh b/build_iso.sh index 0182495..6e69294 100755 --- a/build_iso.sh +++ b/build_iso.sh @@ -44,18 +44,35 @@ stage() # Allow temporary directory override : ${TMPDIR:=/tmp} +# Files prepared by other parts of the kayak build process + KAYAK_MINIROOT=$BUILDSEND_MP/miniroot.gz ZFS_IMG=$BUILDSEND_MP/kayak_${VERSION}.zfs.bz2 [ ! -f $KAYAK_MINIROOT -o ! -f $ZFS_IMG ] && echo "Missing files." && exit 1 -ISO_ROOT=$TMPDIR/iso_root -BA_ROOT=$TMPDIR/boot_archive +# Mount-points + +MINIROOT_ROOT=$TMPDIR/miniroot.$$ +BA_ROOT=$TMPDIR/boot_archive.$$ +UEFI_ROOT=$TMPDIR/uefi.$$ +ISO_ROOT=$TMPDIR/iso_root.$$ + +# Image files + +MINIROOT_FILE=$TMPDIR/miniroot_$$.img +BA_FILE=$TMPDIR/boot_archive_$$.img + +# Parameters -KAYAK_ROOT=$TMPDIR/miniroot.$$ -KR_FILE=$TMPDIR/kr.$$ -MNT=/mnt BA_SIZE=225M + +# Uncomment the following line to build a UEFI ISO. +# We aren't building UEFI yet. +#UEFI_SIZE=4M + +# Output file + DST_ISO=$BUILDSEND_MP/${VERSION}.iso ############################################################################# @@ -66,38 +83,41 @@ DST_ISO=$BUILDSEND_MP/${VERSION}.iso set -o errexit -mkdir $KAYAK_ROOT -mkdir $ISO_ROOT - -# Create a UFS lofi file and mount the UFS filesystem in $MNT. This will -# form the boot_archive for the ISO. +# First, uncompress the miniroot to a temporary file and mount it on +# $MINIROOT_ROOT stage "Mounting source miniroot" -# Uncompress and mount the miniroot -gunzip -c $KAYAK_MINIROOT > $KR_FILE -LOFI_RPATH=`lofiadm -a $KR_FILE` -mount $LOFI_RPATH $KAYAK_ROOT - -stage "Creating UFS image for new miniroot" -mkfile $BA_SIZE $BA_ROOT -LOFI_PATH=`lofiadm -a $BA_ROOT` -echo 'y' | newfs $LOFI_PATH -mount $LOFI_PATH $MNT - -# Copy the files from the miniroot to the new miniroot... -sz=`du -sh $KAYAK_ROOT | awk '{print $1}'` -stage "Adding files to new miniroot" -tar -cf - -C $KAYAK_ROOT . | pv -s $sz | tar -xf - -C $MNT +gzip -dc $KAYAK_MINIROOT > $MINIROOT_FILE +LOFI_MINIROOT=`lofiadm -a $MINIROOT_FILE` +mkdir $MINIROOT_ROOT +mount $LOFI_MINIROOT $MINIROOT_ROOT + +# Now create a UFS boot-archive image and mount it on $BA_ROOT + +stage "Creating UFS image for boot archive" +mkfile $BA_SIZE $BA_FILE +LOFI_BA=`lofiadm -a $BA_FILE` +yes | newfs $LOFI_BA +mkdir $BA_ROOT +mount $LOFI_BA $BA_ROOT + +# Copy the files from the miniroot to the boot archive +sz=`du -sh $MINIROOT_ROOT | awk '{print $1}'` +stage "Adding files to boot archive" +tar -cf - -C $MINIROOT_ROOT . | pv -s $sz | tar -xf - -C $BA_ROOT + # ...and to the ISO root stage "Adding files to ISO root" -tar -cf - -C $KAYAK_ROOT . | pv -s $sz | tar -xf - -C $ISO_ROOT +mkdir $ISO_ROOT +tar -cf - -C $MINIROOT_ROOT . | pv -s $sz | tar -xf - -C $ISO_ROOT -# Clean-up +# No longer need the source miniroot so unmount it and clean up the +# temporary file. stage "Unmounting source miniroot" -umount $KAYAK_ROOT -rmdir $KAYAK_ROOT -lofiadm -d $LOFI_RPATH -rm $KR_FILE +umount $MINIROOT_ROOT +rmdir $MINIROOT_ROOT +lofiadm -d $LOFI_MINIROOT +rm $MINIROOT_FILE # Place the full ZFS image into the ISO root so it does not form part of the # boot archive (otherwise the boot seems to hang for several minutes while @@ -110,7 +130,7 @@ pv $ZFS_IMG > $ISO_ROOT/image/`basename $ZFS_IMG` # find the image - see src/mount_media.c echo $VERSION > $ISO_ROOT/.volsetid -# Put additional files into the boot-archive on $MNT, which is +# Put additional files into the boot-archive on $BA_ROOT, which is # what will be / (via ramdisk) once the ISO is booted. stage "Adding extra files to miniroot" @@ -121,33 +141,33 @@ cp -p \ ipcalc passutil mount_media nossh.xml \ dialog dialog.rc dialog.sh utils.sh dialog-tzselect \ kbd.list \ - $MNT/kayak/. + $BA_ROOT/kayak/. if [ -n "$REFRESH_KAYAK" ]; then # For testing, make sure files in miniroot are current - for f in $MNT/kayak/*; do + for f in $BA_ROOT/kayak/*; do [ -f "$f" ] || continue echo "REFRESH $f" - cp `basename $f` $MNT/kayak + cp `basename $f` $BA_ROOT/kayak done fi -cat < $MNT/root/.bashrc +cat < $BA_ROOT/root/.bashrc export PATH=/usr/bin:/usr/sbin:/sbin export HOME=/root EOF # Have initialboot invoke an interactive installer. -cat < $MNT/.initialboot +cat < $BA_ROOT/.initialboot /kayak/takeover-console /kayak/kayak-menu.sh exit 0 EOF # Increase the timeout -SVCCFG_REPOSITORY=$MNT/etc/svc/repository.db \ +SVCCFG_REPOSITORY=$BA_ROOT/etc/svc/repository.db \ svccfg -s system/initial-boot setprop "start/timeout_seconds=86400" # Refresh the devices on the miniroot. -devfsadm -r $MNT +devfsadm -r $BA_ROOT # # The ISO's miniroot is going to be larger than the PXE miniroot. To that @@ -155,18 +175,20 @@ devfsadm -r $MNT # the miniroot. Use PREBUILT_ILLUMOS if available, or the current system # if not. # + +PROTO= +[ -n "$PREBUILT_ILLUMOS" -a -d $PREBUILT_ILLUMOS/proto/root_i386-nd ] \ + && PROTO=$PREBUILT_ILLUMOS/proto/root_i386-nd + from_one_to_other() { dir=$1 - FROMDIR=/ - [ -n "$PREBUILT_ILLUMOS" -a -d $PREBUILT_ILLUMOS/proto/root_i386/$dir ] \ - && FROMDIR=$PREBUILT_ILLUMOS/proto/root_i386 + [ -n "$PROTO" -a -d $PROTO/$dir ] && src=$PROTO || src=/ shift - tar -cf - -C $FROMDIR/$dir ${@:-.} | tar -xf - -C $MNT/$dir + tar -cf - -C $src/$dir ${@:-.} | tar -xf - -C $BA_ROOT/$dir } -# Add from_one_to_other for any directory {file|subdir file|subdir ...} you need from_one_to_other usr/share/lib/zoneinfo from_one_to_other usr/share/lib/keytables from_one_to_other usr/share/lib/terminfo @@ -175,7 +197,7 @@ from_one_to_other usr/sbin ping from_one_to_other usr/bin netstat ###################################################################### -# Configure the loader for the installer +# Configure the loader for installer # Splash screen - add release version to top of screen @@ -204,34 +226,80 @@ EOM # Okay, we've populated the new miniroot. Close it up and install it # on $ISO_ROOT as the boot archive. # -stage "Miniroot size" -df -h $MNT +stage "Boot archive miniroot size" +df -h $BA_ROOT stage "Unmounting boot archive image" -umount $MNT -lofiadm -d $LOFI_PATH +umount $BA_ROOT +rmdir $BA_ROOT +lofiadm -d $LOFI_BA + stage "Installing boot archive" -pv $BA_ROOT | gzip -9c > $ISO_ROOT/platform/i86pc/amd64/boot_archive.gz +pv $BA_FILE | gzip -9c > $ISO_ROOT/platform/i86pc/amd64/boot_archive.gz ls -lh $ISO_ROOT/platform/i86pc/amd64/boot_archive.gz | awk '{print $5}' -digest -a sha1 $BA_ROOT \ +digest -a sha1 $BA_FILE \ > $ISO_ROOT/platform/i86pc/amd64/boot_archive.hash -rm -f $BA_ROOT +rm -f $BA_FILE stage "Removing unecessary files from ISO root" rm -rf $ISO_ROOT/{usr,bin,sbin,lib,kernel} stage "ISO root size: `du -sh $ISO_ROOT/.`" # And finally, burn the ISO. -mkisofs -N -l -R -U -d -D \ - -o $DST_ISO \ - -b boot/cdboot \ - -c .catalog \ - -no-emul-boot \ - -boot-load-size 4 \ - -boot-info-table \ - -allow-multidot \ - -no-iso-translate \ - -cache-inodes \ - -V "OmniOSce $VERSION" \ - $ISO_ROOT + +if [ -n "$UEFI_SIZE" ]; then + if [ -n "$PROTO" -a -f $PROTO/boot/loader.efi ]; then + echo "Using loader.efi from proto" + EFI=$PROTO/boot/loader.efi + elif [ -f /boot/loader.efi ]; then + echo "Using loader.efi from running system" + EFI=/boot/loader.efi + else + echo "Cannot find loader.efi" + rm -rf $ISO_ROOT + exit 1 + fi + # Create a UEFI bootblock + stage "Building UEFI bootblock" + UEFI_FILE=$ISO_ROOT/boot/efiboot.img + mkfile $UEFI_SIZE $UEFI_FILE + LOFI_UEFI=`lofiadm -a $UEFI_FILE` + yes | mkfs -F pcfs \ + -o b=System,nofdisk,size=8800 ${LOFI_UEFI//lofi/rlofi} + mkdir $UEFI_ROOT + mount -F pcfs $LOFI_UEFI $UEFI_ROOT + mkdir -p $UEFI_ROOT/efi/boot + cp $EFI $UEFI_ROOT/efi/boot/bootx64.efi + df -h $UEFI_ROOT + umount $UEFI_ROOT + rmdir $UEFI_ROOT + lofiadm -d $LOFI_UEFI + + mkisofs -N -l -R -U -d -D \ + -V "OmniOSce $VERSION" \ + -o $DST_ISO \ + -c .catalog \ + -allow-multidot \ + -no-iso-translate \ + -cache-inodes \ + \ + -eltorito-boot boot/cdboot -no-emul-boot -boot-info-table \ + -eltorito-alt-boot \ + -eltorito-boot boot/`basename $UEFI_FILE` -no-emul-boot \ + \ + $ISO_ROOT +else + mkisofs -N -l -R -U -d -D \ + -V "OmniOSce $VERSION" \ + -o $DST_ISO \ + -c .catalog \ + -allow-multidot \ + -no-iso-translate \ + -cache-inodes \ + \ + -b boot/cdboot -no-emul-boot -boot-load-size 4 \ + -boot-info-table \ + \ + $ISO_ROOT +fi rm -rf $ISO_ROOT stage "$DST_ISO is ready" diff --git a/build_image.sh b/build_miniroot.sh similarity index 100% rename from build_image.sh rename to build_miniroot.sh diff --git a/build_usb.sh b/build_usb.sh new file mode 100755 index 0000000..f50389b --- /dev/null +++ b/build_usb.sh @@ -0,0 +1,210 @@ +#!/usr/bin/ksh + +# {{{ CDDL HEADER +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# }}} + +# Copyright 2018 OmniOS Community Edition (OmniOSce) Association. + +export LC_ALL=C + +if [ `id -u` != "0" ]; then + echo "You must be root to run this script." + exit 1 +fi + +ISO_FILE=${1:?iso} +USB_FILE=${2:?usb} + +[ ! -f "$ISO_FILE" ] && echo "Cannot find $ISO_FILE" && exit 1 + +# Uncomment the following line to build a UEFI image. +# We aren't building UEFI yet. +#UEFI_SIZE=34M + +# Allow temporary directory override +: ${TMPDIR:=/tmp} + +UEFI_ROOT=$TMPDIR/uefi_root.$$ +USB_ROOT=$TMPDIR/usb_root.$$ +ISO_ROOT=$TMPDIR/iso_root.$$ + +stage() +{ + echo "***" + echo "*** $*" + echo "***" +} + +set -o errexit + +###################################################################### +# Find UEFI boot file + +if [ -n "$UEFI_SIZE" ]; then + if [ -n "$PREBUILT_ILLUMOS" -a \ + -f $PREBUILT_ILLUMOS/proto/root_i386-nd/boot/boot1.efi ]; then + echo "Using boot1.efi from proto" + EFI_LOADER=$PREBUILT_ILLUMOS/proto/root_i386-nd/boot/boot1.efi + elif [ -f /boot/boot1.efi ]; then + echo "Using boot1.efi from running system" + EFI_LOADER=/boot/boot1.efi + else + echo "Cannot find boot1.efi" + exit 1 + fi +fi + +###################################################################### +# Compute the size for the new USB image. +# +# Use the ISO file size + 20% to account for smaller block size on UFS +# and the log. Round to nearest KiB plus 512. + +ISO_SIZE=`stat -c %s $ISO_FILE` +(( USB_SIZE = int((ISO_SIZE * 1.2) / 1024.) * 1024 + 512 )) + +# In MBR mode: +# plus 4MB for MBR+SMI label +# In UEFI mode: +# plus 4MB for label +# plus 34MB for system partition +# plus 1MB for boot partition + +if [ -n "$UEFI_SIZE" ]; then + ((USB_SIZE += 41943040)) +else + ((USB_SIZE += 4194304)) +fi + +echo "USB Size = $USB_SIZE (ISO_SIZE = $ISO_SIZE)" + +###################################################################### +# Create the new empty USB image and partition it +# + +stage "Creating USB image file" + +mkfile -n $USB_SIZE $USB_FILE +LOFI_USB=`lofiadm -la $USB_FILE` +RLOFI_USB=${LOFI_USB/dsk/rdsk} +# LOFI_USB fill be of the form /dev/dsk/c1t1d0p0 + +if [ -n "$UEFI_SIZE" ]; then + # Let zpool do the partitioning work for us + zpool create -B -o bootsize=$UEFI_SIZE usbtmp-$$ ${LOFI_USB/p0/} + zpool destroy usbtmp-$$ + + # At this point, the disk has three EFI partitions: + # V_SYSTEM ESP @ $UEFI_SIZE + # V_USR For ZFS data + # V_RESERVED Reserved + + # 1 MiB assuming 512-byte sectors + boot_size=2048 + + # Shrink slice 1 to $boot_size sectors and change the partition type + # to 1 (V_BOOT). + new_boot=`prtvtoc -h $RLOFI_USB | nawk -v size=$boot_size ' + $1 == 1 { printf("1:1:00:%d:%d\n", $4, size) } + '` + + # Allocate the remaining free space to slice 2 and set the + # partition type to 2 (V_ROOT) + new_root=`prtvtoc -h $RLOFI_USB | nawk -v size=$boot_size ' + $1 == 1 { printf("2:2:00:%d:%d\n", $4 + size, $5 - size) } + '` + + fmthard -d $new_boot $RLOFI_USB + fmthard -d $new_root $RLOFI_USB + + stage "Building UEFI bootblock" + + yes | mkfs -F pcfs -o b=System ${RLOFI_USB/p0/s0} + mkdir $UEFI_ROOT + mount -F pcfs ${LOFI_USB/p0/s0} $UEFI_ROOT + mkdir -p $UEFI_ROOT/efi/boot + cp $EFI_LOADER $UEFI_ROOT/efi/boot/bootx64.efi + umount $UEFI_ROOT + rmdir $UEFI_ROOT + + ufs=2 +else + # Create Solaris2 partition filling the entire disk + fdisk -B $RLOFI_USB + fdisk -W - $RLOFI_USB | tail -5 | head -2 + echo + + # Create slice 0 covering all of the non-reserved space + OIFS="$IFS"; IFS=" =" + set -- `prtvtoc -f $RLOFI_USB` + IFS="$OIFS" + # FREE_START=2048 FREE_SIZE=196608 FREE_COUNT=1 FREE_PART=... + start=$2; size=$4 + fmthard -d 0:2:01:$start:$size $RLOFI_USB + + ufs=0 +fi + +prtvtoc -s $RLOFI_USB + +###################################################################### +# Format and mount the UFS area + +stage "Formatting UFS slice $ufs" + +UFS_SLICE=${RLOFI_USB/p0/s$ufs} +yes | newfs $UFS_SLICE +mkdir $USB_ROOT +mount -o nologging ${UFS_SLICE/rdsk/dsk} $USB_ROOT + +###################################################################### +# Mount the source ISO, copy files to USB, unmount again + +stage "Mounting source ISO" +LOFI_ISO=`lofiadm -a $ISO_FILE` +mkdir $ISO_ROOT +mount -F hsfs -o ro $LOFI_ISO $ISO_ROOT + +stage "Copying ISO contents to USB image..." +( cd $ISO_ROOT; find . -print | cpio -pmudV $USB_ROOT ) + +stage "Unmounting source ISO" +umount $ISO_ROOT +rmdir $ISO_ROOT +lofiadm -d $LOFI_ISO + +# Create hidden file to stop OSX indexing this image (for example when +# installing via dd) +touch $USB_ROOT/.metadata_never_index + +df -h $USB_ROOT + +###################################################################### +# Install bootblocks +# + +stage "Installing boot blocks" +installboot -mf $USB_ROOT/boot/pmbr $USB_ROOT/boot/gptzfsboot $UFS_SLICE + +###################################################################### +# Unmount and clean up + +stage "Cleaning up" + +umount $USB_ROOT +rmdir $USB_ROOT +lofiadm -d $LOFI_USB + +chmod 444 $USB_FILE + +exit 0 + diff --git a/config-menu.sh b/config-menu.sh index f075cab..91cd9d5 100755 --- a/config-menu.sh +++ b/config-menu.sh @@ -380,8 +380,9 @@ dcfg_ip() # Split IP into IP and prefix typeset _net_ip_ip=${net_ip%/*} - #typeset _net_ip_prefix=${net_ip#*/} - typeset _net_ip_prefix="`$IPCALC -m $_net_ip | cut -d= -f2`" + typeset _net_ip_prefix= + [ -n "$_net_ip" ] && \ + _net_ip_prefix="`$IPCALC -m $_net_ip | cut -d= -f2`" typeset _lab_ip=" IP Address :" typeset _lab_prefix=" Netmask/Prefix :" diff --git a/data/access.log b/data/access.log index 634c0b5..4d32a07 100644 --- a/data/access.log +++ b/data/access.log @@ -1346,6 +1346,7 @@ 20807452 /usr/sbin/mkfs 20807452 /usr/sbin/clri 20807509 /usr/lib/fs/ufs/mkfs +20807509 /usr/lib/fs/pcfs/mkfs 20807639 /kernel/sys/amd64/kaio 20808309 /usr/lib/fs/mntfs/mount 20808483 /usr/bin/cpio diff --git a/data/boot b/data/boot index 97983cc..75356d7 100644 --- a/data/boot +++ b/data/boot @@ -12,6 +12,7 @@ 0 /boot/forth/check-password.4th 0 /boot/forth/color.4th 0 /boot/forth/delay.4th +0 /boot/forth/efi.4th 0 /boot/forth/frames.4th 0 /boot/forth/loader.4th 0 /boot/forth/logo-beastie.4th diff --git a/dialog-install.sh b/dialog-install.sh index d9b982f..639f334 100755 --- a/dialog-install.sh +++ b/dialog-install.sh @@ -161,11 +161,10 @@ RPOOL=rpool rpool_label='Root pool name' rpool_help="`d_centre 'Customise the name of the root pool if required.'`" -# At some point, we should add UEFI as the first (and default) option. -# 'Use GPT scheme with UEFI boot partition, recommended.' -PSCHEMES=(GPT MBR GPT+Active GPT+Slot1) +PSCHEMES=(UEFI GPT MBR GPT+Active GPT+Slot1) PSCHEMES_HELP=( - 'Use GPT scheme, recommended.' + 'Use GPT scheme with UEFI boot partition, recommended.' + 'Use GPT scheme, without UEFI boot partition.' 'Use traditional MBR scheme, supports disks up to 2TB.' 'Use GPT scheme but mark partition as active to work around BIOS bugs.' 'Use GPT scheme but place pMBR in slot 1 to work around BIOS bugs.' @@ -279,6 +278,11 @@ _FLAGS=f case "$PSCHEME" in UEFI) _FLAGS+=B + # The zpool slice will now be slice 1 but slice 0 may have a + # pool label from a previous installation. Clear it out. + for disk in $DISKLIST; do + zpool labelclear -f ${disk}s0 + done ;; MBR) _DISKLIST= @@ -336,7 +340,7 @@ prompt_hostname omniosce prompt_timezone ZFS_IMAGE=/.cdrom/image/*.zfs.bz2 -echo "Installing from ZFS image $ZFS_IMAGE" +d_info "Installing from ZFS image $ZFS_IMAGE" # Because of kayak's small miniroot, just use C as the language for now. LANG=C diff --git a/disk_help.sh b/disk_help.sh index 1e75dee..be11d24 100644 --- a/disk_help.sh +++ b/disk_help.sh @@ -92,21 +92,20 @@ BuildRpoolOnly() { if [[ -z "$disks" ]]; then bomb "No matching disks found to build root pool $RPOOL" fi - rm -f /tmp/kayak-disk-list for i in $disks do if [[ -n "$ztgt" ]]; then ztype="mirror" fi ztgt="$ztgt ${i}" - # Keep track of disks for later... - echo ${i} >> /tmp/kayak-disk-list done log "zpool destroy $RPOOL (just in case we've been run twice)" zpool destroy $RPOOL 2> /dev/null || true log "Creating root pool with: zpool create -f $RPOOL $ztype $ztgt" - # Just let "zpool create" do its thing. We want GPT disks now. - zpool create -f $RPOOL $ztype $ztgt || bomb "Failed to create root pool $RPOOL" + # Just let "zpool create" do its thing. + # We want GPT disks with a UEFI system partition now. + zpool create -fB $RPOOL $ztype $ztgt \ + || bomb "Failed to create root pool $RPOOL" } BuildRpool() { BuildRpoolOnly $* diff --git a/install_help.sh b/install_help.sh index 098a978..160d37c 100644 --- a/install_help.sh +++ b/install_help.sh @@ -49,14 +49,22 @@ log() { echo "[$TS] $*" 1>&4 echo "[$TS] $*" } +slog() { + if [ -n "$USE_DIALOG" ]; then + echo "[$TS] $*" 1>&4 + d_info "$@" + else + log "$@" + fi +} bomb() { log log ====================================================== log "$*" log ====================================================== if [[ -n "$INSTALL_LOG" ]]; then - log "For more information, check $INSTALL_LOG" - log ====================================================== + log "For more information, check $INSTALL_LOG" + log ====================================================== fi exit 1 } @@ -113,7 +121,7 @@ BE_Receive_Image() { local _bename="${4:?bename}" local _media="${5:?media}" - log "Receiving image: $MEDIA" + slog "Preparing to install ZFS image" pv="pv -B 128m" [ "$_grab" = cat ] && pv+=" -s `ls -lh $_media | awk '{print $5}'`" @@ -135,7 +143,7 @@ BE_Mount() { local _root=${3:?root} local _method${4:-beadm} - log "Mounting BE $_bename on $_root" + slog "Mounting BE $_bename on $_root" if [ "$_method" = beadm ]; then beadm mount $_bename $_root @@ -150,7 +158,7 @@ BE_Umount() { local _root=${2:?root} local _method${3:-beadm} - log "Unmounting BE $_bename" + slog "Unmounting BE $_bename" if [ "$_method" = beadm ]; then beadm umount $_bename else @@ -166,7 +174,7 @@ BE_SetUUID() { local uuid=`LD_LIBRARY_PATH=$_root/lib:$_root/usr/lib \ $_root/usr/bin/uuidgen` - log "Setting BE $_bename UUID: $uuid" + slog "Setting BE $_bename UUID: $uuid" zfs set org.opensolaris.libbe:uuid=$uuid $_rpool/ROOT/$_bename zfs set org.opensolaris.libbe:policy=static $_rpool/ROOT/$_bename } @@ -174,7 +182,7 @@ BE_SetUUID() { BE_SeedSMF() { local _root=${1:?root} - log "Seeding SMF database" + slog "Seeding SMF database" cp $_root/lib/svc/seed/global.db $_root/etc/svc/repository.db chmod 0600 $_root/etc/svc/repository.db chown root:sys $_root/etc/svc/repository.db @@ -242,29 +250,15 @@ FetchConfig(){ MakeBootable(){ local _rpool=${1:-rpool} local _bename=${2:-omnios} - log "Making boot environment bootable" + slog "Making boot environment bootable" zpool set bootfs=$_rpool/ROOT/$_bename $_rpool # Must do beadm activate first on the off chance we're bootstrapping from # GRUB. + slog "Activating BE" beadm activate omnios || return 1 - - if [ -n "$1" ]; then - # Generate kayak-disk-list from zpool status. - # NOTE: If this is something on non-s0 slices, the installboot below - # will fail most likely, which is possibly a desired result. - zpool list -Hv $_rpool | nawk ' - NR > 1 && $1 ~ /c[0-9]/ { - sub("s0$", "", $1) - print $1 - }' > /tmp/kayak-disk-list - fi - - # NOTE: This installboot loop assumes we're doing GPT whole-disk rpools. - for i in `cat /tmp/kayak-disk-list`; do - echo "Installing loader bootblocks on /dev/rdsk/${i}s0" - installboot -mfF /boot/pmbr /boot/gptzfsboot /dev/rdsk/${i}s0 || return 1 - done - + slog "Installing bootloader" + bootadm install-bootloader -f -P $_rpool || return 1 + slog "Updating boot archive" bootadm update-archive -R $ALTROOT || return 1 return 0 } diff --git a/usbgen.sh b/usbgen.sh deleted file mode 100755 index cb548b0..0000000 --- a/usbgen.sh +++ /dev/null @@ -1,413 +0,0 @@ -#!/usr/bin/ksh93 - -# -# 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 -# or http://www.opensolaris.org/os/licensing. -# 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 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -# -# Generate USB image from iso -# Originally from slim_install, modified by Toomas Soome. -# - -# Solaris needs /usr/xpg4/bin/ because the tools in /usr/bin are not -# POSIX-conformant -export PATH=/usr/xpg4/bin:/bin:/usr/bin:/usr/sbin - -# Make sure all math stuff runs in the "C" locale to avoid problems -# with alternative # radix point representations (e.g. ',' instead of -# '.' in de_DE.*-locales). This needs to be set _before_ any -# floating-point constants are defined in this script). -if [[ "${LC_ALL}" != "" ]] ; then - export \ - LC_MONETARY="${LC_ALL}" \ - LC_MESSAGES="${LC_ALL}" \ - LC_COLLATE="${LC_ALL}" \ - LC_CTYPE="${LC_ALL}" - unset LC_ALL -fi -export LC_NUMERIC=C - -####################################################################### -# usage -# Print the usage message. -# Input: none -# Returns: none -# -####################################################################### -function usage -{ - print -u2 "\nUsage: " - print -u2 "${progname} iso_file usb_image tmpdir" - print -u2 "iso_file : The path to an existing iso file." - print -u2 "usb_image : The path to usb image to be created." - print -u2 "tmpdir : Temporary directy used during usb image " \ - "creation.\n" - - print -u2 "If tmpdir does not exist it will be created. If " \ - "it or subdirectories under tmpdir can not be created " \ - " an error is generated and this script exits." - -} - -####################################################################### -# get_filesize -# Get filesize for the file argv[2] and return it to the -# variable defined by argv[1]. -# Input: -# $1 - variable to return filesize in -# $2 - file to query -# -# Returns: -# $1 - variable to return filesize in -# -# -1 if file does not exist -# -# A non-zero exit code only for internal errors and success -# in all other cases -# -####################################################################### -function get_filesize -{ - set -o errexit - nameref filesize_ret="$1" # return filesize into this varable - typeset filename="$2" # file to query - integer filesize=-1 # temporary integer for "read" below - typeset dummy # dummy string - - if [[ -f "${filename}" ]] ; then - ls -lb "${filename}" | \ - grep "${filename}" | \ - read dummy dummy dummy dummy filesize dummy - fi - - (( filesize_ret=filesize )) - return 0 -} - -# -# -####################################################################### -# cleanup -# This function attempst to clean up any resources this script -# could generate. Depending on where in the script this function -# is involked some resouces may not be there to cleanup, but -# that will not adversely effect anything. -# -# This function is not defined using the function keyword -# to avoid an exit loop. -# -# Input: none -# Returns: none -# -####################################################################### -cleanup () -{ - - { - trap "" ERR INT - set +o errexit - - # unmounting, and uninstalling the lofi'ed devices and - # cleanup temporary files. - IFS='' - - typeset mount_output="$(mount)" - - [[ "${mount_output}" == ~(E).*"${usb_path}".* ]] && \ - umount "${usb_path}" - - [[ "${mount_output}" == ~(E).*"${iso_path}".* ]] && \ - umount "${iso_path}" - - lofiadm "${usb_file}" && \ - lofiadm -d "${usb_file}" - - lofiadm "${iso_file}" && \ - lofiadm -d "${iso_file}" - - if [[ -d "${iso_path}" ]] ; then - rm -rf "${iso_path}" - fi - - if [[ -d "${usb_path}" ]] ; then - rm -rf "${usb_path}" - fi - - # - # If the tmpdir did not exist this script could - # have created it, so remove it here. - # - if ! ${tmpdir_existed} ; then - rm -rf "${tmpdir}" - fi - } > /dev/null 2>&1 - -} - -####################################################################### -# error_handler -# The error_handler for this script. Will cleanup the usb image -# that could have been partially created. Then invoke cleanup -# to clean up any temporary resouces. -# -# This function is not defined using the function keyword -# to avoid an exit loop. -# -# Input: none -# Returns: none -# -####################################################################### -error_handler () -{ - trap "" ERR INT - set +o errexit - - print -u2 "\nError:\n" - print -u2 -r -- "${progname}: $*" - cleanup - - # - # If an error was encountered while attempting to create - # the new usb image file don't leave a possibley partially - # constructed one around. - # - if [[ -f "${usb_file}" ]] ; then - rm -rf "${usb_file}" > /dev/null 2>&1 - fi - - exit 1 -} - -# main -####################################################################### -# main -# -# Input: -# iso_file : The path to an existing iso file. -# usb_image : The path to usb image to be created. -# tmpdir : Temporary directroy used during usb image creation. -# -# If tmpdir does not exist it will be created. If it can not be -# created an error is generated and this script exits. -# -# This script must be run as root" -# -# Logic Flow: -# Set up error handling. -# Confirm input arguments. -# Create temporary directories. -# Mount up the existing ISO image file. -# Compute the size for the new USB image. -# Create and mount an empty new USB image. -# Copy the contents of the ISO file to the new USB image. -# Remove GRUB entries from the USB image which apply only to ISO. -# Set the file protections for the new USB image. -# -# Returns: -# 1 on failure -# 0 on success -# -####################################################################### -builtin chmod -builtin cp -builtin mkdir -builtin mv -builtin rm - -typeset -r progname="$0" -typeset -r iso_file="$1" -typeset -r tmpdir="$3" -typeset tmpdir_existed=true -typeset -r iso_path="${tmpdir}/iso" - -typeset -r usb_file="$2" -typeset -r usb_path="${tmpdir}/usb" -float usb_size # need floating-point for the calculations below - -typeset isodev -typeset devs -typeset rdevs -typeset s0devs -typeset rs0devs -typeset rs2devs - -# -# Confirm input arguments. -# -if [[ $(id) != ~(E).*uid=0\(root\).* ]]; then - print -u2 "Error:\nYou must run this script as root" - usage - exit 1 -fi - -if (( $# != 3 )) ; then - print -u2 "Error:\nImproper arguments" - usage - exit 1 -fi - -# -# Set up error handling. -# Use set -o errexit to trap errors. However, where possible, -# explicitly check command return status for errors. -# -trap "error_handler Error or interrupt encountered. Exiting" ERR INT -set -o errexit - -# -# Create temporary directories. -# -[[ ! -d $tmpdir ]] && tmpdir_existed=false -mkdir -p "${iso_path}" -if [[ ! -d "${iso_path}" ]] ; then - error_handler "Unable to create or access tmpdir ${iso_path}" -fi - -mkdir -p "${usb_path}" -if [[ ! -d "${usb_path}" ]] ; then - error_handler "Unable to create or access tmpdir ${usb_path}" -fi - -# -# Mount up the existing ISO image file. -# -isodev="$(lofiadm -a "${iso_file}")" || \ - error_handler "Failed to lofiadm ${iso_file}" - -mount -F hsfs "${isodev}" "${iso_path}" || \ - error_handler "Failed to mount ${isodev} on ${iso_path}" - - -# -# Compute the size for the new USB image. -# Use ISO file size + 20% to account for smaller block size on UFS -# and the log. Round to nearest kbyte plus 512 -# plus 4MB for MBR+SMI label -# -get_filesize "usb_size" "${iso_file}" -if (( usb_size == -1 )) ; then - error_handler "Failed to get size of file ${iso_file}" -fi -(( usb_size=((int( (usb_size * 1.2) / 1024.) * 1024.) + 512) + 4194304 )) - -# -# Create and mount an empty new USB image. -# -mkfile -n ${usb_size} "${usb_file}" || \ - error_handler "Failed to create file ${usb_file}" - -devs="$(lofiadm -la "${usb_file}")" || \ - error_handler "Failed to lofiadm file ${usb_file}" - -# -# Set rdevs by replacing dsk with rdsk in devs -# -rdevs="${devs/dsk/rdsk}" -# for mount -s0devs="${devs/p0/s0}" -# for newfs and installboot -rs0devs="${rdevs/p0/s0}" -# for prtvtoc | fmthard -rs2devs="${rdevs/p0/s2}" - -# -# create Solaris2 partition -# -fdisk -B "${rdevs}" -prtvtoc "${rs2devs}" | nawk ' -/^[^\*]/ { r = $1; for(n = 1; n <= NF; n++) vtoc[r,n] = $n } -END { -vtoc[0,1] = 0; -vtoc[0,2] = 2; -vtoc[0,3] = 00; -vtoc[0,4] = vtoc[8,6] + 1; -vtoc[0,5] = vtoc[2,6] - vtoc[8,6]; -vtoc[0,6] = vtoc[2,6]; -printf("\t%d\t%d\t%02d\t%d\t%d\t%d\n", - vtoc[0,1], vtoc[0,2], vtoc[0,3], vtoc[0,4], vtoc[0,5], vtoc[0,6]); -printf("\t%d\t%d\t%02d\t%d\t%d\t%d\n", - vtoc[2,1], vtoc[2,2], vtoc[2,3], vtoc[2,4], vtoc[2,5], vtoc[2,6]); -printf("\t%d\t%d\t%02d\t%d\t%d\t%d\n", - vtoc[8,1], vtoc[8,2], vtoc[8,3], vtoc[8,4], vtoc[8,5], vtoc[8,6]); -}' | fmthard -s- "${rs2devs}" - -# newfs doesn't ask questions if stdin isn't a tty. -newfs "${rs0devs}" ${usb_path}/boot/grub/menu2.lst -if [[ $? == 0 ]] ; then - mv ${usb_path}/boot/grub/menu2.lst ${usb_path}/boot/grub/menu.lst -else - print -u2 "Warning: Could not remove \"Hard Disk\" entry from boot menu" -fi - -# -# Set the file protections for the new USB image. -# -chmod 444 "${usb_file}" - -# -# unmounting, and uninstalling the lofi'ed devices -# -cleanup - -printf "=== %s completed at %s\n\n" "$0" "$(date)" - -exit 0 -