From a3fb9b49f823d3e8b524a6431e1053c50bc8d217 Mon Sep 17 00:00:00 2001 From: adrian15 Date: Sun, 18 Aug 2024 21:56:13 +0200 Subject: [PATCH] Added Liveid support This creates an unique UUID for the media. Its saved thanks to some directories and files into the media filesystem. E.g.: /LIVEID/5BAA1131/19EB89E1/DF6EDB7E/6F422B5C is created in the cdrom. Also linux cmdline will have liveid=/LIVEID/5BAA1131/19EB89E1/DF6EDB7E/6F422B5C so that live-boot knows exactly which device is the right one for the kernel+initrd which have been loaded onto memory. This avoids problems when you have 4 usb pendrives connected to your computer and you select one of them to boot from your BIOS/UEFI firmware. In many cases this will trigger a different usb pendrive to be used instead. Also avoids problems with some HP laptops that have pre-installed live-build systems on their first partition. --- functions/configuration.sh | 28 +++++++++++++++++++++++++ manpages/en/lb_config.1 | 4 ++++ scripts/build/binary | 1 + scripts/build/binary_grub-efi | 4 ++-- scripts/build/binary_uuid | 39 +++++++++++++++++++++++++++++++++++ scripts/build/config | 11 +++++++++- 6 files changed, 84 insertions(+), 3 deletions(-) create mode 100755 scripts/build/binary_uuid diff --git a/functions/configuration.sh b/functions/configuration.sh index 1584fff52..9345e9ced 100755 --- a/functions/configuration.sh +++ b/functions/configuration.sh @@ -403,6 +403,34 @@ Prepare_config () ;; esac + # Setting LB_UUID_FILE (only once) + if [ -z "${LB_UUID_FILE}" ] + then + LIVEID_DIR_PREFIX="LIVEID" + + LB_UUID_SEED="${SOURCE_DATE_EPOCH}" + + LB_UUID=$(echo -n "${LB_UUID_SEED}" | md5sum | tr 'a-z' 'A-Z') + + LB_UUID_DIR1="$(echo ${LB_UUID} | cut -c1-8)" + LB_UUID_DIR2="$(echo ${LB_UUID} | cut -c9-16)" + LB_UUID_DIR3="$(echo ${LB_UUID} | cut -c17-24)" + LB_UUID_FILE4="$(echo ${LB_UUID} | cut -c25-32)" + + LB_UUID_DIR="${LIVEID_DIR_PREFIX}/${LB_UUID_DIR1}"'/'"${LB_UUID_DIR2}"'/'"${LB_UUID_DIR3}" + LB_UUID_FILE="${LB_UUID_DIR}"'/'"${LB_UUID_FILE4}" + + fi + + UUID_CMDLINE="liveid=/${LB_UUID_FILE}" + if ! echo "${LB_BOOTAPPEND_LIVE}" | grep -q "${UUID_CMDLINE}" + then + # Setting bootapend according to UUID + LB_BOOTAPPEND_LIVE="${LB_BOOTAPPEND_LIVE} ${UUID_CMDLINE}" + LB_BOOTAPPEND_LIVE_FAILSAFE="${LB_BOOTAPPEND_LIVE_FAILSAFE} ${UUID_CMDLINE}" + LB_BOOTAPPEND_INSTALL="${LB_BOOTAPPEND_INSTALL} ${UUID_CMDLINE}" + fi + local _LB_BOOTAPPEND_PRESEED if [ -n "${LB_DEBIAN_INSTALLER_PRESEEDFILE}" ] then diff --git a/manpages/en/lb_config.1 b/manpages/en/lb_config.1 index c51d5781e..397ac5692 100644 --- a/manpages/en/lb_config.1 +++ b/manpages/en/lb_config.1 @@ -221,6 +221,8 @@ [\fB\-\-updates\fR true|false] .br [\fB\-\-utc\-time\fR true|false] +.br + [\fB\-\-uuid\-file\fR \fIUUID-FILE\fR] .br [\fB\-\-validate\fR] .br @@ -454,6 +456,8 @@ enables or disables Secure Boot support when using grub-efi, by installing signe defines if debian updates package archives should be included in the image or not. .IP "\fB\-\-utc\-time\fR true|false" 4 defines if timestamps should be UTC. Default is false, unless SOURCE_DATE_EPOCH is set. Note, this does not affect the build log which remains local time. +.IP "\fB\-\-uuid\-file\fR \fIUUID-FILE\fR" 4 +sets the UUID file for identifying the ISO. You must remove the initial forward slash. When not set an UUID value is autogenerated for you based on the date the media was built. .IP "\fB\-\-validate\fR" 4 requests that the config be validated only, not changed, thus after the validation check the script ends rather than writing an updated config. Please note that at the time of writing, many options do not have corresponding validation checks. .IP "\fB\-\-verbose\fR" 4 diff --git a/scripts/build/binary b/scripts/build/binary index 9c21fa7a6..ea0209380 100755 --- a/scripts/build/binary +++ b/scripts/build/binary @@ -55,6 +55,7 @@ lb binary_linux-image "${@}" lb binary_memtest "${@}" lb binary_grub-legacy "${@}" lb binary_grub-pc "${@}" +lb binary_uuid "${@}" lb binary_grub_cfg "${@}" lb binary_syslinux "${@}" lb binary_disk "${@}" diff --git a/scripts/build/binary_grub-efi b/scripts/build/binary_grub-efi index 41a8c526e..932593559 100755 --- a/scripts/build/binary_grub-efi +++ b/scripts/build/binary_grub-efi @@ -251,11 +251,11 @@ esac # look in that partition for a grub.cfg file, and even if it finds it # it will not be able to find the vmlinuz and initrd. # Drop a minimal grub.cfg in the EFI partition that sets the root and prefix -# to whatever partition holds the /.disk/info file, and load the grub +# to whatever partition holds the image UUID file, and load the grub # config from that same partition. mkdir -p ${_CHROOT_DIR}/grub-efi-temp-cfg cat >${_CHROOT_DIR}/grub-efi-temp-cfg/grub.cfg < +## +## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING. +## This is free software, and you are welcome to redistribute it +## under certain conditions; see COPYING for details. + + +set -e + +# Including common functions +[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh + +# Setting static variables +DESCRIPTION="Installs uuid into binary" +USAGE="${PROGRAM} [--force]" + +# Processing arguments and configuration files +Init_config_data "${@}" + +Echo_message "Begin installing uuid..." + +# Requiring stage file +Require_stagefiles config bootstrap + +# Checking stage file +Check_stagefile + +# Acquire lock file +Acquire_lockfile + +LB_UUID_DIR="$(dirname ${LB_UUID_FILE})" +mkdir -p "binary/${LB_UUID_DIR}" +touch "binary/${LB_UUID_FILE}" + +# Creating stage file +Create_stagefile diff --git a/scripts/build/config b/scripts/build/config index 8b8010acb..c05a3d2d4 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -124,6 +124,7 @@ USAGE="${PROGRAM} [--apt apt|apt-get|aptitude]\n\ \t [--uefi-secure-boot auto|enable|disable]\n\ \t [--updates true|false]\n\ \t [--utc-time true|false]\n\ +\t [--uuid-file UUID-FILE]\n\ \t [--validate]\n\ \t [--verbose]\n\ \t [--win32-loader true|false]\n\ @@ -173,7 +174,7 @@ Local_arguments () quiet, security:,source:,source-images:,swap-file-path:,swap-file-size:,system:, tasksel:, - uefi-secure-boot:,updates:,utc-time:,usage, + uefi-secure-boot:,updates:,utc-time:,uuid-file:,usage, validate,verbose,version, win32-loader:, zsync:" @@ -825,6 +826,11 @@ Local_arguments () shift 2 ;; + --uuid-file) + LB_UUID_FILE="${2}" + shift 2 + ;; + --win32-loader) LB_WIN32_LOADER="${2}" shift 2 @@ -1311,6 +1317,9 @@ LB_SWAP_FILE_SIZE="${LB_SWAP_FILE_SIZE}" # Enable/disable UEFI secure boot support LB_UEFI_SECURE_BOOT="${LB_UEFI_SECURE_BOOT}" + +# Use UUID file. Otherwise it gets autogenerated +LB_UUID_FILE="${LB_UUID_FILE}" EOF # Creating lb_source_* configuration