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 "
35 echo " -e efiboot.img "
36 echo " -E EFI directory "
41 v_print "Cleaning up.."
45 function err_print() {
46 echo "ERROR: $@" 1>&2;
55 # Parse command line options
56 ARGS=`getopt -o "o:i:k:e:E:" -l "output,initrd,kernel,efiboot,EFI:" \
57 -n "$SCRIPTNAME" -- "$@"`
67 -o) OUTPUT_FILENAME=$2; shift 2 ;;
68 -i) INITRD=$2; shift 2 ;;
69 -k) KERNEL=$2; shift 2 ;;
70 -e) EFIBOOT=$2; shift 2 ;;
71 -E) EFIDIR=$2; shift 2 ;;
72 # *) show_options ; exit 1 ;;
77 # Verify whether kernel, initrd, and the image file is present
78 if [ -z "$OUTPUT_FILENAME" ]; then
79 err_print "Output filename not provided."
84 if [ -z "$INITRD" ]; then
85 err_print "Initrd not provided."
90 if [ -z "$KERNEL" ]; then
91 err_print "Kernel not provided."
96 if [ -z "$EFIBOOT" ]; then
97 err_print "efiboot.img not provided."
102 if [ -z "$EFIDIR" ]; then
103 err_print "EFI directory not provided."
108 # Create a temporary build directory for holiding the contents of iso
109 TMP_IMAGE_DIR="$TMP_BUILD_DIR/image"
110 v_print "Creating temporary directory $TMP_IMAGE_DIR"
111 mkdir -p "$TMP_IMAGE_DIR"
113 if [ "$(uname -m)" = 'x86_64' ]; then
114 # Copy isolinux bin to the isolinux directory
115 mkdir -p "$TMP_IMAGE_DIR/isolinux"
116 v_print "Copying isolinux.bin"
117 if [ -f /usr/share/syslinux/isolinux.bin ]
119 cp /usr/share/syslinux/isolinux.bin "$TMP_IMAGE_DIR/isolinux"
121 elif [ -f /usr/lib/syslinux/isolinux.bin ]
123 cp /usr/lib/syslinux/isolinux.bin "$TMP_IMAGE_DIR/isolinux"
125 err_print "Could not find isolinux.bin. Install syslinux?"
130 # Copy initrd, kernel
131 v_print "Copying kernel to $TMP_IMAGE_DIR/vmlinuz"
132 cp $KERNEL "$TMP_IMAGE_DIR/vmlinuz"
133 if [ $? -ne 0 ]; then
134 err_print "Failed to copy $KERNEL to $TMP_IMAGE_DIR"
139 v_print "Copying initrd to $TMP_IMAGE_DIR/initrd"
140 cp $INITRD "$TMP_IMAGE_DIR/initrd"
141 if [ $? -ne 0 ]; then
142 err_print "Failed to copy $INITRD to $TMP_IMAGE_DIR"
147 mkdir -p "$TMP_IMAGE_DIR/images"
148 v_print "Copying efiboot image to $TMP_IMAGE_DIR/images/efiboot.img"
149 cp $EFIBOOT "$TMP_IMAGE_DIR/images/efiboot.img"
150 if [ $? -ne 0 ]; then
151 err_print "Failed to copy $EFIBOOT to $TMP_IMAGE_DIR/images"
156 v_print "Copying EFI directory to $TMP_IMAGE_DIR/EFI"
157 cp -r $EFIDIR "$TMP_IMAGE_DIR/EFI"
158 if [ $? -ne 0 ]; then
159 err_print "Failed to copy $EFIDIR to $TMP_IMAGE_DIR/EFI"
163 # Generate grub.cfg for default booting
164 sed -i '/BEGIN/q' "$TMP_IMAGE_DIR/EFI/BOOT/grub.cfg"
166 menuentry 'Install image' --class red --class gnu-linux --class gnu --class os {
167 linux /vmlinuz boot_method=vmedia console=tty0 console=ttyS1,115200 console=ttyS0,115200 console=ttyAMA0,115200 selinux=0
169 }" >> "$TMP_IMAGE_DIR/EFI/BOOT/grub.cfg"
171 if [ "$(uname -m)" = 'x86_64' ]; then
172 # Generate isolinux.cfg for default booting
173 v_print "Generating isolinux.cfg"
177 menu label "Install image"
179 append initrd=/initrd boot_method=vmedia console=tty0 console=ttyS1,115200 selinux=0 --
181 PROMPT 0 " > "$TMP_IMAGE_DIR/isolinux/isolinux.cfg"
184 # Convert relative path output filename to absolute path
185 echo $OUTPUT_FILENAME | grep -q '^/'
186 if [ $? -ne 0 ]; then
187 OUTPUT_FILENAME="$PWD/$OUTPUT_FILENAME"
190 # On x86_64 platforms, use isolinux for BIOS support
191 if [ "$(uname -m)" = 'x86_64' ]; then
192 MKISOFS_ARGS+=" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
193 -boot-load-size 4 -boot-info-table"
196 # efiboot.img path is hard set, create an EFI compatible ISO
197 MKISOFS_ARGS+=" -eltorito-alt-boot -e images/efiboot.img -no-emul-boot"
200 v_print "Generating the ISO"
201 cd $TMP_IMAGE_DIR && $MKISOFS -r -V "INSTALL_IMAGE" -cache-inodes -J -l $MKISOFS_ARGS -o $OUTPUT_FILENAME .
203 if [ $? -ne 0 ]; then
204 err_print "Failed generating the ISO"