Last active
November 24, 2023 09:46
-
-
Save papamoose/c1132333920cec67cb50 to your computer and use it in GitHub Desktop.
add non-free firmware into initrd.gz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# trap keyboard interrupt (control-c) | |
trap control_c INT | |
# Must be run as root | |
# requires: | |
# - wget | |
# - pax | |
# shows how initrd.gz finds firmware, could potentially download all firmware debs and put them in /firmware. | |
#root@tftp:/var/lib/tftpboot/kernel/debian/wheezy/amd64/non-free/tmp# grep -ri "*.udeb" * | |
#bin/mountmedia: for filename in $dir/*.deb $dir/*.udeb $dir/*.ude \ | |
#bin/mountmedia: $dir/firmware/*.deb $dir/firmware/*.udeb $dir/firmware/*.ude; do | |
#bin/check-missing-firmware: check_for_firmware /firmware/*.deb /firmware/*.udeb | |
# kernel.org git repo of firmware: http://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/ | |
INITRD="$1" | |
WORKING_DIR=/tmp/initrd | |
CURRENT_DIR="$(pwd -P)" | |
mkdir -p $WORKING_DIR | |
cleanup() { | |
rm -rf $WORKING_DIR/* | |
return $? | |
} | |
control_c() { | |
# run if user hits control-c | |
echo "Caught interupt. Cleaning up..." | |
cleanup | |
exit $? | |
} | |
main(){ | |
echo "Copying kernel and ram disk to non-free directory..." | |
cp $INITRD $WORKING_DIR | |
mkdir -p $WORKING_DIR/firmware | |
cd $WORKING_DIR | |
echo "Downloading firmware.tar.gz..." | |
wget -cq http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/unstable/current/firmware.tar.gz | |
echo "Extracting firmware..." | |
tar -C firmware -zxf firmware.tar.gz | |
echo "Combining all debs in firmware.tar.gz into one gzip file..." | |
pax -x sv4cpio -s'%firmware%/firmware%' -w firmware | gzip -c >firmware.cpio.gz | |
# cd to the directory where you have your initrd | |
cd "$OUTPUT_DIR" | |
[ -f $INITRD/initrd.gz.orig ] || cp -p $INITRD $OUTPUT_DIR/initrd.gz.orig | |
echo "Creating new ram disk with non-free firmware..." | |
cat $OUTPUT_DIR/initrd.gz.orig $WORKING_DIR/firmware.cpio.gz > $OUTPUT_DIR/initrd.gz | |
} | |
usage(){ | |
echo "Usage: $0 </path/to/initrd.gz>" | |
echo " Copies your original initrd and injects nonfree drivers" | |
echo " into the RAM disk you specify." | |
} | |
if [ -z "$INITRD" ]; then | |
usage | |
exit | |
else | |
OUTPUT_DIR="$PWD/$(dirname $INITRD)" | |
cleanup | |
main | |
cleanup | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This entire script can now be done like this: