]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
lsinitrd: add '-s' option to sort the initrd output by file size
authorCong Wang <xiyou.wangcong@gmail.com>
Tue, 10 Jan 2012 14:45:45 +0000 (22:45 +0800)
committerHarald Hoyer <harald@redhat.com>
Mon, 23 Jan 2012 09:00:43 +0000 (10:00 +0100)
This is useful to analyse which files consume the space of initrd.

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
lsinitrd

index 7da9f612004c6b777f46b76f251de7c6261818c5..ad7ece9f493d86d7d9d8590bb464fdddb62a0f27 100755 (executable)
--- a/lsinitrd
+++ b/lsinitrd
 # 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 "========================================================================"