Skip to content

Instantly share code, notes, and snippets.

@palacaze
Created February 25, 2021 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save palacaze/dec0624165fd4359114c2158da175420 to your computer and use it in GitHub Desktop.
Save palacaze/dec0624165fd4359114c2158da175420 to your computer and use it in GitHub Desktop.
A script to create a preseeded Debian ISO
#!/bin/bash
# This script creates a Preseeded Debian buster ISO installer.
# The preseeded file must have been filled beforehand.
debian_iso_url="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.4.0-amd64-netinst.iso"
debian_preseed_cfg="$(dirname "$0")/debian-buster-preseed.cfg"
debian_iso_file="$(basename ${debian_iso_url})"
debian_iso_preseeded="preseeded-${debian_iso_file}"
executable_exists() {
command -v "$1" > /dev/null 2>&1
}
egreen() {
echo -e "\033[1;32m${*}\033[0m"
}
ered() {
echo -e "\033[1;33m${*}\033[0m"
}
if [[ ${EUID} == 0 ]]; then
ered "You must not be root to run this script"
return
fi
# install wget isohybrid and cdrtools (for mkisofs) on your computer
for exe in bsdtar wget isohybrid mkisofs; do
if ! executable_exists "${exe}"; then
ered "${exe} application is missing, please install it and try again"
return
fi
done
work_dir="$(mktemp -d)"
debian_iso_path="${work_dir}/${debian_iso_file}"
work_dir_iso="${work_dir}/iso"
# fetch the net installer
wget "${debian_iso_url}" -O "${debian_iso_path}"
# uncompress the iso image
mkdir -p "${work_dir_iso}"
cat "${debian_iso_path}" | bsdtar -C "${work_dir_iso}" -xf -
chmod -R +w "${work_dir_iso}"
# add the file with preseeded answers at the root
cp "${debian_preseed_cfg}" "${work_dir_iso}/preseed.cfg"
# append options to the bootloader kernel command line to use the preseed file
sed -i '/append/s/$/ locale=en_US.UTF-8 keymap=us file=cdrom\/preseed.cfg/' "${work_dir_iso}/isolinux/txt.cfg"
# create a new iso
mkisofs -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-o "${debian_iso_preseeded}" "${work_dir_iso}"
isohybrid "${debian_iso_preseeded}"
# remove temp dir
rm -rf "${work_dir}"
echo ""
egreen "${debian_iso_preseeded} ready"
egreen "Put it on a usb key (as root) with the following command"
egreen "cat ${debian_iso_preseeded} > /dev/sdX && sync"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment