summaryrefslogtreecommitdiff
path: root/lsinitrd.sh
diff options
context:
space:
mode:
authorHarald Hoyer <harald@redhat.com>2013-03-07 12:54:02 +0100
committerHarald Hoyer <harald@redhat.com>2013-03-07 13:03:24 +0100
commitdde2db3da9d265bc5aba17e1137139f19126ae0e (patch)
treeef389d0c0639248f2d720c7f42f9dce2fe3d5dd9 /lsinitrd.sh
parentcbc21754e537f2f3a3ef9c346f8a2bf0432ee218 (diff)
downloaddracut-dde2db3da9d265bc5aba17e1137139f19126ae0e.tar.gz
dracut-dde2db3da9d265bc5aba17e1137139f19126ae0e.tar.bz2
dracut-dde2db3da9d265bc5aba17e1137139f19126ae0e.zip
lsinitrd: use /boot/<machine-id>/<kernel-version>/initrd as the default image
if /boot/<machine-id> exists; then use /boot/<machine-id>/<kernel-version>/initrd as the default image; else fallback to /boot/initramfs-<kernel-version>.img
Diffstat (limited to 'lsinitrd.sh')
-rwxr-xr-xlsinitrd.sh40
1 files changed, 37 insertions, 3 deletions
diff --git a/lsinitrd.sh b/lsinitrd.sh
index 77a15c5f..7a09423f 100755
--- a/lsinitrd.sh
+++ b/lsinitrd.sh
@@ -21,7 +21,13 @@
usage()
{
- echo "Usage: $(${0##*/}) [-s] [<initramfs file> [<filename>]]"
+ {
+ echo "Usage: ${0##*/} [-s] [<initramfs file> [<filename>]]"
+ 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 <initramfs file> specified and the default image '$image' cannot be accessed!"
+ echo
+ } >&2
+ usage
+ exit 1
+fi
CAT=zcat
FILE_T=$(file --dereference "$image")