Home | History | Annotate | Download | only in livemedia
      1 #!/usr/bin/bash
      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 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     23 # Use is subject to license terms.
     24 #
     25 # Generate USB image from iso
     26 
     27 source build_live_dvd.conf
     28 
     29 echo "=== $0 started at `date`"
     30 
     31 ISO_PATH=$TMPDIR/iso
     32 [ -d $ISO_PATH ] || mkdir -p $ISO_PATH
     33 USB_PATH=$TMPDIR/usb
     34 [ -d $USB_PATH ] || mkdir -p $USB_PATH
     35 isodev=`lofiadm -a $ISO_FILE` || exit
     36 mount -F hsfs $isodev $ISO_PATH
     37 
     38 if [ -n "$USB_ZVOL" ]; then
     39 	zfs list $USB_ZVOL >/dev/null 2>&1 && zfs destroy $USB_ZVOL
     40 	zfs create -b 512 -V $USB_SIZE $USB_ZVOL
     41 	if [ $? != 0 ]; then
     42 		echo "Unable to create $USB_ZVOL for USB generation"
     43 		exit 1
     44 	fi
     45 	rdevs=/dev/zvol/rdsk/$USB_ZVOL
     46 	devs=/dev/zvol/dsk/$USB_ZVOL
     47 else
     48 	mkfile -n $USB_SIZE $USB_FILE
     49 	devs=`lofiadm -a $USB_FILE`
     50 	rdevs=`echo $devs|sed -e 's/lofi/rlofi/'`
     51 fi
     52 yes | newfs $rdevs || exit
     53 mount -o nologging $devs $USB_PATH || exit
     54 
     55 # Copy ISO contents to USB
     56 echo "Copying ISO contents to USB image"
     57 cd $ISO_PATH
     58 find . -print|cpio -pmudV $USB_PATH
     59 
     60 # Remove GRUB entries which apply only to DVD
     61 sed -e '/tracing/,$d' $USB_PATH/boot/grub/menu.lst > $USB_PATH/boot/grub/menu2.lst
     62 rm $USB_PATH/boot/grub/menu.lst
     63 mv $USB_PATH/boot/grub/menu2.lst $USB_PATH/boot/grub/menu.lst
     64 
     65 # Now mount microroot and make required changes for USB
     66 echo "Creating temporary microroot"
     67 cp $ISO_PATH/boot/x86.microroot $TMPDIR/x86.microroot.gz
     68 
     69 cd $TMPDIR
     70 gunzip $TMPDIR/x86.microroot.gz
     71 TMP_MICROROOT=$TMPDIR/microroot
     72 [ -d $TMP_MICROROOT ] || mkdir $TMP_MICROROOT
     73 mount -F ufs -o nologging `lofiadm -a $TMPDIR/x86.microroot` $TMP_MICROROOT
     74 
     75 # Creating the new microroot for USB
     76 echo "Replacing USB specific files"
     77 cd $TMP_MICROROOT
     78 touch $TMP_MICROROOT/.liveusb
     79 cp $LIVEKIT/listusb sbin/
     80 
     81 cd $TMPDIR
     82 umount $TMP_MICROROOT
     83 gzip -9 $TMPDIR/x86.microroot
     84 
     85 echo "Copying microroot to USB"
     86 rm $USB_PATH/boot/x86.microroot
     87 cp $TMPDIR/x86.microroot.gz $USB_PATH/boot/x86.microroot
     88 
     89 # unmounting, and uninstalling the lofi'ed devices
     90 echo "Cleaning up."
     91 umount $USB_PATH
     92 umount $ISO_PATH
     93 lofiadm -d $TMPDIR/x86.microroot
     94 lofiadm $devs >/dev/null 2>&1 && lofiadm -d $devs
     95 lofiadm -d $isodev
     96 
     97 echo "=== $0 completed at `date`"
     98