# [S]how to extract kernel by genkernel --integrated-initramfs

## FKK

with --integrated-initramfs flag, genkernel tar kernel.image and initramfs together as one file,

what's the format of this file?

I need to check some init scripts inside.

how can i extract it out?

Normal kernel bzImage extract works:

```

# file kernel 

kernel: Linux kernel x86 boot executable bzImage, version 3.10.25-gentoo (root@gentoo) #22 SMP Sat Jan 11 19:25:37 UTC 2, RO-rootFS, swap_dev 0xA, Normal VGA

# od -t x1 -A d kernel | grep "1f 8b 08" 

# dd if=kernel bs=1 skip=16492 | zcat > vmlinux

# file vmlinux 

vmlinux: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, BuildID[sha1]=dc....8c, stripped

# ls -l *

-rw-r--r-- 1 root root 10604576 Jan 11 19:49 kernel

-rw-r--r-- 1 root root 25118324 Jan 11 19:52 vmlinux

# size vmlinux 

   text    data     bss     dec     hex filename

5225740 19362152        1572864 26160756        18f2e74 vmlinux

```

but where is the initramfs ?

Question 2:

how to modify init script inside initramfs(bzImage) by genkernel?

by genkernel's  man page, there is a flag 

 *Quote:*   

>        init=<...>
> 
>            Override location of init script, default is "/sbin/init".
> 
> 

 

but in my system, this /sbin/init is a ELF bin, not shell script 

is there a location i can put my init script for genkernel ?

by gen log, i found this copy step.  but how that tmp dir made......

 *Quote:*   

> 
> 
> =================================================================
> 
> *         >> Appending auxilary cpio data...
> ...

 

I want to change these 3 scripts:

             ./etc/initrd.defaults     ./etc/initrd.scripts  ./init

----------

## szatox

Not sure if it's gonna be helpful by any means, but perhaps you can just run `genkernel --no-clean initramfs`  to make another one?

When you have initramfs decompress it and then extract with cpio. You will get another directory with little linux system inside. Change what you want and run

`find <path to directory with modified initramfs> | cpio -H newc -o | gzip -c > <path to new initramfs image file>`

you can of course use another compression tool, but gzip is fast and I had some glitch with xz. file says initramfs made by genkernel is in xz format, I can extract it with xz, but when I compress new image with xz kernel suddenly is unable to use it.

btw, don't worry, init inside initramfs IS a shell script. And it's big, but not really hard to hack if you have at least basic knowlege on bash

----------

## FKK

 *szatox wrote:*   

> Not sure if it's gonna be helpful by any means, but perhaps you can just run `genkernel --no-clean initramfs`  to make another one?
> 
> 

 

thx for reply and cmd for separate initramfs .

I'm compiling new gentoo for my unlucky box, but all fail. 

One kernel I made month ago works well, i want to look inside initramfs what's diff....

I remember i put something inside initramfs or changed the scripts, but forgot the detail ...........

----------

## frostschutz

 *FKK wrote:*   

> I need to check some init scripts inside.
> 
> how can i extract it out?

 

This may be of help: https://wiki.gentoo.org/wiki/Custom_Initramfs#Salvaging

If it's the same format you can use this method directly; if it's a different format, binwalk should still be able to point you in the right direction.

----------

## FKK

 *frostschutz wrote:*   

>  *FKK wrote:*   I need to check some init scripts inside.
> 
> how can i extract it out? 
> 
> This may be of help: https://wiki.gentoo.org/wiki/Custom_Initramfs#Salvaging
> ...

 

how can i miss this wiki !!!

watching....... ty ty

----------

## FKK

i didnt find the file i want, but this question is solved.

https://wiki.gentoo.org/wiki/Custom_Initramfs#Salvaging

----------

