36b59c001c
There is a wide variety of tracing options through the various shell scripts. Some use "set -eux", others explicity set xtrace and others do nothing. There is a "-x" option to bin/disk-image-create but it doesn't flow down to the many scripts it calls. This adds a global integer variable set by disk-image-create DIB_DEBUG_TRACE. All scripts have a stanza added to detect this and turn on tracing. Any other tracing methods are rolled into this. So the standard header is --- if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then set -x fi set -eu set -o pipefail --- Multiple -x options can be specified to dib-create-image, which increases the value of DIB_DEBUG_TRACE. If script authors feel their script should only trace at higher levels, they should modify the "-gt" value. If they feel it should trace by default, they can modify the default value also. Changes to pachset 16 : scripts which currently trace themselves by default have retained this behaviour with DIB_DEBUG_TRACE defaulting to "1". This was done by running [1] on patch set 15. See the thread beginning at [2] dib-lint is also updated to look for the variable being matched. [1] https://gist.github.com/ianw/71bbda9e6acc74ccd0fd [2] http://lists.openstack.org/pipermail/openstack-dev/2014-November/051575.html Change-Id: I6c5a962260741dcf6f89da9a33b96372a719b7b0
163 lines
5.3 KiB
Bash
Executable file
163 lines
5.3 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
|
set -x
|
|
fi
|
|
set -eu
|
|
set -o pipefail
|
|
|
|
function build_efiboot_img() {
|
|
|
|
cat > "$TMP_BUILD_DIR/grub-embedded.cfg" << END_CONFIG
|
|
search --set=root --label VMEDIA_BOOT_ISO
|
|
set prefix=(\$root)/EFI/BOOT/
|
|
END_CONFIG
|
|
|
|
grub-mkimage --format=x86_64-efi --output=$TMP_BUILD_DIR/bootx64.efi \
|
|
--config=$TMP_BUILD_DIR/grub-embedded.cfg --compression=xz \
|
|
--prefix=/EFI/BOOT part_gpt part_msdos fat ext2 hfs hfsplus \
|
|
iso9660 udf ufs1 ufs2 zfs chain linux boot appleldr ahci \
|
|
configfile normal regexp minicmd reboot halt search \
|
|
search_fs_file search_fs_uuid search_label gfxterm gfxmenu \
|
|
efi_gop efi_uga all_video loadbios gzio echo true probe \
|
|
loadenv bitmap_scale font cat help ls png jpeg tga test \
|
|
at_keyboard usb_keyboard
|
|
|
|
# Create a FAT formatted image that contains bootx64.efi in the /EFI/BOOT
|
|
# directory. This is used to bootstrap GRUB from the ISO image.
|
|
dd if=/dev/zero of=$TMP_BUILD_DIR/efiboot.img bs=1K count=1440
|
|
mkdosfs -F 12 $TMP_BUILD_DIR/efiboot.img
|
|
|
|
# Create a temporary mount point:
|
|
MOUNTPOINT=$TMP_BUILD_DIR/tmpmount
|
|
mkdir $MOUNTPOINT
|
|
sudo mount -o loop $TMP_BUILD_DIR/efiboot.img $MOUNTPOINT
|
|
sudo mkdir -p $MOUNTPOINT/EFI/BOOT
|
|
sudo cp $TMP_BUILD_DIR/bootx64.efi $MOUNTPOINT/EFI/BOOT
|
|
sudo umount $MOUNTPOINT
|
|
rmdir $MOUNTPOINT
|
|
cp $TMP_BUILD_DIR/efiboot.img $TMP_IMAGE_DIR/isolinux
|
|
}
|
|
|
|
function build_iso() {
|
|
|
|
KERNEL=$1
|
|
INITRD=$2
|
|
KERNEL_CMDLINE_ARGS=$3
|
|
OUTPUT_FILENAME=$4
|
|
|
|
SCRIPTNAME=$(basename $0)
|
|
SCRIPTDIR=$(dirname $0)
|
|
MKISOFS="/usr/bin/mkisofs"
|
|
EFI_BOOT_DIR="EFI/BOOT"
|
|
|
|
# Create a temporary build directory for holiding the contents of iso
|
|
TMP_IMAGE_DIR="$TMP_BUILD_DIR/image"
|
|
echo "Creating temporary directory $TMP_IMAGE_DIR"
|
|
mkdir -p "$TMP_IMAGE_DIR"
|
|
|
|
# Copy isolinux bin to the isolinux directory
|
|
mkdir -p "$TMP_IMAGE_DIR/isolinux"
|
|
echo "Copying isolinux.bin"
|
|
|
|
# TODO(rameshg87): Something similar to pkg-map can be used here.
|
|
# But pkg-map doesn't work for cleanup scripts right now.
|
|
if [ $DISTRO_NAME = "fedora" ]; then
|
|
ISOLINUX_BIN=/usr/share/syslinux/isolinux.bin
|
|
else
|
|
ISOLINUX_BIN=/usr/lib/syslinux/isolinux.bin
|
|
fi
|
|
|
|
cp $ISOLINUX_BIN "$TMP_IMAGE_DIR/isolinux"
|
|
|
|
# Copy initrd, kernel
|
|
echo "Copying kernel to $TMP_IMAGE_DIR/vmlinuz"
|
|
cp $KERNEL "$TMP_IMAGE_DIR/vmlinuz"
|
|
|
|
echo "Copying initrd to $TMP_IMAGE_DIR/initrd"
|
|
cp $INITRD "$TMP_IMAGE_DIR/initrd"
|
|
|
|
# Generate isolinux.cfg for default booting
|
|
echo "Generating isolinux.cfg"
|
|
cat > "$TMP_IMAGE_DIR/isolinux/isolinux.cfg" << END_CONFIG
|
|
DEFAULT install
|
|
LABEL install
|
|
menu label "Install image"
|
|
kernel /vmlinuz
|
|
append initrd=/initrd $KERNEL_CMDLINE_ARGS --
|
|
TIMEOUT 5
|
|
PROMPT 0
|
|
END_CONFIG
|
|
|
|
|
|
echo "Creating EFI/BOOT directory"
|
|
mkdir -p "$TMP_IMAGE_DIR/$EFI_BOOT_DIR"
|
|
|
|
# Generate grub.cfg for default booting
|
|
echo "Generating grub.cfg"
|
|
cat > "$TMP_IMAGE_DIR/$EFI_BOOT_DIR/grub.cfg" << END_CONFIG
|
|
set default="0"
|
|
set timeout="5"
|
|
set hidden_timeout_quiet=false
|
|
|
|
menuentry "install" {
|
|
linux /vmlinuz $KERNEL_CMDLINE_ARGS --
|
|
initrd /initrd
|
|
}
|
|
END_CONFIG
|
|
|
|
|
|
DIB_UEFI_ISO_BUILD_EFIBOOT=${DIB_UEFI_ISO_BUILD_EFIBOOT:-}
|
|
if [ -n "$DIB_UEFI_ISO_BUILD_EFIBOOT" ]; then
|
|
build_efiboot_img
|
|
else
|
|
cp $SCRIPTDIR/efiboot.img $TMP_IMAGE_DIR/isolinux
|
|
fi
|
|
|
|
# Create the ISO
|
|
echo "Generating the ISO"
|
|
$MKISOFS -r -V "VMEDIA_BOOT_ISO" -cache-inodes -J -l \
|
|
-b isolinux/isolinux.bin -no-emul-boot \
|
|
-boot-load-size 4 -boot-info-table \
|
|
-eltorito-alt-boot -e isolinux/efiboot.img \
|
|
-no-emul-boot -o $OUTPUT_FILENAME $TMP_IMAGE_DIR
|
|
|
|
}
|
|
|
|
IMAGE_NAME=${IMAGE_NAME:-'image'}
|
|
|
|
if echo $IMAGE_ELEMENT | grep -q '\bramdisk\b'; then
|
|
EMITTED_KERNEL=$IMAGE_NAME.kernel
|
|
EMITTED_RAMDISK=$IMAGE_NAME.initramfs
|
|
EMITTED_KERNEL_CMDLINE_ARGS="boot_method=vmedia"
|
|
EMITTED_ISO_FILENAME=$IMAGE_NAME.iso
|
|
elif echo $IMAGE_ELEMENT | grep -q '\bbaremetal\b'; then
|
|
EMITTED_KERNEL=${IMAGE_NAME}.vmlinuz
|
|
EMITTED_RAMDISK=${IMAGE_NAME}.initrd
|
|
EMITTED_KERNEL_CMDLINE_ARGS="root=UUID=$DIB_IMAGE_ROOT_FS_UUID"
|
|
DIB_BOOT_ISO_KERNEL_CMDLINE_ARGS=${DIB_BOOT_ISO_KERNEL_CMDLINE_ARGS:-}
|
|
if [ -n "$DIB_BOOT_ISO_KERNEL_CMDLINE_ARGS" ]; then
|
|
EMITTED_KERNEL_CMDLINE_ARGS="$EMITTED_KERNEL_CMDLINE_ARGS $DIB_BOOT_ISO_KERNEL_CMDLINE_ARGS"
|
|
fi
|
|
export EMITTED_ISO_FILENAME="$IMAGE_NAME-boot.iso"
|
|
else
|
|
echo "Cannot find the kernel/ramdisk to build the iso image. "
|
|
echo "Please use 'iso' element with either 'baremetal' or 'ramdisk' elements"
|
|
fi
|
|
|
|
build_iso "$EMITTED_KERNEL" "$EMITTED_RAMDISK" "$EMITTED_KERNEL_CMDLINE_ARGS" \
|
|
"$EMITTED_ISO_FILENAME"
|