3 # Copyright 2012 Hewlett-Packard Development Company, L.P.
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
18 # This script generates iso image from the given kernel and ramdisk
20 SCRIPTNAME=`basename $0`
21 TMP_BUILD_DIR="/tmp/$SCRIPTNAME.$$"
22 QEMU_IMG="/usr/bin/qemu-img"
23 MKISOFS="/usr/bin/mkisofs"
26 function show_options() {
28 echo "Usage: ${SCRIPTNAME} [options]"
32 echo " -o output filename "
39 v_print "Cleaning up.."
43 function err_print() {
44 echo "ERROR: $@" 1>&2;
53 # Parse command line options
54 ARGS=`getopt -o "o:i:k:" -l "output,initrd,kernel:" \
55 -n "$SCRIPTNAME" -- "$@"`
65 -o) OUTPUT_FILENAME=$2; shift 2 ;;
66 -i) INITRD=$2; shift 2 ;;
67 -k) KERNEL=$2; shift 2 ;;
68 # *) show_options ; exit 1 ;;
73 # Verify whether kernel, initrd, and the image file is present
74 if [ -z "$OUTPUT_FILENAME" ]; then
75 err_print "Output filename not provided."
80 if [ -z "$INITRD" ]; then
81 err_print "Initrd not provided."
86 if [ -z "$KERNEL" ]; then
87 err_print "Kernel not provided."
92 # Create a temporary build directory for holiding the contents of iso
93 TMP_IMAGE_DIR="$TMP_BUILD_DIR/image"
94 v_print "Creating temporary directory $TMP_IMAGE_DIR"
95 mkdir -p "$TMP_IMAGE_DIR"
97 # Copy isolinux bin to the isolinux directory
98 mkdir -p "$TMP_IMAGE_DIR/isolinux"
99 v_print "Copying isolinux.bin"
100 if [ -f /usr/share/syslinux/isolinux.bin ]
102 cp /usr/share/syslinux/isolinux.bin "$TMP_IMAGE_DIR/isolinux"
104 elif [ -f /usr/lib/syslinux/isolinux.bin ]
106 cp /usr/lib/syslinux/isolinux.bin "$TMP_IMAGE_DIR/isolinux"
108 err_print "Could not find isolinux.bin. Install syslinux?"
114 # Copy initrd, kernel
115 v_print "Copying kernel to $TMP_IMAGE_DIR/vmlinuz"
116 cp $KERNEL "$TMP_IMAGE_DIR/vmlinuz"
117 if [ $? -ne 0 ]; then
118 err_print "Failed to copy $KERNEL to $TMP_IMAGE_DIR"
123 v_print "Copying initrd to $TMP_IMAGE_DIR/initrd"
124 cp $INITRD "$TMP_IMAGE_DIR/initrd"
125 if [ $? -ne 0 ]; then
126 err_print "Failed to copy $INITRD to $TMP_IMAGE_DIR"
131 # Generate isolinux.cfg for default booting
132 v_print "Generating isolinux.cfg"
136 menu label "Install image"
138 append initrd=/initrd boot_method=vmedia console=tty0 console=ttyS1,115200 selinux=0 --
140 PROMPT 0 " > "$TMP_IMAGE_DIR/isolinux/isolinux.cfg"
142 # Convert relative path output filename to absolute path
143 echo $OUTPUT_FILENAME | grep -q '^/'
144 if [ $? -ne 0 ]; then
145 OUTPUT_FILENAME="$PWD/$OUTPUT_FILENAME"
149 v_print "Generating the ISO"
150 cd $TMP_IMAGE_DIR && $MKISOFS -r -V "INSTALL_IMAGE" -cache-inodes -J -l -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -o $OUTPUT_FILENAME .