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.

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 stretch 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 which a user can employ to extract all files from an ISO Image:

bsdtar -C DESTINATION -xf debian-9.3.0-i386-netinst.iso
xorriso -osirrox on -indev debian-9.3.0-i386-netinst.iso -extract / DESTINATION
7z x -oDESTINATION debian-9.3.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.

udevil mount debian-9.3.0-i386-netinst.iso

Copy the files to isofiles with, for example,

cp -rT /media/debian-9.3.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/

Fixing md5sum.txt

 # cd isofiles
 # md5sum `find -follow -type f` > md5sum.txt
 # cd ..

Creating a New Bootable ISO Image

Install genisoimage and do

genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/ \                                                    
            -no-emul-boot -boot-load-size 4 -boot-info-table \                                                           
            -o preseed-debian-9.3.0-i386-netinst.iso isofiles

(Omit \ when using the command. It is only there to indicate a line-break ).

A quick test of the ISO using the qemu command

qemu -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

cat debian-9.3.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 preseed-debian-9.3.0-i386-netinst.iso

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-9.3.0-i386-netinst.iso \
        -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
        -c isolinux/ -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-9.3.0-i386-netinst.iso