From 3ea5d2e28fe0e5790594d036c430dbad4e903186 Mon Sep 17 00:00:00 2001
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Tue, 10 Jan 2012 22:45:45 +0800
Subject: [PATCH] lsinitrd: add '-s' option to sort the initrd output by file
size
This is useful to analyse which files consume the space of initrd.
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
lsinitrd | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/lsinitrd b/lsinitrd
index 7da9f61..ad7ece9 100755
--- a/lsinitrd
+++ b/lsinitrd
@@ -19,7 +19,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-[[ $# -le 2 ]] || { echo "Usage: $(basename $0) [<initramfs file> [<filename>]]" ; exit 1 ; }
+[[ $# -le 2 ]] || { echo "Usage: $(basename $0) [-s] [<initramfs file> [<filename>]]" ; exit 1 ; }
+
+sorted=0
+while getopts "s" opt; do
+ case $opt in
+ s) sorted=1;;
+ \?) exit 1;;
+ esac
+done
+shift $((OPTIND-1))
+
image="${1:-/boot/initramfs-$(uname -r).img}"
[[ -f "$image" ]] || { echo "$image does not exist" ; exit 1 ; }
@@ -45,5 +55,9 @@ echo "$image: $(du -h $image | awk '{print $1}')"
echo "========================================================================"
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout 'lib/dracut/dracut-*' 2>/dev/null
echo "========================================================================"
-$CAT "$image" | cpio --extract --verbose --quiet --list
+if [ "$sorted" -eq 1 ]; then
+ $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
+else
+ $CAT "$image" | cpio --extract --verbose --quiet --list
+fi
echo "========================================================================"