Skip to content

Instantly share code, notes, and snippets.

Last active October 2, 2022 10:49
Show Gist options
  • Save nixikanius/971b9c46d43b91b890953d79d8c3bb1b to your computer and use it in GitHub Desktop.
Save nixikanius/971b9c46d43b91b890953d79d8c3bb1b to your computer and use it in GitHub Desktop.
Preparing Debian ISO image with remote installation over SSH

Preparation of ISO Image

  1. Create working directory:

    mkdir debinst
  2. Download netinstall image:

    (cd debinst && curl -OL
  3. Prepare debinst/preseed.cfg with following content:

    # prevent questions for network configuration
    d-i netcfg/get_hostname string debian
    d-i netcfg/get_domain string local
    # activating of remote installation over SSH
    d-i anna/choose_modules string network-console
    d-i network-console/password           password installer
    d-i network-console/password-again     password installer
    # netcfg will choose an interface that has link if possible. This makes it
    # skip displaying a list if there is more than one interface.
    d-i netcfg/choose_interface            select auto
  4. Run docker container to prepare new ISO:

    docker run --rm -it -v $PWD/debinst:/mnt/debinst debian bash

    (Note: The following commands are assumed to be executed inside the container.)

  5. Install required packages:

    apt update && apt install -y --no-install-recommends xorriso isolinux cpio nano
  6. Create temp directory for ISO image:

    export ISO_FILES="$(mktemp -d)"
  7. Extract original installation image to temp directory:

    xorriso -osirrox on -indev /mnt/debinst/debian-*-amd64-netinst.iso -extract / $ISO_FILES
  8. Extract initrd.gz:

    gunzip $ISO_FILES/install.amd/initrd.gz
  9. Add preseed.cfg to initrd:

    (cd /mnt/debinst && echo preseed.cfg | cpio -H newc -o -A -F $ISO_FILES/install.amd/initrd)
  10. gzip back initrd:

    gzip $ISO_FILES/install.amd/initrd
  11. Recalculate md5 sum:

    (cd $ISO_FILES; md5sum `find -follow -type f` > md5sum.txt)
  12. Modify $ISO_FILES/boot/grub/grub.cfg:

    nano $ISO_FILES/boot/grub/grub.cfg
    1. Add menu timeout to the top of file:
      set timeout=10
    2. Insert new menu entry for automatic install before all current entries:
      menuentry --hotkey=r 'Remote install' {
          set background_color=black
          linux    /install.amd/vmlinuz auto=true vga=788 --- quiet
          initrd   /install.amd/initrd.gz
  13. Make new ISO image:

    xorriso -as mkisofs -o /mnt/debinst/debian-preseed.iso -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -c isolinux/ -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat $ISO_FILES
  14. Exit docker container:

  15. Flash ISO image to external drive:

    sudo dd if=./debinst/debian-preseed.iso of=/dev/disk2 bs=1m
  16. Plug flash drive into target machine and boot from it.

  17. Check DHCP server for IP address of target machine and connect to installator via SSH:

    ssh installer@target

    (Note: Use the password from preseed.cfg to authenticate.)

Inspired by

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment