3 # Create an Ovirt Host USB device (stateful)
4 # Copyright 2008 Red Hat, Inc.
5 # Written by Chris Lalancette <clalance@redhat.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 warn
() { printf '%s: %s\n' "$ME" "$*" >&2; }
22 die
() { warn
"$@"; exit 1; }
24 test $# != 2 && die
"Usage: $ME <usbdevice> <iso-image>"
29 test ! -r $ISO && die
"$ISO is not a readable file"
30 test ! -b $USBDEVICE && die
"$USBDEVICE is not a valid block device"
31 test $
( id
-u ) -ne 0 && die
"$ME must run as root"
33 IMGTMP
=/var
/tmp
/ovirt-$$
34 SQUASHTMP
=/var
/tmp
/ovirt-squash-$$
35 USBTMP
=/var
/tmp
/ovirt-usb-$$
38 mkdir
-p $IMGTMP $SQUASHTMP $USBTMP
39 mount
-o loop
$ISO $IMGTMP
40 mount
-o loop
$IMGTMP/LiveOS
/squashfs.img
$SQUASHTMP
42 # clear out the old partition table
43 dd if=/dev
/zero of
=$USBDEVICE bs
=4096 count
=1
44 printf 'n\np\n1\n\n\nt\n83\na\n1\nw\n' | fdisk
$USBDEVICE
46 cat /usr
/lib
/syslinux
/mbr.bin
> $USBDEVICE
47 dd if=$SQUASHTMP/LiveOS
/ext3fs.img of
=${USBDEVICE}1
49 mount
${USBDEVICE}1 $USBTMP
51 cp $IMGTMP/isolinux
/* $USBTMP
53 rm -f $USBTMP/isolinux.bin
54 mv $USBTMP/isolinux.cfg
$USBTMP/extlinux.conf
56 LABEL
=`echo $ISO | cut -d'.' -f1 | cut -c-16`
57 sed -i -e "s/ *append.*/ append initrd=initrd.img root=LABEL=$LABEL ro/" $USBTMP/extlinux.conf
64 rm -rf $SQUASHTMP $IMGTMP $USBTMP