Home | History | Annotate | Download | only in livemedia
      1  33  dave #!/usr/bin/bash
      2  33  dave #
      3  33  dave # CDDL HEADER START
      4  33  dave #
      5  33  dave # The contents of this file are subject to the terms of the
      6  33  dave # Common Development and Distribution License (the "License").
      7  33  dave # You may not use this file except in compliance with the License.
      8  33  dave #
      9  33  dave # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  33  dave # or http://www.opensolaris.org/os/licensing.
     11  33  dave # See the License for the specific language governing permissions
     12  33  dave # and limitations under the License.
     13  33  dave #
     14  33  dave # When distributing Covered Code, include this CDDL HEADER in each
     15  33  dave # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  33  dave # If applicable, add the following below this CDDL HEADER, with the
     17  33  dave # fields enclosed by brackets "[]" replaced with your own identifying
     18  33  dave # information: Portions Copyright [yyyy] [name of copyright owner]
     19  33  dave #
     20  33  dave # CDDL HEADER END
     21  33  dave #
     22  33  dave # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     23  33  dave # Use is subject to license terms.
     24  33  dave #
     25  33  dave # Generate USB image from iso
     26  33  dave 
     27  33  dave source build_live_dvd.conf
     28  33  dave 
     29  33  dave echo "=== $0 started at `date`"
     30  33  dave 
     31  33  dave ISO_PATH=$TMPDIR/iso
     32  33  dave [ -d $ISO_PATH ] || mkdir -p $ISO_PATH
     33  33  dave USB_PATH=$TMPDIR/usb
     34  33  dave [ -d $USB_PATH ] || mkdir -p $USB_PATH
     35  33  dave isodev=`lofiadm -a $ISO_FILE` || exit
     36  33  dave mount -F hsfs $isodev $ISO_PATH
     37  33  dave 
     38  33  dave if [ -n "$USB_ZVOL" ]; then
     39  33  dave 	zfs list $USB_ZVOL >/dev/null 2>&1 && zfs destroy $USB_ZVOL
     40  33  dave 	zfs create -b 512 -V $USB_SIZE $USB_ZVOL
     41  33  dave 	if [ $? != 0 ]; then
     42  33  dave 		echo "Unable to create $USB_ZVOL for USB generation"
     43  33  dave 		exit 1
     44  33  dave 	fi
     45  33  dave 	rdevs=/dev/zvol/rdsk/$USB_ZVOL
     46  33  dave 	devs=/dev/zvol/dsk/$USB_ZVOL
     47  33  dave else
     48  33  dave 	mkfile -n $USB_SIZE $USB_FILE
     49  33  dave 	devs=`lofiadm -a $USB_FILE`
     50  33  dave 	rdevs=`echo $devs|sed -e 's/lofi/rlofi/'`
     51  33  dave fi
     52  33  dave yes | newfs $rdevs || exit
     53  38  dave mount -o nologging $devs $USB_PATH || exit
     54  33  dave 
     55  33  dave # Copy ISO contents to USB
     56  33  dave echo "Copying ISO contents to USB image"
     57  33  dave cd $ISO_PATH
     58  33  dave find . -print|cpio -pmudV $USB_PATH
     59  33  dave 
     60  38  dave # Remove GRUB entries which apply only to DVD
     61  38  dave sed -e '/tracing/,$d' $USB_PATH/boot/grub/menu.lst > $USB_PATH/boot/grub/menu2.lst
     62  33  dave rm $USB_PATH/boot/grub/menu.lst
     63  33  dave mv $USB_PATH/boot/grub/menu2.lst $USB_PATH/boot/grub/menu.lst
     64  33  dave 
     65  33  dave # Now mount microroot and make required changes for USB
     66  33  dave echo "Creating temporary microroot"
     67  33  dave cp $ISO_PATH/boot/x86.microroot $TMPDIR/x86.microroot.gz
     68  33  dave 
     69  33  dave cd $TMPDIR
     70  33  dave gunzip $TMPDIR/x86.microroot.gz
     71  33  dave TMP_MICROROOT=$TMPDIR/microroot
     72  33  dave [ -d $TMP_MICROROOT ] || mkdir $TMP_MICROROOT
     73  33  dave mount -F ufs -o nologging `lofiadm -a $TMPDIR/x86.microroot` $TMP_MICROROOT
     74  33  dave 
     75  33  dave # Creating the new microroot for USB
     76  33  dave echo "Replacing USB specific files"
     77  33  dave cd $TMP_MICROROOT
     78  33  dave touch $TMP_MICROROOT/.liveusb
     79  33  dave cp $LIVEKIT/listusb sbin/
     80  33  dave 
     81  33  dave cd $TMPDIR
     82  33  dave umount $TMP_MICROROOT
     83  33  dave gzip -9 $TMPDIR/x86.microroot
     84  33  dave 
     85  33  dave echo "Copying microroot to USB"
     86  33  dave rm $USB_PATH/boot/x86.microroot
     87  33  dave cp $TMPDIR/x86.microroot.gz $USB_PATH/boot/x86.microroot
     88  33  dave 
     89  33  dave # unmounting, and uninstalling the lofi'ed devices
     90  33  dave echo "Cleaning up."
     91  33  dave umount $USB_PATH
     92  33  dave umount $ISO_PATH
     93  33  dave lofiadm -d $TMPDIR/x86.microroot
     94  33  dave lofiadm $devs >/dev/null 2>&1 && lofiadm -d $devs
     95  33  dave lofiadm -d $isodev
     96  33  dave 
     97  33  dave echo "=== $0 completed at `date`"
     98