[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#790095: lsinitramfs(8): multiple-segmented initramfs supported



Package: initramfs-tools
Version: 0.120
Severity: normal
Tags: patch

>From initramfs-tools 0.118 (Oct. 2014):
  * [d5f4cd6] lsinitramfs: Parse and list files that include early microcode.
    Thanks to Brett Parker and Olivier Berger. (Closes: #717805)

So the manpage description as the following is incorrect.
| BUGS
|        lsinitramfs  cannot deal with multiple-segmented initramfs images, such
|        as those created when an early  (uncompressed)  initramfs  with  system
|        firmware is prepended to the regular compressed initrams, or when over‐
|        lay data is appended to the initramfs.

So please knock off these lines.

In addition to this, I wonder why not offer utility to extract the
regular compressed initrams by using the same code with trivial changes.
It is pain to manually extract the new initrd image content.

I attach patch here one as example against the git master.

Hmmm...
 https://wiki.debian.org/InitramfsDebug
This needs to be updated.
>From 25dd1b58987a8b2c9b4a0edf979fc98b8a0e6a16 Mon Sep 17 00:00:00 2001
From: Osamu Aoki <osamu@debian.org>
Date: Sat, 27 Jun 2015 08:26:03 +0900
Subject: [PATCH 1/4] multi-segment initramfs supported

---
 lsinitramfs.8 | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/lsinitramfs.8 b/lsinitramfs.8
index 798aa8d..b07ddeb 100644
--- a/lsinitramfs.8
+++ b/lsinitramfs.8
@@ -36,13 +36,6 @@ List content of two initramfs files in verbose mode:
 .PP
 .B lsinitramfs -l /boot/vmlinuz-2.6.31-grml64 /boot/vmlinuz-2.6.33-grml64
 
-.SH BUGS
-.BR lsinitramfs
-cannot deal with multiple-segmented initramfs images, such as those created
-when an early (uncompressed) initramfs with system firmware is prepended to
-the regular compressed initrams, or when overlay data is appended to the
-initramfs.
-
 .SH AUTHOR
 The initramfs-tools are written by Maximilian Attems <maks@debian.org>
 and numerous others.
-- 
2.1.4

>From 8d0ad0ce10cde2d3f1c8a9013efa4f81b376d069 Mon Sep 17 00:00:00 2001
From: Osamu Aoki <osamu@debian.org>
Date: Sat, 27 Jun 2015 08:28:05 +0900
Subject: [PATCH 2/4] getinitramfs command

---
 getinitramfs | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100755 getinitramfs

diff --git a/getinitramfs b/getinitramfs
new file mode 100755
index 0000000..34eb43c
--- /dev/null
+++ b/getinitramfs
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+set -eu
+
+usage()
+{
+	echo "Usage: $(basename $0) [-l] <initramfs file>"
+}
+
+if [ "$#" -eq 0 ] ; then
+	usage >&2
+	exit 1
+fi
+
+OPTIONS=`getopt -o h --long help -n "$0" -- "$@"`
+# Check for non-GNU getopt
+if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi
+
+eval set -- "$OPTIONS"
+
+while true; do
+        case "$1" in
+        -h|--help)
+		usage
+		exit 0
+	;;
+	--)
+		shift
+		break
+	;;
+	*)
+		echo "Internal error!" >&2
+		exit 1
+	esac
+done
+
+# Read bytes out of a file, checking that they are valid hex digits
+readhex()
+{
+	dd < "$1" bs=1 skip="$2" count="$3" 2> /dev/null | \
+		LANG=C grep -E "^[0-9A-Fa-f]{$3}\$"
+}
+
+# Check for a zero byte in a file
+checkzero()
+{
+	dd < "$1" bs=1 skip="$2" count=1 2> /dev/null | \
+		LANG=C grep -q -z '^$'
+}
+
+for initramfs in "$@" ; do
+	if ! [ -r "${initramfs}" ] ; then
+		echo "Specified file could not be read." >&2
+		exit 1
+	else
+		echo "${initramfs}"
+
+		# There may be a prepended uncompressed archive.  cpio
+		# won't tell us the true size of this so we have to
+		# parse the headers and padding ourselves.  This is
+		# very roughly based on linux/lib/earlycpio.c
+		offset=0
+		while true; do
+			if checkzero "$initramfs" $offset; then
+				offset=$((offset + 4))
+				continue
+			fi
+			magic="$(readhex "$initramfs" $offset 6)" || break
+			test $magic = 070701 || test $magic = 070702 || break
+			namesize=0x$(readhex "$initramfs" $((offset + 94)) 8)
+			filesize=0x$(readhex "$initramfs" $((offset + 54)) 8)
+			offset=$(((offset + 110)))
+			offset=$(((offset + $namesize + 3) & ~3))
+			offset=$(((offset + $filesize + 3) & ~3))
+		done
+
+		if [ $offset -ne 0 ]; then
+			# Extract main archive
+			echo "Multi-segmented initramfs image: $initramfs"
+			dd < "$initramfs" bs="$offset" skip=1 2> /dev/null \
+				> $initramfs.main
+			echo " ==> Extracted main initramfs image: $initramfs.main"
+		else
+			echo "Simple initramfs image: $initramfs"
+		fi
+
+	fi
+done
-- 
2.1.4

>From 14d809dd3c432994f720c2e9267a9a87e04c6eed Mon Sep 17 00:00:00 2001
From: Osamu Aoki <osamu@debian.org>
Date: Sat, 27 Jun 2015 08:47:27 +0900
Subject: [PATCH 3/4] Add getinitramfs(8)

---
 getinitramfs.8     | 44 ++++++++++++++++++++++++++++++++++++++++++++
 lsinitramfs.8      |  1 +
 mkinitramfs.8      |  1 +
 update-initramfs.8 |  3 ++-
 4 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 getinitramfs.8

diff --git a/getinitramfs.8 b/getinitramfs.8
new file mode 100644
index 0000000..1734612
--- /dev/null
+++ b/getinitramfs.8
@@ -0,0 +1,44 @@
+.TH GETINITRAMFS 8  "2010/06/16" "Linux" "getinitramfs manual"
+
+.SH NAME
+getinitramfs \- extract the main initramfs image
+
+.SH SYNOPSIS
+.B getinitramfs
+.RI [ options ] " <initramfsfile> " [ <initramfsfile> ]
+.br
+
+.SH DESCRIPTION
+The modern multiple-segmented initramfs image consists of the early
+uncompressed initramfs containing system firmware and the compressed main
+initramfs, concatenated together.
+
+The
+.B getinitramfs
+command extracts the main initramfs image with suffix 
+.I .main
+from given initramfs images.
+
+.SH OPTIONS
+
+.TP
+.B -h
+Display usage information and exit.
+
+.SH USAGE EXAMPLES
+
+Get the main initramfs of current running kernel:
+
+.PP
+.B getinitramfs /boot/initrd.img-$(uname -r)
+
+.SH AUTHOR
+The initramfs-tools are written by Maximilian Attems <maks@debian.org>
+and numerous others.
+
+.SH SEE ALSO
+.BR
+.IR initramfs-tools (8),
+.IR mkinitramfs (8),
+.IR lsinitramfs (8),
+.IR update-initramfs (8).
diff --git a/lsinitramfs.8 b/lsinitramfs.8
index b07ddeb..226cec2 100644
--- a/lsinitramfs.8
+++ b/lsinitramfs.8
@@ -44,4 +44,5 @@ and numerous others.
 .BR
 .IR initramfs-tools (8),
 .IR mkinitramfs (8),
+.IR getinitramfs (8),
 .IR update-initramfs (8).
diff --git a/mkinitramfs.8 b/mkinitramfs.8
index 0a109f6..3bab90d 100644
--- a/mkinitramfs.8
+++ b/mkinitramfs.8
@@ -156,3 +156,4 @@ Jeff Bailey <jbailey@raspberryginger.com> and numerous others.
 .IR initramfs-tools (8),
 .IR update-initramfs (8),
 .IR lsinitramfs (8).
+.IR getinitramfs (8).
diff --git a/update-initramfs.8 b/update-initramfs.8
index 31f225d..34b2bf1 100644
--- a/update-initramfs.8
+++ b/update-initramfs.8
@@ -96,4 +96,5 @@ Jeff Bailey <jbailey@raspberryginger.com> and numerous others.
 .IR initramfs.conf (5),
 .IR initramfs-tools (8),
 .IR mkinitramfs (8),
-.IR lsinitramfs (8).
+.IR lsinitramfs (8),
+.IR getinitramfs (8).
-- 
2.1.4

>From cb921b5de0e82663176b245870beced8da02be25 Mon Sep 17 00:00:00 2001
From: Osamu Aoki <osamu@debian.org>
Date: Sat, 27 Jun 2015 08:48:55 +0900
Subject: [PATCH 4/4] update packaging for getinitramfs

---
 debian/initramfs-tools.install  | 1 +
 debian/initramfs-tools.manpages | 1 +
 2 files changed, 2 insertions(+)

diff --git a/debian/initramfs-tools.install b/debian/initramfs-tools.install
index 25d7990..160f6c6 100644
--- a/debian/initramfs-tools.install
+++ b/debian/initramfs-tools.install
@@ -1,4 +1,5 @@
 lsinitramfs		usr/bin
+getinitramfs		usr/bin
 mkinitramfs		usr/sbin
 init			usr/share/initramfs-tools
 scripts			usr/share/initramfs-tools
diff --git a/debian/initramfs-tools.manpages b/debian/initramfs-tools.manpages
index d56d0bd..57a48b1 100644
--- a/debian/initramfs-tools.manpages
+++ b/debian/initramfs-tools.manpages
@@ -1,4 +1,5 @@
 lsinitramfs.8
+getinitramfs.8
 mkinitramfs.8
 initramfs.conf.5
 initramfs-tools.8
-- 
2.1.4


Reply to: