2017-11-26 21:17:09 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# created by Tobias Powalowski <tpowa@archlinux.org>
|
|
|
|
|
|
|
|
_BASENAME="$(basename "${0}")"
|
2022-01-14 10:57:58 +01:00
|
|
|
_PRESET_DIR="/etc/archboot/presets"
|
2021-10-14 12:20:49 +02:00
|
|
|
_SHIM_URL="https://kojipkgs.fedoraproject.org/packages/shim/15.4/5/x86_64"
|
|
|
|
_SHIM_VERSION="shim-x64-15.4-5.x86_64.rpm"
|
|
|
|
_SHIM32_VERSION="shim-ia32-15.4-5.x86_64.rpm"
|
2022-01-18 09:56:43 +01:00
|
|
|
_GRUB_CONFIG="/usr/share/archboot/grub/grub.cfg"
|
2022-01-14 10:55:01 +01:00
|
|
|
# covered by usage
|
|
|
|
_GENERATE=""
|
|
|
|
_PRESET=""
|
|
|
|
_IMAGENAME=""
|
|
|
|
_RELEASENAME=""
|
|
|
|
# temporary directories
|
2022-01-16 14:34:02 +01:00
|
|
|
_X86_64="$(mktemp -d X86_64.XXX)"
|
|
|
|
_SHIM="$(mktemp -d shim.XXX)"
|
|
|
|
_SHIM32="$(mktemp -d shim32.XXX)"
|
2017-11-26 21:17:09 +01:00
|
|
|
|
|
|
|
usage () {
|
|
|
|
echo "${_BASENAME}: usage"
|
|
|
|
echo "CREATE X86_64 USB/CD IMAGES"
|
|
|
|
echo "-----------------------------"
|
|
|
|
echo "PARAMETERS:"
|
2022-01-18 16:26:17 +01:00
|
|
|
echo " -g Start generation of image."
|
2021-10-04 20:21:21 +02:00
|
|
|
echo " -p=PRESET Which preset should be used."
|
2021-10-07 11:21:28 +02:00
|
|
|
echo " /etc/archboot/presets locates the presets"
|
|
|
|
echo " default=x86_64"
|
2017-11-26 21:17:09 +01:00
|
|
|
echo " -i=IMAGENAME Your IMAGENAME."
|
|
|
|
echo " -r=RELEASENAME Use RELEASENAME in boot message."
|
|
|
|
echo " -h This message."
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# change to english locale!
|
|
|
|
export LANG="en_US"
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case ${1} in
|
2022-01-18 16:26:17 +01:00
|
|
|
-g|--g) _GENERATE="1" ;;
|
2022-01-14 10:55:01 +01:00
|
|
|
-p=*|--p=*) _PRESET="$(echo ${1} | awk -F= '{print $2;}')" ;;
|
|
|
|
-i=*|--i=*) _IMAGENAME="$(echo ${1} | awk -F= '{print $2;}')" ;;
|
|
|
|
-r=*|--r=*) _RELEASENAME="$(echo ${1} | awk -F= '{print $2;}')" ;;
|
2017-11-26 21:17:09 +01:00
|
|
|
-h|--h|?) usage ;;
|
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-09-10 13:40:49 +02:00
|
|
|
### check for root
|
|
|
|
if ! [[ ${UID} -eq 0 ]]; then
|
|
|
|
echo "ERROR: Please run as root user!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-01-14 10:57:58 +01:00
|
|
|
### check for aarch64
|
|
|
|
if ! [[ "$(uname -m)" == "x86_64" ]]; then
|
|
|
|
echo "ERROR: Please run on x86_64 hardware."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-01-18 16:26:17 +01:00
|
|
|
[[ "${_GENERATE}" == "1" ]] || usage
|
|
|
|
|
2021-10-07 11:21:28 +02:00
|
|
|
#set PRESET
|
2022-01-14 10:55:01 +01:00
|
|
|
[[ -z "${_PRESET}" ]] && _PRESET="x86_64"
|
|
|
|
_PRESET=""${_PRESET_DIR}"/"${_PRESET}""
|
2021-10-04 20:42:01 +02:00
|
|
|
|
2021-09-09 15:06:55 +02:00
|
|
|
# set defaults, if nothing given
|
2022-01-14 10:55:01 +01:00
|
|
|
[[ -z "${_RELEASENAME}" ]] && _RELEASENAME="$(date +%Y.%m.%d-%H.%M)"
|
|
|
|
[[ -z "${_IMAGENAME}" ]] && _IMAGENAME="archlinux-archboot-${_RELEASENAME}-x86_64"
|
2021-09-09 15:06:55 +02:00
|
|
|
|
2022-01-18 16:26:17 +01:00
|
|
|
_prepare_kernel_initramfs_files() {
|
|
|
|
source "${_PRESET}"
|
|
|
|
mkdir -p "${_X86_64}/EFI/BOOT"
|
|
|
|
mkdir -p "${_X86_64}/boot"
|
2022-01-18 07:56:40 +01:00
|
|
|
# fix for mkinitcpio 31
|
|
|
|
# https://bugs.archlinux.org/task/72882
|
|
|
|
# remove on mkinitcpio 32 release
|
|
|
|
cp "/usr/lib/initcpio/functions" "/usr/lib/initcpio/functions.old"
|
|
|
|
[[ -f "/usr/share/archboot/patches/31-initcpio.functions.fixed" ]] && cp "/usr/share/archboot/patches/31-initcpio.functions.fixed" "/usr/lib/initcpio/functions"
|
2022-01-18 16:26:17 +01:00
|
|
|
mkinitcpio -c "${MKINITCPIO_CONFIG}" -k "${ALL_kver}" -g "${_X86_64}/boot/initramfs_x86_64.img" || exit 1
|
2022-01-18 07:56:40 +01:00
|
|
|
mv "/usr/lib/initcpio/functions.old" "/usr/lib/initcpio/functions"
|
2022-01-18 16:26:17 +01:00
|
|
|
install -m644 "${ALL_kver}" "${_X86_64}/boot/vmlinuz_x86_64"
|
|
|
|
# install ucode files
|
|
|
|
cp /boot/{intel-ucode.img,amd-ucode.img} "${_X86_64}/boot/"
|
|
|
|
# fix license files
|
2022-01-18 18:59:57 +01:00
|
|
|
mkdir -p "${_X86_64}"/licenses/{amd-ucode,intel-ucode}
|
|
|
|
cp /usr/share/licenses/amd-ucode/LICENSE.amd-ucode "${_X86_64}/licenses/amd-ucode"
|
|
|
|
cp /usr/share/licenses/intel-ucode/LICENSE "${_X86_64}/licenses/intel-ucode"
|
2017-11-26 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
2021-10-14 15:12:56 +02:00
|
|
|
_prepare_efitools_uefi () {
|
2022-01-13 15:32:45 +01:00
|
|
|
cp -f "/usr/share/efitools/efi/HashTool.efi" "${_X86_64}/EFI/tools/HashTool.efi"
|
|
|
|
cp -f "/usr/share/efitools/efi/KeyTool.efi" "${_X86_64}/EFI/tools/KeyTool.efi"
|
2021-09-12 20:41:48 +02:00
|
|
|
}
|
|
|
|
|
2021-10-14 12:20:49 +02:00
|
|
|
_prepare_fedora_shim_bootloaders () {
|
|
|
|
# Details on shim https://www.rodsbooks.com/efi-bootloaders/secureboot.html#initial_shim
|
|
|
|
# add shim x64 signed files from fedora
|
2022-01-14 10:55:01 +01:00
|
|
|
curl -s --create-dirs -L -O --output-dir "${_SHIM}" "${_SHIM_URL}/${_SHIM_VERSION}"
|
|
|
|
bsdtar -C "${_SHIM}" -xf "${_SHIM}"/"${_SHIM_VERSION}"
|
2022-01-16 15:17:13 +01:00
|
|
|
cp "${_SHIM}/boot/efi/EFI/fedora/mmx64.efi" "${_X86_64}/EFI/BOOT/mmx64.efi"
|
|
|
|
cp "${_SHIM}/boot/efi/EFI/fedora/shimx64.efi" "${_X86_64}/EFI/BOOT/BOOTX64.efi"
|
2021-10-14 12:20:49 +02:00
|
|
|
# add shim ia32 signed files from fedora
|
2022-01-16 15:17:13 +01:00
|
|
|
curl -s --create-dirs -L -O --output-dir "${_SHIM32}" "${_SHIM_URL}/${_SHIM32_VERSION}"
|
2022-01-14 10:55:01 +01:00
|
|
|
bsdtar -C "${_SHIM32}" -xf "${_SHIM32}/${_SHIM32_VERSION}"
|
|
|
|
cp "${_SHIM32}/boot/efi/EFI/fedora/mmia32.efi" "${_X86_64}/EFI/BOOT/mmia32.efi"
|
|
|
|
cp "${_SHIM32}/boot/efi/EFI/fedora/shimia32.efi" "${_X86_64}/EFI/BOOT/BOOTIA32.efi"
|
2021-10-14 12:20:49 +02:00
|
|
|
### adding this causes boot loop in ovmf and only tries create a boot entry
|
2022-01-13 15:32:45 +01:00
|
|
|
#cp "${SHIM}/boot/efi/EFI/BOOT/fbx64.efi" "${_X86_64}/EFI/BOOT/fbx64.efi"
|
2021-10-12 11:55:47 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 11:54:51 +02:00
|
|
|
_prepare_uefi_image() {
|
2022-01-18 07:56:40 +01:00
|
|
|
## get size of boot x86_64 files
|
|
|
|
BOOTSIZE=$(du -bc ${_X86_64}/EFI | grep total | cut -f1)
|
|
|
|
IMGSZ=$(( (${BOOTSIZE}*102)/100/1024 + 1)) # image size in sectors
|
|
|
|
## Create cdefiboot.img
|
|
|
|
dd if=/dev/zero of="${_X86_64}"/efi.img bs="${IMGSZ}" count=1024
|
|
|
|
VFAT_IMAGE="${_X86_64}/efi.img"
|
|
|
|
mkfs.vfat "${VFAT_IMAGE}"
|
|
|
|
## Copy all files to UEFI vfat image
|
|
|
|
mcopy -i "${VFAT_IMAGE}" -s "${_X86_64}"/EFI ::/
|
2017-11-26 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_download_uefi_shell_tianocore() {
|
2022-01-18 07:56:40 +01:00
|
|
|
mkdir -p "${_X86_64}/EFI/tools/"
|
|
|
|
## Install Tianocore UDK/EDK2 ShellBinPkg UEFI X64 "Full Shell" - For UEFI Spec. >=2.3 systems
|
|
|
|
cp /usr/share/edk2-shell/x64/Shell.efi "${_X86_64}/EFI/tools/shellx64_v2.efi"
|
|
|
|
## Install Tianocore UDK/EDK2 EdkShellBinPkg UEFI X64 "Full Shell" - For UEFI Spec. <2.3 systems
|
|
|
|
cp /usr/share/edk2-shell/x64/Shell_Full.efi "${_X86_64}/EFI/tools/shellx64_v1.efi"
|
|
|
|
## Install Tianocore UDK/EDK2 ShellBinPkg UEFI IA32 "Full Shell" - For UEFI Spec. >=2.3 systems
|
|
|
|
cp /usr/share/edk2-shell/ia32/Shell.efi "${_X86_64}/EFI/tools/shellia32_v2.efi"
|
|
|
|
## InstallTianocore UDK/EDK2 EdkShellBinPkg UEFI IA32 "Full Shell" - For UEFI Spec. <2.3 systems
|
|
|
|
cp /usr/share/edk2-shell/ia32/Shell_Full.efi "${_X86_64}/EFI/tools/shellia32_v1.efi"
|
2021-09-12 21:12:31 +02:00
|
|
|
}
|
2017-11-26 21:17:09 +01:00
|
|
|
|
2021-10-14 12:20:49 +02:00
|
|
|
# build grubXXX with all modules: http://bugs.archlinux.org/task/71382
|
|
|
|
# If you don't use shim use --disable-shim-lock
|
2017-11-26 21:17:09 +01:00
|
|
|
_prepare_uefi_X64_GRUB_USB_files() {
|
2022-01-18 07:56:40 +01:00
|
|
|
### Hint: https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/grub.macros#_407
|
2022-01-18 09:56:43 +01:00
|
|
|
grub-mkstandalone -d /usr/lib/grub/x86_64-efi -O x86_64-efi --sbat=/usr/share/grub/sbat.csv --modules="all_video boot btrfs cat configfile cryptodisk echo efi_gop efi_uga efifwsetup efinet ext2 f2fs fat font gcry_rijndael gcry_rsa gcry_serpent gcry_sha256 gcry_twofish gcry_whirlpool gfxmenu gfxterm gzio halt hfsplus http iso9660 loadenv loopback linux lvm lsefi lsefimmap luks luks2 mdraid09 mdraid1x minicmd net normal part_apple part_msdos part_gpt password_pbkdf2 pgp png reboot regexp search search_fs_uuid search_fs_file search_label serial sleep syslinuxcfg test tftp video xfs zstd backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug keylayouts at_keyboard" --fonts="unicode" --locales="" --themes="" -o "${_X86_64}/EFI/BOOT/grubx64.efi" "boot/grub/grub.cfg=${_GRUB_CONFIG}"
|
2017-11-26 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_prepare_uefi_IA32_GRUB_USB_files() {
|
2022-01-18 07:56:40 +01:00
|
|
|
### Hint: https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/grub.macros#_407
|
2022-01-18 09:56:43 +01:00
|
|
|
grub-mkstandalone -d /usr/lib/grub/i386-efi -O i386-efi --sbat=/usr/share/grub/sbat.csv --modules="all_video boot btrfs cat configfile cryptodisk echo efi_gop efi_uga efifwsetup efinet ext2 f2fs fat font gcry_rijndael gcry_rsa gcry_serpent gcry_sha256 gcry_twofish gcry_whirlpool gfxmenu gfxterm gzio halt hfsplus http iso9660 loadenv loopback linux lvm lsefi lsefimmap luks luks2 mdraid09 mdraid1x minicmd net normal part_apple part_msdos part_gpt password_pbkdf2 pgp png reboot regexp search search_fs_uuid search_fs_file search_label serial sleep syslinuxcfg test tftp video xfs zstd backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug keylayouts at_keyboard" --fonts="unicode" --locales="" --themes="" -o "${_X86_64}/EFI/BOOT/grubia32.efi" "boot/grub/grub.cfg=${_GRUB_CONFIG}"
|
2022-01-16 15:58:47 +01:00
|
|
|
}
|
|
|
|
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Starting ISO creation ..."
|
2022-01-18 16:26:17 +01:00
|
|
|
echo "Prepare kernel and initramfs ..."
|
|
|
|
_prepare_kernel_initramfs_files
|
|
|
|
|
2021-10-15 08:51:27 +02:00
|
|
|
echo "Prepare fedora shim ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
_prepare_fedora_shim_bootloaders >/dev/null 2>&1
|
2021-10-12 12:55:10 +02:00
|
|
|
|
2021-10-15 08:51:27 +02:00
|
|
|
echo "Prepare uefi shells ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
_download_uefi_shell_tianocore >/dev/null 2>&1
|
2017-11-26 21:17:09 +01:00
|
|
|
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Prepare efitools ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
_prepare_efitools_uefi >/dev/null 2>&1
|
2017-11-26 21:17:09 +01:00
|
|
|
|
2021-10-15 08:51:27 +02:00
|
|
|
echo "Prepare X64 Grub ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
_prepare_uefi_X64_GRUB_USB_files >/dev/null 2>&1
|
2017-11-26 21:17:09 +01:00
|
|
|
|
2021-10-15 08:51:27 +02:00
|
|
|
echo "Prepare IA32 Grub ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
_prepare_uefi_IA32_GRUB_USB_files >/dev/null 2>&1
|
2017-11-26 21:17:09 +01:00
|
|
|
|
2021-10-15 08:51:27 +02:00
|
|
|
echo "Prepare UEFI image ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
_prepare_uefi_image >/dev/null 2>&1
|
2017-11-26 21:17:09 +01:00
|
|
|
|
2022-01-18 10:03:15 +01:00
|
|
|
## Generate the BIOS+ISOHYBRID+UEFI CD image
|
2017-11-27 15:43:56 +01:00
|
|
|
echo "Generating X86_64 hybrid ISO ..."
|
2022-01-18 09:56:43 +01:00
|
|
|
grub-mkrescue --compress="xz" --fonts="unicode" --locales="" --themes="" -o "${_IMAGENAME}.iso" "${_X86_64}"/ "boot/grub/grub.cfg=${_GRUB_CONFIG}" &> "${_IMAGENAME}.log"
|
2017-11-26 21:17:09 +01:00
|
|
|
|
|
|
|
## create sha256sums.txt
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Generating sha256sum ..."
|
2021-09-10 13:46:55 +02:00
|
|
|
rm -f "sha256sums.txt" || true
|
2021-09-27 21:49:46 +02:00
|
|
|
cksum -a sha256 *.iso > "sha256sums.txt"
|
2017-11-26 21:17:09 +01:00
|
|
|
|
|
|
|
# cleanup
|
2022-01-18 16:26:17 +01:00
|
|
|
echo "Cleanup remove ${_X86_64}, ${_SHIM} and ${_SHIM32} ..."
|
2022-01-13 15:32:45 +01:00
|
|
|
rm -rf "${_X86_64}"
|
2022-01-14 10:55:01 +01:00
|
|
|
rm -rf "${_SHIM}"
|
|
|
|
rm -rf "${_SHIM32}"
|
2021-10-15 09:29:07 +02:00
|
|
|
echo "Finished ISO creation."
|