#!/bin/sh set -e printf "Checking dependencies...\n" dpkg-query -W \ git \ debootstrap \ squashfs-tools \ xorriso \ isolinux \ syslinux-efi \ grub-pc-bin \ grub-efi-amd64-bin \ mtools \ dosfstools mkdir -p /srv/LIVE_BOOT debootstrap \ --arch=amd64 \ --variant=minbase \ --merged-usr \ sid \ /srv/LIVE_BOOT/chroot \ http://deb.debian.org/debian/ # Copy the filesystem tree cp -R $PWD/root/* /srv/LIVE_BOOT/chroot # Run script in chroot chroot /srv/LIVE_BOOT/chroot /srv/entrypoint.sh # Clean the installation rm -rf /srv/LIVE_BOOT/chroot/srv/* # Change password to the users printf "Setting passwords for users...\n" printf "root:root\n" | chpasswd --root /srv/LIVE_BOOT/chroot printf "live-user:root\n" | chpasswd --root /srv/LIVE_BOOT/chroot # Create directories that will contain files for our live environment files and scratch files. bash -c "mkdir -p /srv/LIVE_BOOT/{staging/{EFI/boot,boot/grub/x86_64-efi,isolinux,live},tmp}" # Compress the chroot environment into a Squash filesystem. # I'm using blocks of 1MiB with xz for x86 mksquashfs \ /srv/LIVE_BOOT/chroot \ /srv/LIVE_BOOT/staging/live/filesystem.squashfs \ -e boot \ -b 1M \ -comp xz \ -Xbcj x86 # Copy the kernel and initramfs from inside the chroot to the live directory. cp /srv/LIVE_BOOT/chroot/boot/vmlinuz-* \ /srv/LIVE_BOOT/staging/live/vmlinuz && \ cp /srv/LIVE_BOOT/chroot/boot/initrd.img-* \ /srv/LIVE_BOOT/staging/live/initrd # Prepare Boot Loader Menus # Create an ISOLINUX (Syslinux) boot menu. This boot menu is used when booting in BIOS/legacy mode. cat <<'EOF' >/srv/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 Debian Live [BIOS/ISOLINUX] MENU DEFAULT KERNEL /live/vmlinuz APPEND initrd=/live/initrd boot=live LABEL linux MENU LABEL Debian Live [BIOS/ISOLINUX] (nomodeset) MENU DEFAULT KERNEL /live/vmlinuz APPEND initrd=/live/initrd boot=live nomodeset EOF # Create a second, similar, boot menu for GRUB. This boot menu is used when booting in EFI/UEFI mode. cat <<'EOF' >/srv/LIVE_BOOT/staging/boot/grub/grub.cfg search --set=root --file /DEBIAN_CUSTOM set default="0" set timeout=30 # If X has issues finding screens, experiment with/without nomodeset. menuentry "Debian Live [EFI/GRUB]" { linux ($root)/live/vmlinuz boot=live initrd ($root)/live/initrd } menuentry "Debian Live [EFI/GRUB] (nomodeset)" { linux ($root)/live/vmlinuz boot=live nomodeset initrd ($root)/live/initrd } EOF # Create a third boot config. # This config will be an early configuration file that is embedded inside GRUB in the EFI partition. # This finds the root and loads the GRUB config from there. cat <<'EOF' >/srv/LIVE_BOOT/tmp/grub-standalone.cfg search --set=root --file /DEBIAN_CUSTOM set prefix=($root)/boot/grub/ configfile /boot/grub/grub.cfg EOF # Create a special file in staging named DEBIAN_CUSTOM. # This file will be used to help GRUB figure out which device contains our live filesystem. # This file name must be unique and must match the file name in our grub.cfg config. touch /srv/LIVE_BOOT/staging/DEBIAN_CUSTOM # Prepare Boot Loader Files # Copy BIOS/legacy boot required files into our workspace. cp /usr/lib/ISOLINUX/isolinux.bin "/srv/LIVE_BOOT/staging/isolinux/" && \ cp /usr/lib/syslinux/modules/bios/* "/srv/LIVE_BOOT/staging/isolinux/" # Copy EFI/modern boot required files into our workspace. cp -r /usr/lib/grub/x86_64-efi/* "/srv/LIVE_BOOT/staging/boot/grub/x86_64-efi/" # Generate an EFI bootable GRUB image. grub-mkstandalone \ --format=x86_64-efi \ --output=/srv/LIVE_BOOT/tmp/bootx64.efi \ --locales="" \ --fonts="" \ "boot/grub/grub.cfg=/srv/LIVE_BOOT/tmp/grub-standalone.cfg" # Create a FAT16 UEFI boot disk image containing the EFI bootloader. # Note the use of the mmd and mcopy commands to copy our UEFI boot loader named bootx64.efi. (cd /srv/LIVE_BOOT/staging/EFI/boot && \ 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 /srv/LIVE_BOOT/tmp/bootx64.efi ::efi/boot/ ) # Create Bootable ISO/CD xorriso \ -as mkisofs \ -iso-level 3 \ -o "/srv/LIVE_BOOT/debian-custom.iso" \ -full-iso9660-filenames \ -volid "DEBIAN_CUSTOM" \ -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 /EFI/boot/efiboot.img \ -no-emul-boot \ -isohybrid-gpt-basdat \ -append_partition 2 0xef /srv/LIVE_BOOT/staging/EFI/boot/efiboot.img \ "/srv/LIVE_BOOT/staging"