It is intended that all the commands necessary to remaster an ISO image can be run by a regular user. Root privilege is only required when it comes to writing the modified image to a bootable device.
Modifying an installation ISO image to preseed the installer from its initrd.
If you want to incorporate preseeding directly into the Debian Installer (as opposed to using boot parameters) it is necessary to modify (remaster) the ISO image to use one of the methods advised by the Installation Guide. As the Guide says:
There are three methods that can be used for preseeding: initrd, file and network.
The file method to get a remastered image to use a preseed file within an image puts preseed.cfg on the image's file system. Putting preseed.cfg into the initrd is the method described on this page. The installer will look for a file of this name when it boots.
Note: This page describes remastering the initrd file named initrd.gz. This means, you need to boot the text-based installer, to have the installer detect the preseed.cfg file (thus: use the 'Install' or 'Expert install' option from the GRUB menu)! When you use the graphical installer options ('Graphical install' or 'Graphical expert install'), the preseed.cfg will not be found!
Extracting the Initrd from an ISO Image
One of the already built ISO images is required; either a Netinst image or DVD-1 would be suitable. A buster i386 netinst image is used as an example in what follows. Because an ISO 9660 image is a read-only image, the initrd will have to be extracted from it (together with all the other files), modified and a new image built with the new initrd.
There are at least three commands that a user can employ to extract all files from an ISO Image:
bsdtar -C DESTINATION -xf debian-10.2.0-i386-netinst.iso xorriso -osirrox on -indev debian-10.2.0-i386-netinst.iso -extract / DESTINATION 7z x -oDESTINATION debian-10.2.0-i386-netinst.iso
Another user technique (which is the one used on this page) would be to mount the ISO image and copy all the files from it to a chosen directory, isofiles.
A desktop environment likely has a file manager which will do the mounting and copying for you.
A terminal application which will display the files in the image and allow copying to isofiles is Midnight Commander.
Command line utilities for mounting an ISO image include udevil:
udevil mount debian-10.2.0-i386-netinst.iso
Copy the files to isofiles with, for example,
cp -rT /media/debian-10.2.0-i386-netinst.iso/ isofiles/
Adding a Preseed File to the Initrd
You now have the directory isofiles with all the ISO's files in it. Make initrd.gz writable by the user, uncompress it and append a preseed file to the initrd. Recompress the initrd and return initrd.gz to its original read-only state:
chmod +w -R isofiles/install.386/ gunzip isofiles/install.386/initrd.gz echo preseed.cfg | cpio -H newc -o -A -F isofiles/install.386/initrd gzip isofiles/install.386/initrd chmod -w -R isofiles/install.386/
cd isofiles chmod +w md5sum.txt find -follow -type f ! -name md5sum.txt -print0 | xargs -0 md5sum > md5sum.txt chmod -w md5sum.txt cd ..
A warning will be issued because ./debian is a symlink to . :
find: File system loop detected; ‘./debian’ is part of the same file system loop as ‘.’ :
The production of md5sum.txt is unaffected.
Creating a New Bootable ISO Image
The following instructions suffice for i386 and amd64 in legacy BIOS mode. Information on how to create bootable ISOs for EFI or for architectures like arm64 is given at RepackBootableISO.
Install genisoimage and do
genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table \ -o preseed-debian-10.2.0-i386-netinst.iso isofiles
(Omit \ when using the command. It is only there for presentational purposes to indicate a line-break).
A quick test of the ISO using the qemu command
qemu-system-i386 -net user -cdrom test.iso
could be done before burning it to a CD or DVD or writing it to a USB device.
As root, the original ISO was capable of being written to a USB stick at /dev/sdX (X depends on what lsblk gives when the stick is plugged in) with
cp debian-10.2.0-i386-netinst.iso /dev/sdX
and would have been bootable. The new ISO can be restored to a bootable state for using on a USB device with
isohybrid is found in the syslinux-utils package.
Alternatively, the genisoimage and isohybrid commands can be replaced by the single command:
xorriso -as mkisofs -o preseed-debian-10.2.0-i386-netinst.iso \ -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \ -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot \ -boot-load-size 4 -boot-info-table isofiles
after installing isolinux.
Finally, remove isofiles and unmount the original ISO:
chmod +w -R isofiles rm -r isofiles udevil unmount /media/debian-10.2.0-i386-netinst.iso