- Switch all lb mirrors to mirror.mephi.ru/debian/ for faster/reliable downloads - Disable security repo (--security false) — not needed for LiveCD - Pin MEMTEST_VERSION=6.10-4 in VERSIONS, export to hook environment - Set BEE_REQUIRE_MEMTEST=1 in build-in-container.sh — missing memtest is now fatal - Fix 9100-memtest.hook.binary: add apt-get download fallback when lb binary_memtest has already purged the package cache; handle both 5.x (memtest86+x64.bin) and 6.x (memtest86+.bin) BIOS binary naming Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
185 lines
5.0 KiB
Bash
Executable File
185 lines
5.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# Ensure memtest is present in the final ISO even if live-build's built-in
|
|
# memtest stage does not copy the binaries or expose menu entries.
|
|
set -e
|
|
|
|
: "${BEE_REQUIRE_MEMTEST:=0}"
|
|
|
|
# memtest86+ 6.x uses memtest86+.bin (no x64 suffix) for the BIOS binary,
|
|
# while 5.x used memtest86+x64.bin. We normalise both to x64 names in the ISO.
|
|
MEMTEST_FILES="memtest86+x64.bin memtest86+x64.efi"
|
|
BINARY_BOOT_DIR="binary/boot"
|
|
GRUB_CFG="binary/boot/grub/grub.cfg"
|
|
ISOLINUX_CFG="binary/isolinux/live.cfg"
|
|
|
|
log() {
|
|
echo "memtest hook: $*"
|
|
}
|
|
|
|
fail_or_warn() {
|
|
msg="$1"
|
|
if [ "${BEE_REQUIRE_MEMTEST}" = "1" ]; then
|
|
log "ERROR: ${msg}"
|
|
exit 1
|
|
fi
|
|
log "WARNING: ${msg}"
|
|
return 0
|
|
}
|
|
|
|
copy_memtest_file() {
|
|
src="$1"
|
|
dst_name="${2:-$(basename "$src")}"
|
|
dst="${BINARY_BOOT_DIR}/${dst_name}"
|
|
|
|
[ -f "$src" ] || return 1
|
|
mkdir -p "${BINARY_BOOT_DIR}"
|
|
cp "$src" "$dst"
|
|
log "copied ${dst_name} from ${src}"
|
|
}
|
|
|
|
extract_memtest_from_deb() {
|
|
deb="$1"
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
log "extracting memtest payload from ${deb}"
|
|
dpkg-deb -x "$deb" "$tmpdir"
|
|
|
|
# EFI binary: both 5.x and 6.x use memtest86+x64.efi
|
|
if [ -f "${tmpdir}/boot/memtest86+x64.efi" ]; then
|
|
copy_memtest_file "${tmpdir}/boot/memtest86+x64.efi"
|
|
fi
|
|
|
|
# BIOS binary: 5.x = memtest86+x64.bin, 6.x = memtest86+.bin
|
|
if [ -f "${tmpdir}/boot/memtest86+x64.bin" ]; then
|
|
copy_memtest_file "${tmpdir}/boot/memtest86+x64.bin"
|
|
elif [ -f "${tmpdir}/boot/memtest86+.bin" ]; then
|
|
copy_memtest_file "${tmpdir}/boot/memtest86+.bin" "memtest86+x64.bin"
|
|
fi
|
|
|
|
rm -rf "$tmpdir"
|
|
}
|
|
|
|
download_and_extract_memtest() {
|
|
tmpdl="$(mktemp -d)"
|
|
ver_arg=""
|
|
if [ -n "${MEMTEST_VERSION:-}" ]; then
|
|
ver_arg="=memtest86+=${MEMTEST_VERSION}"
|
|
log "downloading memtest86+=${MEMTEST_VERSION} from apt"
|
|
else
|
|
log "downloading memtest86+ from apt (no version pinned)"
|
|
fi
|
|
# shellcheck disable=SC2086
|
|
( cd "$tmpdl" && apt-get download "memtest86+${ver_arg}" ) 2>/dev/null || true
|
|
deb="$(find "$tmpdl" -maxdepth 1 -type f -name 'memtest86+*.deb' 2>/dev/null | head -1)"
|
|
if [ -n "$deb" ]; then
|
|
extract_memtest_from_deb "$deb"
|
|
else
|
|
log "apt download of memtest86+ failed"
|
|
fi
|
|
rm -rf "$tmpdl"
|
|
}
|
|
|
|
ensure_memtest_binaries() {
|
|
missing=0
|
|
for f in ${MEMTEST_FILES}; do
|
|
[ -f "${BINARY_BOOT_DIR}/${f}" ] || missing=1
|
|
done
|
|
[ "$missing" -eq 1 ] || return 0
|
|
|
|
# 1. Try files already placed by lb binary_memtest or chroot
|
|
for root in chroot/boot /boot; do
|
|
for f in ${MEMTEST_FILES}; do
|
|
[ -f "${BINARY_BOOT_DIR}/${f}" ] || copy_memtest_file "${root}/${f}" || true
|
|
done
|
|
# 6.x BIOS binary may lack x64 in name — copy with normalised name
|
|
if [ ! -f "${BINARY_BOOT_DIR}/memtest86+x64.bin" ]; then
|
|
copy_memtest_file "${root}/memtest86+.bin" "memtest86+x64.bin" || true
|
|
fi
|
|
done
|
|
|
|
missing=0
|
|
for f in ${MEMTEST_FILES}; do
|
|
[ -f "${BINARY_BOOT_DIR}/${f}" ] || missing=1
|
|
done
|
|
[ "$missing" -eq 1 ] || return 0
|
|
|
|
# 2. Try apt package cache (may be empty if lb binary_memtest already purged)
|
|
for root in cache chroot/var/cache/apt/archives /var/cache/apt/archives; do
|
|
[ -d "$root" ] || continue
|
|
deb="$(find "$root" -type f \( -name 'memtest86+_*.deb' -o -name 'memtest86+*.deb' \) 2>/dev/null | head -1)"
|
|
[ -n "$deb" ] || continue
|
|
extract_memtest_from_deb "$deb"
|
|
break
|
|
done
|
|
|
|
missing=0
|
|
for f in ${MEMTEST_FILES}; do
|
|
[ -f "${BINARY_BOOT_DIR}/${f}" ] || missing=1
|
|
done
|
|
[ "$missing" -eq 1 ] || return 0
|
|
|
|
# 3. Fallback: download fresh from apt (lb binary_memtest purges the cache)
|
|
download_and_extract_memtest
|
|
|
|
missing=0
|
|
for f in ${MEMTEST_FILES}; do
|
|
if [ ! -f "${BINARY_BOOT_DIR}/${f}" ]; then
|
|
fail_or_warn "missing ${BINARY_BOOT_DIR}/${f}"
|
|
missing=1
|
|
fi
|
|
done
|
|
[ "$missing" -eq 0 ] || return 0
|
|
}
|
|
|
|
ensure_grub_entry() {
|
|
[ -f "$GRUB_CFG" ] || {
|
|
fail_or_warn "missing ${GRUB_CFG}"
|
|
return 0
|
|
}
|
|
|
|
grep -q '### BEE MEMTEST ###' "$GRUB_CFG" && return 0
|
|
|
|
cat >> "$GRUB_CFG" <<'EOF'
|
|
|
|
### BEE MEMTEST ###
|
|
if [ "${grub_platform}" = "efi" ]; then
|
|
menuentry "Memory Test (memtest86+)" {
|
|
chainloader /boot/memtest86+x64.efi
|
|
}
|
|
else
|
|
menuentry "Memory Test (memtest86+)" {
|
|
linux16 /boot/memtest86+x64.bin
|
|
}
|
|
fi
|
|
### /BEE MEMTEST ###
|
|
EOF
|
|
|
|
log "appended memtest entry to ${GRUB_CFG}"
|
|
}
|
|
|
|
ensure_isolinux_entry() {
|
|
[ -f "$ISOLINUX_CFG" ] || {
|
|
fail_or_warn "missing ${ISOLINUX_CFG}"
|
|
return 0
|
|
}
|
|
|
|
grep -q '### BEE MEMTEST ###' "$ISOLINUX_CFG" && return 0
|
|
|
|
cat >> "$ISOLINUX_CFG" <<'EOF'
|
|
|
|
# ### BEE MEMTEST ###
|
|
label memtest
|
|
menu label ^Memory Test (memtest86+)
|
|
linux /boot/memtest86+x64.bin
|
|
# ### /BEE MEMTEST ###
|
|
EOF
|
|
|
|
log "appended memtest entry to ${ISOLINUX_CFG}"
|
|
}
|
|
|
|
log "ensuring memtest binaries and menu entries in binary image"
|
|
ensure_memtest_binaries
|
|
ensure_grub_entry
|
|
ensure_isolinux_entry
|
|
log "memtest assets ready"
|