Skip to content

Instantly share code, notes, and snippets.

@Data-ptr
Created April 21, 2018 16:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Data-ptr/eb96004e2b9bfc9b45a65673cad37b17 to your computer and use it in GitHub Desktop.
Save Data-ptr/eb96004e2b9bfc9b45a65673cad37b17 to your computer and use it in GitHub Desktop.
Modifying a Debian ISO (amd64) with a preseed file, but on OSX
#
# Figured out using:
# https://wiki.debian.org/DebianInstaller/Preseed/EditIso
# https://www.thegeekstuff.com/2009/07/how-to-view-modify-and-recreate-initrd-img/
# https://gist.github.com/Aktau/5510437
# https://www.cyberciti.biz/faq/how-to-extract-a-deb-file-without-opening-it-on-debian-or-ubuntu-linux/
#
## Go home
cd
## Install needed things
# Hope you have Homebrew installed and working
brew install p7zip gzip wget xorriso
## make working area
# -p = make intermediate directories as needed
mkdir -p builds/debianpreseeded/isofiles
## Go to working area
cd builds/debpreseeded
## Get net install CD (change to newest if you like)
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso
## 7Zip extrct the ISO
# x = extract o = output
7z x -oisofiles debian-9.4.0-amd64-netinst.iso
## Make initrd stuff writable (maybe not nessicary using 7zip and or OSX)
# R = recursive, +w = write (on OSX -R first, opposite of most guides)
chmod -R +w isofiles/install.amd/
## Gzip extract the initrd image
gunzip isofiles/install.amd/initrd.gz
## Move the image to working area
mv isofiles/install.amd/initrd ./
## Make a sub-working area to work with initrd files
mkdir initrdfiles
## Go to sub-working area
cd initrdfiles
## CoPy IO out the files into the sub-working area
# i = read and extarct, d = create directories if needed, F = from file
cpio -id -F ../initrd
## Include the `preseed.cfg` file (hope there was one)
cp ../preseed.cfg ./
## CoPy IO the files (now with the preseed) back into a file
find . | cpio --create --format='newc' > ../initrdnew
## Back to main working area
cd ..
## Gzip it back up
gzip initrdnew
## Put it back into place, with the proper name as well
mv initrdnew.gz isofiles/install.amd/initrd.gz
## Take writable back off
chmod -R -w isofiles/install.amd/
## Change to the ISO working directory
cd isofiles
## Rebuild the md5 file (OSX style!)
#`md5 -r` (r = reverse) replicates `md5sum` output on OSX
# for `find` -L replaces `-follow`
# and OSX needs ` . ` whereas it can be left out on Linux boxes
# Piped to `sort` to match original `md5sum.txt`
md5 -r `find -L . -type f | sort` > md5sum.txt
# output to md5sum2.txt and run `head md5sum*` to see difference (or lack)
## Back to main workspace
cd ..
## Make a sub-workspace for geting hybrid iso file
mkdir isolinuxdeb
## Move into it
cd isolinuxdeb/
## Get a package for isolinux
wget http://ftp.us.debian.org/debian/pool/main/s/syslinux/isolinux_6.03+dfsg-5+deb8u2_all.deb
## eXtract the files (apart...?) with ARchiver
ar x isolinux_6.03+dfsg-5+deb8u2_all.deb
## Untar the files
tar xvf data.tar.xz
## That'a all, back to main main workspace
cd ..
## And rebuild the ISO
xorriso -as mkisofs \
-r -J -V "preseed debian" \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-no-emul-boot \
-partition_offset 16 \
-boot-load-size 4 \
-boot-info-table \
-isohybrid-mbr "./isolinuxdeb/usr/lib/ISOLINUX/isohdpfx.bin" \
-o preseededsedian.iso \
./isofiles
## Get rid of old initrd working files
rm -rf ./initrd*
## Also get rid of isolinux package stuff
rm -rf ./isolinuxdeb/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment