178 lines
5.3 KiB
Bash
178 lines
5.3 KiB
Bash
|
|
ROOT_PASSWORD="rehdd"
|
|
|
|
|
|
# Create a working directory
|
|
mkdir -p "${HOME}/LIVE_BOOT"
|
|
|
|
# Create environment live directories
|
|
mkdir -p "${HOME}/LIVE_BOOT"/{staging/{EFI/BOOT,boot/grub/x86_64-efi,isolinux,live},tmp}
|
|
|
|
# Download Debian environment
|
|
debootstrap \
|
|
--arch=amd64 \
|
|
--variant=minbase \
|
|
stable \
|
|
"${HOME}/LIVE_BOOT/chroot" \
|
|
http://ftp.de.debian.org/debian/
|
|
|
|
# Set hostname
|
|
echo "reHDD" | sudo tee "${HOME}/LIVE_BOOT/chroot/etc/hostname"
|
|
|
|
# Install Linux Kernel
|
|
chroot "${HOME}/LIVE_BOOT/chroot" << EOF
|
|
apt-get update && \
|
|
apt-get install -y --no-install-recommends \
|
|
linux-image-amd64 \
|
|
live-boot \
|
|
systemd-sysv
|
|
EOF
|
|
|
|
# Install packages
|
|
chroot "${HOME}/LIVE_BOOT/chroot" << EOF
|
|
apt-get install -y --no-install-recommends \
|
|
iwd \
|
|
curl openssh-client \
|
|
nano
|
|
EOF
|
|
|
|
# Set root password
|
|
chroot "${HOME}/LIVE_BOOT/chroot" passwd root
|
|
|
|
# Compress the chroot environment into a Squash filesystem
|
|
mksquashfs \
|
|
"${HOME}/LIVE_BOOT/chroot" \
|
|
"${HOME}/LIVE_BOOT/staging/live/filesystem.squashfs" \
|
|
-e boot
|
|
|
|
# Copy the kernel from inside the chroot to the live directory.
|
|
cp "${HOME}/LIVE_BOOT/chroot/boot"/vmlinuz-* \
|
|
"${HOME}/LIVE_BOOT/staging/live/vmlinuz"
|
|
|
|
# Copy initramfs from inside the chroot to the live directory.
|
|
cp "${HOME}/LIVE_BOOT/chroot/boot"/initrd.img-* \
|
|
"${HOME}/LIVE_BOOT/staging/live/initrd"
|
|
|
|
|
|
# Create an ISOLINUX (Syslinux) boot menu
|
|
cat <<'EOF' > "${HOME}/LIVE_BOOT/staging/isolinux/isolinux.cfg"
|
|
UI vesamenu.c32
|
|
|
|
MENU TITLE Boot Menu
|
|
DEFAULT linux
|
|
TIMEOUT 600
|
|
MENU RESOLUTION 640 480
|
|
MENU COLOR border 30;44 #40ffffff #a0000000 std
|
|
MENU COLOR title 1;36;44 #9033ccff #a0000000 std
|
|
MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
|
|
MENU COLOR unsel 37;44 #50ffffff #a0000000 std
|
|
MENU COLOR help 37;40 #c0ffffff #a0000000 std
|
|
MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
|
|
MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
|
|
MENU COLOR msg07 37;40 #90ffffff #a0000000 std
|
|
MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
|
|
|
|
LABEL linux
|
|
MENU LABEL reHDD [BIOS]
|
|
MENU DEFAULT
|
|
KERNEL /live/vmlinuz
|
|
APPEND initrd=/live/initrd boot=live
|
|
EOF
|
|
|
|
# Create an EFI/UEFI boot menu
|
|
cat <<'EOF' > "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg"
|
|
insmod part_gpt
|
|
insmod part_msdos
|
|
insmod fat
|
|
insmod iso9660
|
|
|
|
insmod all_video
|
|
insmod font
|
|
|
|
set default="0"
|
|
set timeout=30
|
|
|
|
# If X has issues finding screens, experiment with/without nomodeset.
|
|
|
|
menuentry "reHDD [UEFI]" {
|
|
search --no-floppy --set=root --label DEBLIVE
|
|
linux ($root)/live/vmlinuz boot=live
|
|
initrd ($root)/live/initrd
|
|
}
|
|
EOF
|
|
|
|
# Copy the grub.cfg file to the EFI BOOT directory
|
|
cp "${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" "${HOME}/LIVE_BOOT/staging/EFI/BOOT/"
|
|
|
|
# Create helper GRUB boot config
|
|
cat <<'EOF' > "${HOME}/LIVE_BOOT/tmp/grub-embed.cfg"
|
|
if ! [ -d "$cmdpath" ]; then
|
|
# On some firmware, GRUB has a wrong cmdpath when booted from an optical disc.
|
|
# https://gitlab.archlinux.org/archlinux/archiso/-/issues/183
|
|
if regexp --set=1:isodevice '^(\([^)]+\))\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "$cmdpath"; then
|
|
cmdpath="${isodevice}/EFI/BOOT"
|
|
fi
|
|
fi
|
|
configfile "${cmdpath}/grub.cfg"
|
|
EOF
|
|
|
|
# Copy BIOS/legacy boot required files to live environment
|
|
cp /usr/lib/ISOLINUX/isolinux.bin "${HOME}/LIVE_BOOT/staging/isolinux/"
|
|
cp /usr/lib/syslinux/modules/bios/* "${HOME}/LIVE_BOOT/staging/isolinux/"
|
|
|
|
# Copy EFI/modern boot required files to live environment
|
|
cp -r /usr/lib/grub/x86_64-efi/* "${HOME}/LIVE_BOOT/staging/boot/grub/x86_64-efi/"
|
|
|
|
# Generate an EFI bootable GRUB image.
|
|
grub-mkstandalone -O i386-efi \
|
|
--modules="part_gpt part_msdos fat iso9660" \
|
|
--locales="" \
|
|
--themes="" \
|
|
--fonts="" \
|
|
--output="${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTIA32.EFI" \
|
|
"boot/grub/grub.cfg=${HOME}/LIVE_BOOT/tmp/grub-embed.cfg"
|
|
|
|
grub-mkstandalone -O x86_64-efi \
|
|
--modules="part_gpt part_msdos fat iso9660" \
|
|
--locales="" \
|
|
--themes="" \
|
|
--fonts="" \
|
|
--output="${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTx64.EFI" \
|
|
"boot/grub/grub.cfg=${HOME}/LIVE_BOOT/tmp/grub-embed.cfg"
|
|
|
|
# Create a FAT16 UEFI boot disk image containing the EFI bootloaders.
|
|
(cd "${HOME}/LIVE_BOOT/staging" && \
|
|
dd if=/dev/zero of=efiboot.img bs=1M count=20 && \
|
|
mkfs.vfat efiboot.img && \
|
|
mmd -i efiboot.img ::/EFI ::/EFI/BOOT && \
|
|
mcopy -vi efiboot.img \
|
|
"${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTIA32.EFI" \
|
|
"${HOME}/LIVE_BOOT/staging/EFI/BOOT/BOOTx64.EFI" \
|
|
"${HOME}/LIVE_BOOT/staging/boot/grub/grub.cfg" \
|
|
::/EFI/BOOT/
|
|
)
|
|
|
|
# Generate ISO from live environment
|
|
xorriso \
|
|
-as mkisofs \
|
|
-iso-level 3 \
|
|
-o "${HOME}/LIVE_BOOT/debian-custom.iso" \
|
|
-full-iso9660-filenames \
|
|
-volid "reHDD" \
|
|
--mbr-force-bootable -partition_offset 16 \
|
|
-joliet -joliet-long -rational-rock \
|
|
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
|
|
-eltorito-boot \
|
|
isolinux/isolinux.bin \
|
|
-no-emul-boot \
|
|
-boot-load-size 4 \
|
|
-boot-info-table \
|
|
--eltorito-catalog isolinux/isolinux.cat \
|
|
-eltorito-alt-boot \
|
|
-e --interval:appended_partition_2:all:: \
|
|
-no-emul-boot \
|
|
-isohybrid-gpt-basdat \
|
|
-append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B ${HOME}/LIVE_BOOT/staging/efiboot.img \
|
|
"${HOME}/LIVE_BOOT/staging"
|
|
|
|
cp "${HOME}/LIVE_BOOT/debian-custom.iso" reHDD_Bootable.iso |