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.
This commit is contained in:
adrian15 2024-08-18 21:56:13 +02:00
parent c7bc5f311c
commit a3fb9b49f8
6 changed files with 84 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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 "${@}"

View File

@ -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 <<EOF
search --set=root --file /.disk/info
search --set=root --file /${LB_UUID_FILE}
set prefix=(\\\$root)/boot/grub
configfile (\\\$root)/boot/grub/grub.cfg
EOF

39
scripts/build/binary_uuid Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## 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

View File

@ -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