logo

make-initrd

Unnamed repository; edit this file 'description' to name the repository.
commit: 87d30823c9f1cf589f2600848e658a1e63e07c60
parent: d52f029df67cfae4a0ffd047a4594d980a14be97
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 22 Mar 2019 10:58:29 +0100

make-initrd: Fix quotes and move to POSIX shell

Diffstat:

Dmake-initrd.bash63---------------------------------------------------------------
Amake-initrd.sh64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 63 deletions(-)

diff --git a/make-initrd.bash b/make-initrd.bash @@ -1,63 +0,0 @@ -#!/bin/bash -# Copyright 2017-2019 Haelwenn (lanodan) Monnier <contact@hacktivis.me> -# Distributed under the terms of the ISC license - -kv=${1:-$(uname -r)} -out_base=initramfs-${kv} -elves="lvm busybox blkid lsblk cryptsetup mksh zfs zpool" -WORKDIR="$(pwd)" - -die() { - echo "$@" - exit 1 -} - -if test -e "$out_base"; then - rm -fr "$out_base" || die "Failed: rm -fr $out_base" -fi -mkdir -p "$out_base" || die "Failed: mkdir $out_base" -pushd "$out_base" || die "Failed: pushd $out_base" -mkdir -p usr/bin bin lib dev proc sys newroot etc || die "Failed creating base directories" -ln -s /proc/mounts etc/mtab || die "Failed symlink for /etc/mtab" - -if test -d /lib/modules/$kv -then - mkdir -p lib/modules ; cp -pr /lib/modules/$kv lib/modules -else - echo "[Warning] “/lib/modules/$kv” doesn’t exist" -fi - -mknod -m 600 dev/console c 5 1 -mknod -m 666 dev/urandom c 1 9 -mknod -m 666 dev/random c 1 8 -mknod -m 640 dev/mem c 1 1 -mknod -m 666 dev/null c 1 3 -mknod -m 666 dev/tty c 5 0 -mknod -m 666 dev/zero c 1 5 -mknod -m 640 dev/tty1 c 4 1 - -for elf in $elves; do - cp $(which $elf) bin/ -done - -cp "${WORKDIR}/init" . && chmod 755 init || exit -ln bin/mksh bin/sh -bin/busybox --install usr/bin - -for bin in $(find bin); do - if ldd "$bin" >/dev/null - then - for lib in $(ldd "$bin" | sed -nre 's,.* (/.*lib.*/.*.so.*) .*,\1,p') - do - filename=$(basename "$lib") - test -e "/lib/${filename}" || cp "$lib" lib - done - fi -done - -if find . -print0 | cpio --null -ov --format=newc | xz -9 --check=crc32 > ../${out_base}.cpio.xz; then - test -e /boot/${out_base}.cpio.xz && mv /boot/${out_base}.cpio.xz /boot/${out_base}.cpio.xz.old - cp ../${out_base}.cpio.xz /boot -fi - -popd diff --git a/make-initrd.sh b/make-initrd.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Copyright 2017-2019 Haelwenn (lanodan) Monnier <contact@hacktivis.me> +# Distributed under the terms of the ISC license + +kv=${1:-$(uname -r)} +out_base=initramfs-${kv} +elves="lvm busybox blkid lsblk cryptsetup mksh zfs zpool" +WORKDIR="$(pwd)" + +die() { + echo "$@" + exit 1 +} + +if test -e "$out_base"; then + rm -fr "$out_base" || die "Failed: rm -fr $out_base" +fi +mkdir -p "$out_base" || die "Failed: mkdir $out_base" +cd "$out_base" || die "Failed: cd $out_base" +mkdir -p usr/bin bin lib dev proc sys newroot etc || die "Failed creating base directories" +ln -s /proc/mounts etc/mtab || die "Failed symlink for /etc/mtab" + +if test -d "/lib/modules/$kv" +then + mkdir -p lib/modules ; cp -pr "/lib/modules/$kv" lib/modules +else + echo "[Warning] “/lib/modules/$kv” doesn’t exist" +fi + +mknod -m 600 dev/console c 5 1 +mknod -m 666 dev/urandom c 1 9 +mknod -m 666 dev/random c 1 8 +mknod -m 640 dev/mem c 1 1 +mknod -m 666 dev/null c 1 3 +mknod -m 666 dev/tty c 5 0 +mknod -m 666 dev/zero c 1 5 +mknod -m 640 dev/tty1 c 4 1 + +for elf in $elves; do + origin=$(command -v "$elf") + cp "$origin" bin/ +done + +cp "${WORKDIR}/init" . && chmod 755 init || exit +ln bin/mksh bin/sh +bin/busybox --install usr/bin + +for bin in $(find bin); do + if ldd "$bin" >/dev/null + then + for lib in $(ldd "$bin" | sed -nre 's,.* (/.*lib.*/.*.so.*) .*,\1,p') + do + filename=$(basename "$lib") + test -e "/lib/${filename}" || cp "$lib" lib + done + fi +done + +if find . -print0 | cpio --null -ov --format=newc | xz -9 --check=crc32 > "../${out_base}.cpio.xz"; then + test -e "/boot/${out_base}.cpio.xz" && mv "/boot/${out_base}.cpio.xz" "/boot/${out_base}.cpio.xz.old" + cp "../${out_base}.cpio.xz" /boot +fi + +cd "${WORKDIR}"