2014-10-09 09:54:19 +00:00
|
|
|
#!/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.
|
|
|
|
|
2016-04-08 05:46:21 +00:00
|
|
|
# dib-lint: disable=safe_sudo
|
|
|
|
|
2014-09-04 04:56:29 +00:00
|
|
|
if [ ${DIB_DEBUG_TRACE:-1} -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
set -eu
|
2014-10-09 09:54:19 +00:00
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
function build_efiboot_img() {
|
2015-03-10 07:38:05 +00:00
|
|
|
# Signed bootloader files are saved at tmp/bootloader_files during
|
|
|
|
# post-install stage needs to copy them into image.
|
|
|
|
# Signed bootloader packages used are:-
|
|
|
|
# Ubuntu: grub-efi-amd64-signed and shim-signed
|
|
|
|
# Fedora: grub2-efi and shim
|
2014-10-09 09:54:19 +00:00
|
|
|
|
2018-02-28 12:31:34 +00:00
|
|
|
if [[ $DISTRO_NAME = "fedora" || $DISTRO_NAME = "rhel7" ]] ; then
|
2015-03-10 07:38:05 +00:00
|
|
|
cp $TMP_BOOTLOADER_DIR/shim.efi $TMP_BUILD_DIR/bootx64.efi
|
|
|
|
cp $TMP_BOOTLOADER_DIR/grubx64.efi $TMP_BUILD_DIR/grubx64.efi
|
2021-02-25 15:30:21 +00:00
|
|
|
elif [[ $DISTRO_NAME = "centos" ]] ; then
|
|
|
|
cp $TMP_BOOTLOADER_DIR/shimx64-centos.efi $TMP_BUILD_DIR/bootx64.efi
|
|
|
|
cp $TMP_BOOTLOADER_DIR/grubx64.efi $TMP_BUILD_DIR/grubx64.efi
|
|
|
|
elif [[ $DISTRO_NAME = "ubuntu" || $DISTRO_NAME = "debian" ]] ; then
|
|
|
|
cp $TMP_BOOTLOADER_DIR/shimx64.efi.signed $TMP_BUILD_DIR/bootx64.efi
|
|
|
|
cp $TMP_BOOTLOADER_DIR/grubx64.efi.signed $TMP_BUILD_DIR/grubx64.efi
|
2015-03-10 07:38:05 +00:00
|
|
|
else
|
|
|
|
cp $TMP_BOOTLOADER_DIR/shim.efi.signed $TMP_BUILD_DIR/bootx64.efi
|
|
|
|
cp $TMP_BOOTLOADER_DIR/grubx64.efi.signed $TMP_BUILD_DIR/grubx64.efi
|
|
|
|
fi
|
2014-10-09 09:54:19 +00:00
|
|
|
|
2015-03-10 07:38:05 +00:00
|
|
|
dd if=/dev/zero of=$TMP_BUILD_DIR/efiboot.img bs=1K count=5760
|
2014-10-09 09:54:19 +00:00
|
|
|
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
|
2015-03-10 07:38:05 +00:00
|
|
|
sudo cp $TMP_BUILD_DIR/grubx64.efi $MOUNTPOINT/EFI/BOOT
|
2014-10-09 09:54:19 +00:00
|
|
|
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"
|
2015-03-10 07:38:05 +00:00
|
|
|
if [ $DISTRO_NAME = "fedora" ]; then
|
|
|
|
EFI_BOOT_DIR="EFI/fedora"
|
|
|
|
EXTRA_KERNEL_PARAMS="usbcore.autosuspend=-1"
|
2021-02-25 15:30:21 +00:00
|
|
|
#centos
|
|
|
|
elif [ $DISTRO_NAME = "centos" ]; then
|
|
|
|
EFI_BOOT_DIR="EFI/centos"
|
|
|
|
EXTRA_KERNEL_PARAMS=""
|
2015-08-12 11:32:46 +00:00
|
|
|
#debian
|
|
|
|
elif [ $DISTRO_NAME = "debian" ]; then
|
|
|
|
EFI_BOOT_DIR="EFI/debian"
|
|
|
|
EXTRA_KERNEL_PARAMS=""
|
|
|
|
#ubuntu:
|
2015-03-10 07:38:05 +00:00
|
|
|
else
|
|
|
|
EFI_BOOT_DIR="EFI/ubuntu"
|
|
|
|
EXTRA_KERNEL_PARAMS=""
|
|
|
|
fi
|
2014-10-09 09:54:19 +00:00
|
|
|
|
2017-05-31 04:16:17 +00:00
|
|
|
# Create a temporary build directory for holding the contents of iso
|
2014-10-09 09:54:19 +00:00
|
|
|
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"
|
|
|
|
|
2015-03-10 07:38:05 +00:00
|
|
|
ISOLINUX_BIN=$TMP_BOOTLOADER_DIR/isolinux.bin
|
2015-04-29 07:21:03 +00:00
|
|
|
LDLINUX_BIN=$TMP_BOOTLOADER_DIR/ldlinux.c32
|
2014-10-09 09:54:19 +00:00
|
|
|
|
|
|
|
cp $ISOLINUX_BIN "$TMP_IMAGE_DIR/isolinux"
|
|
|
|
|
2015-04-29 07:21:03 +00:00
|
|
|
# Starting from SYSLINUX 5.00, the isolinux.bin is dependent
|
|
|
|
# on ldlinux.c32.
|
|
|
|
# http://www.syslinux.org/wiki/index.php/Library_modules
|
|
|
|
if [ -f "$LDLINUX_BIN" ]; then
|
|
|
|
cp $LDLINUX_BIN "$TMP_IMAGE_DIR/isolinux"
|
|
|
|
fi
|
|
|
|
|
2014-10-09 09:54:19 +00:00
|
|
|
# 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
|
|
|
|
|
2015-03-10 07:38:05 +00:00
|
|
|
echo "Creating EFI/ubuntu directory"
|
2014-10-09 09:54:19 +00:00
|
|
|
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" {
|
2015-03-10 07:38:05 +00:00
|
|
|
search --set=root --label VMEDIA_BOOT_ISO
|
2015-04-12 15:10:57 +00:00
|
|
|
linuxefi /vmlinuz $EXTRA_KERNEL_PARAMS $KERNEL_CMDLINE_ARGS --
|
|
|
|
initrdefi /initrd
|
2014-10-09 09:54:19 +00:00
|
|
|
}
|
|
|
|
END_CONFIG
|
|
|
|
|
2015-03-10 07:38:05 +00:00
|
|
|
build_efiboot_img
|
2014-10-09 09:54:19 +00:00
|
|
|
|
|
|
|
# Create the ISO
|
|
|
|
echo "Generating the ISO"
|
2014-10-23 16:54:18 +00:00
|
|
|
$MKISOFS -r -V "VMEDIA_BOOT_ISO" -cache-inodes -J -l \
|
2014-10-09 09:54:19 +00:00
|
|
|
-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
|
2015-05-04 09:41:16 +00:00
|
|
|
DIB_DEPLOY_ISO_KERNEL_CMDLINE_ARGS=${DIB_DEPLOY_ISO_KERNEL_CMDLINE_ARGS:-}
|
|
|
|
EMITTED_KERNEL_CMDLINE_ARGS="boot_method=vmedia $DIB_DEPLOY_ISO_KERNEL_CMDLINE_ARGS"
|
2014-10-09 09:54:19 +00:00
|
|
|
EMITTED_ISO_FILENAME=$IMAGE_NAME.iso
|
2021-01-21 13:06:08 +00:00
|
|
|
elif echo $IMAGE_ELEMENT | grep -q '\bironic-python-agent\b'; then
|
2015-03-10 07:38:05 +00:00
|
|
|
EMITTED_KERNEL=$IMAGE_NAME.vmlinuz
|
|
|
|
EMITTED_RAMDISK=$IMAGE_NAME.initramfs
|
2015-05-04 09:41:16 +00:00
|
|
|
DIB_DEPLOY_ISO_KERNEL_CMDLINE_ARGS=${DIB_DEPLOY_ISO_KERNEL_CMDLINE_ARGS:-}
|
|
|
|
EMITTED_KERNEL_CMDLINE_ARGS="boot_method=vmedia $DIB_DEPLOY_ISO_KERNEL_CMDLINE_ARGS"
|
2015-03-10 07:38:05 +00:00
|
|
|
EMITTED_ISO_FILENAME=$IMAGE_NAME.iso
|
2014-10-09 09:54:19 +00:00
|
|
|
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
|
|
|
|
|
2015-03-10 07:38:05 +00:00
|
|
|
export TMP_BOOTLOADER_DIR=$TARGET_ROOT/tmp/bootloader_files
|
2014-10-09 09:54:19 +00:00
|
|
|
build_iso "$EMITTED_KERNEL" "$EMITTED_RAMDISK" "$EMITTED_KERNEL_CMDLINE_ARGS" \
|
|
|
|
"$EMITTED_ISO_FILENAME"
|
2015-03-10 07:38:05 +00:00
|
|
|
|
|
|
|
# Clean-up the bootloaders directory
|
|
|
|
sudo rm -fr $TMP_BOOTLOADER_DIR
|