From 0e3fcf3170ec146f68fd8a41470a2f9e08cd0ca0 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Thu, 11 Aug 2022 00:21:54 +0200 Subject: [PATCH] Add initrd tools --- path/wdvn-initrd-create | 6 ++++++ path/wdvn-initrd-extract | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 path/wdvn-initrd-create create mode 100755 path/wdvn-initrd-extract diff --git a/path/wdvn-initrd-create b/path/wdvn-initrd-create new file mode 100755 index 0000000..6527c13 --- /dev/null +++ b/path/wdvn-initrd-create @@ -0,0 +1,6 @@ +#!/bin/bash +set -e +INPUT="$1" +OUTPUT="$2" +cd "$INPUT" +find . | cpio -H newc -o | gzip -9 > "$OUTPUT" \ No newline at end of file diff --git a/path/wdvn-initrd-extract b/path/wdvn-initrd-extract new file mode 100755 index 0000000..3cd3546 --- /dev/null +++ b/path/wdvn-initrd-extract @@ -0,0 +1,25 @@ +#!/bin/bash +set -e +OLDPWD="$PWD" +INPUT="$1" +OUTPUT="$2" +TEMP="$2.tmp" +TYPE="$(file -b -L "$INPUT")" + +mkdir -p "$TEMP/basic" + +if [[ "$TYPE" == *"cpio archive"* ]]; then + mkdir -p "$TEMP/microcode" + cd "$TEMP/microcode" + BLOCKS="$(cpio -i <"$INPUT" 2>&1 >/dev/null | tail -1)" + BLOCKS="${BLOCKS%% *}" + dd if="$INPUT" of="$TEMP/initrd.img" bs=512 skip=$BLOCKS + cd "$TEMP/basic" + zcat "$TEMP/initrd.img" | cpio -i + rm "$TEMP/initrd.img" +else + cd "$TEMP/basic" + zcat "$INPUT" | cpio -i +fi + +mv "$TEMP" "$OUTPUT" \ No newline at end of file