Add initrd tools

This commit is contained in:
Fierelier 2022-08-11 00:21:54 +02:00
parent dc89e6debd
commit 0e3fcf3170
2 changed files with 31 additions and 0 deletions

6
path/wdvn-initrd-create Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
set -e
INPUT="$1"
OUTPUT="$2"
cd "$INPUT"
find . | cpio -H newc -o | gzip -9 > "$OUTPUT"

25
path/wdvn-initrd-extract Executable file
View File

@ -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"