Differences between revisions 1 and 21 (spanning 20 versions)
Revision 1 as of 2006-08-03 15:14:04
Size: 1761
Editor: ?FilipVanRaemdonck
Comment:
Revision 21 as of 2020-04-15 03:53:58
Size: 5609
Editor: PaulWise
Comment: cleanups
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Debian-Installer: How to modify an existing CD image to preseed d-i =
If you want to preseed DebianInstaller right from booting the installer CD, you can modify it to use an initrd which has your preseed.cfg file.

== Create copy of image ==
You need one of the already built ISO images, which will be used as the basis that we modify. Because you can't modify an ["ISO9660"] image, you've to copy it first:

... as root ... {{{
 # mkdir -p loopdir
 # mount -o loop your-image.iso loopdir (you need to load loop module: #modprobe loop)
 # rm -rf cd
 # mkdir cd
 # rsync -a -H --exclude=TRANS.TBL loopdir/ cd
 # umount loopdir
}}}
== Hack the initrd ==
... as root ... {{{
# mkdir irmod
# cd irmod
# gzip -d < ../cd/install/2.6/initrd.gz | \
 cpio --extract --verbose --make-directories --no-absolute-filenames
# cp ../my_preseed.cfg irmod/preseed.cfg
# find . | cpio -H newc --create --verbose | \
 gzip -9 > ../cd/install/2.6/initrd.gz
# cd ../
# rm -fr irmod/
}}}
== Fix md5sum's ==
{{{
 # cd cd
 # md5sum `find -follow -type f` > md5sum.txt
 # cd ..
}}}
== Create new image ==
To make the cdrom bootable, you need to run mkisofs with appropriate parameters. Here is how to do it for x86/amd64, using isolinux.

Change to the top of the cd directory then:

To create the cdrom image using the isolinux boot image:{{{
 # mkisofs -o test.iso -r -J -no-emul-boot -boot-load-size 4 \
 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat ./cd
}}}
If you want you can do a quick test of the iso using qemu:{{{
 # qemu -user-net -cdrom test.iso
}}}
Burn the image to cdrom{{{
 # cdrecord -dev /dev/hd? test.iso
{{{#!wiki note
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.
Line 49: Line 5:
Much of this information was gleaned from the wiki document ["DebianInstaller/Modify"]. Modifying an installation ISO image to preseed the installer from its initrd.

<<TableOfContents(3)>>

== Introduction ==

If you want to incorporate preseeding directly into the Debian Installer (as opposed to using [[https://www.debian.org/releases/stable/i386/ch05s03.en.html#preseed-args|boot parameters]]) it is necessary to modify (remaster) the ISO image to use one of the methods advised by the [[https://www.debian.org/releases/stable/i386/apbs01.en.html|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 [[ManipulatingISOs#remaster|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 [[https://www.debian.org/distrib/netinst|Netinst]] image or [[https://www.debian.org/CD/http-ftp/|DVD-1]] would be suitable. A buster i386 netinst image is used as an example in what follows. Because an [[WikiPedia:ISO_9660|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 [[ManipulatingISOs#extraction|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 [[ManipulatingISOs#loopmount|mount the ISO image]] and copy all the files from it to a chosen directory, ''isofiles''.

 * A [[DesktopEnvironment|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 [[DebianPkg:mc|Midnight Commander]].

 * Command line utilities for mounting an ISO image include DebianMan: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/
}}}

== Regenerating md5sum.txt ==

{{{
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|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 DebianMan: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 DebianPkg: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 DebianMan: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 preseed-debian-10.2.0-i386-netinst.iso
}}}

DebianMan:isohybrid is found in the DebianPkg: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 DebianPkg: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
}}}

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.

Introduction

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

Regenerating md5sum.txt

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 preseed-debian-10.2.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-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