From dde2db3da9d265bc5aba17e1137139f19126ae0e Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 7 Mar 2013 12:54:02 +0100 Subject: [PATCH] lsinitrd: use /boot///initrd as the default image if /boot/ exists; then use /boot///initrd as the default image; else fallback to /boot/initramfs-.img --- lsinitrd.1.asc | 5 +++-- lsinitrd.sh | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lsinitrd.1.asc b/lsinitrd.1.asc index 5b0c62e..fd98161 100644 --- a/lsinitrd.1.asc +++ b/lsinitrd.1.asc @@ -10,12 +10,13 @@ lsinitrd - tool to show the contents of an initramfs image SYNOPSIS -------- -*lsinit* ['OPTION...'] [] +*lsinitrd* ['OPTION...'] [] DESCRIPTION ----------- lsinitrd shows the contents of an initramfs image. if is omitted, then -lsinitrd uses the default image /boot/initramfs-.img. +lsinitrd uses the default image _/boot///initrd_ or +_/boot/initramfs-.img_. OPTIONS ------- diff --git a/lsinitrd.sh b/lsinitrd.sh index 77a15c5..7a09423 100755 --- a/lsinitrd.sh +++ b/lsinitrd.sh @@ -21,7 +21,13 @@ usage() { - echo "Usage: $(${0##*/}) [-s] [ []]" + { + echo "Usage: ${0##*/} [-s] [ []]" + echo + echo "-h, --help print a help message and exit." + echo "-s, --size sort the contents of the initramfs by size." + echo + } >&2 } [[ $# -le 2 ]] || { usage ; exit 1 ; } @@ -36,8 +42,36 @@ while getopts "s" opt; do done shift $((OPTIND-1)) -image="${1:-/boot/initramfs-$(uname -r).img}" -[[ -f "$image" ]] || { echo "$image does not exist" ; exit 1 ; } +KERNEL_VERSION="$(uname -r)" + +if [[ "$1" ]]; then + image="$1" + if ! [[ -f "$image" ]]; then + { + echo "$image does not exist" + echo + } >&2 + usage + exit 1 + fi +fi + +[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id + +if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then + image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd" +else + image="/boot/initramfs-${KERNEL_VERSION}.img}" +fi + +if ! [[ -f "$image" ]]; then + { + echo "No specified and the default image '$image' cannot be accessed!" + echo + } >&2 + usage + exit 1 +fi CAT=zcat FILE_T=$(file --dereference "$image") -- 2.7.4