mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Campbell <ijc@hellion.org.uk>
To: Willy Tarreau <w@1wt.eu>
Cc: Martin Schlemmer <Martin.Schlemmer@nwu.ac.za>,
	linux-kernel@vger.kernel.org
Subject: Re: Initramfs from existing vmlinuz
Date: Mon, 05 Jan 2009 11:12:26 +0000	[thread overview]
Message-ID: <1231153946.2648.49.camel@zakaz.uk.xensource.com> (raw)
In-Reply-To: <20081223233410.GC6800@1wt.eu>

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

On Wed, 2008-12-24 at 00:34 +0100, Willy Tarreau wrote:
> You first have to extract and uncompress the ELF image from vmlinuz.
> For this, look for the gzip signature 1F 8B 08 in your vmlinuz, and
> feed all data starting from this point to zcat.

Since v2.6.26 (I think, it was v2.08 of the x86 bzImage format anyhow,
which was the same point the payload became ELF formatted) you can find
it directly using the payload_offset and payload_length fields in the
bzImage header. Attached bzexplode.c demonstrates this. e.g. "bzexplode
vmlinuz | zcat > vmlinux.elf"

Ian.

-- 
Ian Campbell
Current Noise: Electric Wizard - Saturn's Children

A likely impossibility is always preferable to an unconvincing possibility.
		-- Aristotle

[-- Attachment #2: bzexplode.c --]
[-- Type: text/x-csrc, Size: 1251 bytes --]

#include <stdio.h>
#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>

#include <inttypes.h>

#include <err.h>

#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
	int fd;
	struct stat sb;
	void *p;
	uint8_t *hdr;
	int setup_sectors;
	uint32_t compressed_payload_offset;
	uint32_t compressed_payload_length;

	if (argc != 2)
		errx(1, "usage: bzexplode <bzImage>");

	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		err(1, "open");

	if (fstat(fd, &sb) < 0)
		err(1, "fstat");

	p = mmap(0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
	if (p == MAP_FAILED)
		err(1, "mmap");

	hdr = p;
	setup_sectors = hdr[0x1f1];
	compressed_payload_offset = *(uint32_t*)&hdr[0x248];

	fprintf(stderr, "setup sectors %d\n", setup_sectors);

	compressed_payload_offset += (setup_sectors+1) * 512;

	//compressed_payload_length = *(uint32_t*)(p + compressed_payload_offset - 4);
	compressed_payload_length = *(uint32_t*)&hdr[0x24c];

	fprintf(stderr, "compressed_payload_offset %"PRIx32" (abs)\n",
		compressed_payload_offset);
	fprintf(stderr, "compressed_payload_length %"PRIx32"\n",
		compressed_payload_length);

	write(1,
	      p + compressed_payload_offset,
	      compressed_payload_length);
	return 0;
}

  parent reply	other threads:[~2009-01-05 11:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-23 22:28 Martin Schlemmer
2008-12-23 23:34 ` Willy Tarreau
2008-12-24 11:37   ` Martin Schlemmer
2008-12-25 17:55     ` Martin Schlemmer
2008-12-25 18:17     ` Initramfs from existing vmlinuz (#2) Martin Schlemmer
2009-01-05 11:12   ` Ian Campbell [this message]
2009-01-05 11:47     ` Initramfs from existing vmlinuz Willy Tarreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1231153946.2648.49.camel@zakaz.uk.xensource.com \
    --to=ijc@hellion.org.uk \
    --cc=Martin.Schlemmer@nwu.ac.za \
    --cc=linux-kernel@vger.kernel.org \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®