Skip to content

Instantly share code, notes, and snippets.

@hedinasr
Created July 5, 2017 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hedinasr/302f1cd1ad6fca98030f1b160ca2ffb0 to your computer and use it in GitHub Desktop.
Save hedinasr/302f1cd1ad6fca98030f1b160ca2ffb0 to your computer and use it in GitHub Desktop.
Script to add firmware files and preseed file to a debian ISO
#!/bin/bash
# add-preseed-and-firmware-to-debian: Add non-free firmware and preseed to Debian install media
#
# Copyright (C) 2016-2017 Hedi Nasr <h.nsr69@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Changelog:
# 2017.07.05 - Initial creation
#
# https://cdimage.debian.org/cdimage/archive/8.8.0/amd64/iso-cd/debian-8.8.0-amd64-netinst.iso
# https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.0.0-amd64-netinst.iso
if [ "$(id -u)" != "0" ]
then
echo "This script must be run as root" 1>&2
exit 1
fi
if [ $# -ne 3 ]
then
echo "Usage: $0 <input.iso> <ouput.iso> <preseed.file>"
exit 1
fi
iso=$1
output=$2
preseed=$3
lpdir=__loopdir__
cddir=__cd__
irdir=__irmod__
bnx2="firmware-bnx2_0.43_all.deb"
bnx2x="firmware-bnx2x_0.43_all.deb"
md5_bnx2="ccc2fdab32d5e64d9efe4a31ccfd6f3a"
md5_bnx2x="a8500ad4ae81e4bb9a6e0b49f4a87c27"
# Fichier md5
echo $md5_bnx2 $bnx2 > $bnx2.md5
echo $md5_bnx2x $bnx2x > $bnx2x.md5
# On télécharge les deux fichier .deb
wget http://ftp.fr.debian.org/debian/pool/non-free/f/firmware-nonfree/$bnx2
wget http://ftp.fr.debian.org/debian/pool/non-free/f/firmware-nonfree/$bnx2x
if md5sum -c $bnx2.md5 && md5sum -c $bnx2x.md5
then
echo "MD5 passed"
else
echo "MD5 failed!"
exit 1
fi
# Copie de l'original
mkdir $lpdir
mount -o loop $iso $lpdir
rm -rf $cddir
mkdir $cddir
rsync -a -H --exclude=TRANS.TBL $lpdir/ $cddir
umount $lpdir
# Update initrd
mkdir $irdir
cd $irdir
gzip -d < ../$cddir/install.amd/initrd.gz | \
cpio --extract --make-directories --no-absolute-filenames
cp ../$preseed preseed.cfg
find . | cpio -H newc --create | \
gzip -9 > ../$cddir/install.amd/initrd.gz
cd ../
rm -rf $irdir
# On ajoute les firmware
cp $bnx2 $cddir/firmware
cp $bnx2x $cddir/firmware
# Fix checksum
cd $cddir
md5sum `find -follow -type f` > md5sum.txt
cd ..
# Create iso
genisoimage -o $output -r -J -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat ./$cddir
# Cleaning up
rm -rf $lpdir
rm -rf $cddir
rm -f $bnx2 $bnx2x
rm -f $bnx2.md5 $bnx2x.md5
echo "Created $output!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment