Editing the initrd (ramdisk)? - Vibrant Q&A, Help & Troubleshooting

Anyone know how to do that and bundle it back up into a zImage we can flash on the Vibrant/Galaxy S? HTC's boot.img was reasonably simple to mod, but I haven't found any good data on re-assembling the zImage Samsung uses. I have been able to extract the initrd, but nothing on putting it back together.
I'd prefer not to completely build the kernel, as I'd like to keep using JACs and he hasn't posted the source. And I'd have to build the cross-compiler as well, time consuming.

Irritating, the Samsung kernel source build works but doesn't do this bit either. No initrd... grrrr...

No doubt there is a way to reverse-engineer the way the kernel and ramdisk is put together, but it's way beyond my capability at the moment. With that said, if we can take it apart, we can probably put it back together.

i too am looking for instructions how to repack and/or split this

Jr33 said:
i too am looking for instructions how to repack and/or split this
Click to expand...
Click to collapse
Here's how you pull the initrd out from a Vibrant image, well, JAC OCv4 anyway.. Based on a thread and script in the international Galaxy S forum. I still don't know how to re-assemble it, but Wes put some stuff in git that might help, I'm still building after a repo sync. After you run the script with the zImage as the only parameter, you should get an initrd directory with the extracted contents of the ramdisk.
Code:
#!/bin/sh
zImage=$1
#=======================================================
# find start of gziped kernel object in the zImage file:
#=======================================================
pos=`grep -a -b --only-matching $'\x1F\x8B\x08' $zImage | cut -f 1 -d :`
echo "-I- Extracting kernel image from $zImage (start = $pos)"
# dd if=$zImage bs=1 skip=$pos | gunzip > kernel.img
#===========================================================================
# find start and end of the "cpio" initramfs image inside the kernel object:
# ASCII cpio header starts with '070701'
# The end of the cpio archive is marked with an empty file named TRAILER!!!
#===========================================================================
search=`perl -e'print "\x1F\x8B\x08"'`
start=`grep -a -b --only-matching $search kernel.img | head -1 | cut -f 1 -d :`
echo "-I- Extracting initramfs image from kernel.img (start = $start, end = $end)"
dd if=kernel.img bs=1 skip=$start | gzip -d -c > initramfs.img
mkdir initrd
cd initrd
cpio -i --no-absolute-filenames < ../initramfs.img

Related

extracting initramfs from zImage

I *think* I got this to work, but someone with less n00b should verify.
Code:
'find your header
grep -a -b --only-matching $'\x1f\x8b\x08\x00' < zImage
'use your header value
dd bs=1 if=zImage skip={your number} | gzip -d -c > initramfs.cpio
'extract
sudo cpio -i --no-absolute-filenames < ../initramfs.cpio
I did compile this into a new zImage, but it made no difference, still looping samsungs..
This method (not mine) also works, but generates a file list. You should be able cpio out the files with minor adjustments.. credit to skeeterslint for this.
Code:
grep -a -b --only-matching `perl -e'print "\x1F\x8B\x08"'` zImage
dd if=zImage bs=1 skip=#fromsteponehere | gunzip > Image
grep -a -b --only-matching `perl -e'print "\x1F\x8B\x08"'` Image
dd if=Image bs=1 skip=#fromstep3goeshere | gzip -d -c | cpio -t

[Q] USB HOST support SiyahKernel 3.0beta6

Dear Friends,
I have been building custom USB devices for Android as a hobby during my spare time since the end of last year. I have been succesfully using until now Siyah kernel V2.5.2-VWM + Android 2.3.5 in order to test my hardware prototypes with my SGS2. This version of Siyah kernel was compiled with some flags (CONFIG_SEC_WHITELIST=n) that disabled a white-list placed by Samsung that prevented third-party USB devices from connecting to the phone.
I updated yesterday to Siyah-v3.0b6 and CM9 and found that my USB devices are not working (OTG devices like my USB memory stick still works). I tracked the problem using the "lsusb" terminal command and the "USB Device Info" app, and I found that my devices are not enumerated correctly anymore. This is a symptom that the Samsung white-list is enabled and it is filtering USB devices that are not found in the list.
I may be wrong, but I think the workaround is only in the compilation flag above described. Does anyone of you people know of any kernel supporting ICS that is working with custom USB devices, or HID devices (joysticks, keyboards, mouse, gamepads, etc)?
I dont have enough credits to post this in the developer Forum so that Gokhanmoral can receive this feedback. I hope he may eventually read this post.
Thanks in advance for your help,
Saul
Did you try Beta 5? I had problems with Beta 6, I could not access the phone via adb or see any of the drives on my PC via MTP. Maybe there are general USB problems in that version. Going back to Beta 5 solved it.
rovo89 said:
Did you try Beta 5? I had problems with Beta 6, I could not access the phone via adb or see any of the drives on my PC via MTP. Maybe there are general USB problems in that version. Going back to Beta 5 solved it.
Click to expand...
Click to collapse
Thanks a lot for the suggestion. I am digging on this issue and found that it is more related to a compilation flag of the new kernel for ICS.
regards,
Saul
USB Host support for custom devices
Hello Saul,
I am experiencing a similar problem with my custom USB device. I have a rooted Samsung Galaxy S2 (GT-I9100) with android 4.0.3.
Did you manage to complie a kernel that works? I downloaded the GT-I9200_ICS_Opensource_Update4.zip kernel source files from opensource.samsung.com but I am not able to compile it. I got the error:
Code:
drivers/media/video/samsung/mali/linux/mali_osk_mali.c:23:98: error: arch/config.h: No such file or directory
Any ideas or guidance would be greatly appreciated.
Model: GT-I9100
Android version: 4.0.3
Baseband: I9100BULP6
Kernel: [email protected]#3
Compilation: IML74K.BULPC
Hi Saul and everybody,
I figured out what the problem was; this is just in case it's useful to someone.
It seems the "make clean" and "make mrproper" routines in the Makefile created by Samsund does not work properley and you need to unzip the entire source code again and restart the proces from scratch every time you want to change the .config and re-compile.
Afterwards, I also noticed the image won't work because I needed to exctract an initramfs for my device and to link it to the new kernel during the kernel compilation process and setting the CONFIG_INITRAMFS_SOURCE .config parameter pointing to the location where it was extracted.
In order to extract my initramfs, I applied the following script (which is an adaptation I made to this one http://forum.xda-developers.com/wiki/Extract_initramfs_from_zImage) to a zImage kernel included in a stockrom that worked fine in my device:
Code:
#!/bin/bash
#
#Source: http://forum.xda-developers.com/wiki/Extract_initramfs_from_zImage
#
#Extract initramfs from zImage
#
#initramfs provides the rootfs when booting a Linux kernel on a mobile device.
#Below script may be helpful if you are interested in extracting such an image from a zImage kernel file.
#Tested on Ubuntu for Samsung Galaxy S firmware. Other zImages may have different archiving options - would require a #modification to the script...
#
#After extracting the initramfs, it can be unpacked into the local directory with
#
#cpio -v -i --no-absolute-filenames < <path-to-initramfs.img>
#
zImage=$1
#========================================================
# find start of gziped kernel object in the zImage file:
#========================================================
#
# Next two lines modified by Federico Linares
#
p1=`perl -e 'print "\x1F\x8B\x08"'` # Added by Federico Liares
pos=`grep -P -a -b --only-matching $p1 $zImage | cut -f 1 -d :` # Modified by Federico Linares
echo "-I- Extracting kernel image from $zImage (start = $pos)"
#========================================================================
# the cpio archive might be gzipped too, so two gunzips could be needed:
#========================================================================
dd if=$zImage bs=1 skip=$pos | gunzip > /tmp/kernel.img
pos=`grep -P -a -b -m 1 --only-matching $'\x1F\x8B\x08' /tmp/kernel.img | cut -f 1 -d :`
#===========================================================================
# find start and end of the "cpio" initramfs image inside the kernel object:
# ASCII cpio header starts with '070701'
# The end of the cpio archive is marked with an empty file named TRAILER!!!
#===========================================================================
if [ ! $pos = "" ]; then
echo "-I- Extracting compressed cpio image from kernel image (start = $pos)"
dd if=/tmp/kernel.img bs=1 skip=$pos | gunzip > /tmp/cpio.img
start=`grep -a -b -m 1 --only-matching '070701' /tmp/cpio.img | head -1 | cut -f 1 -d :`
end=`grep -a -b -m 1 --only-matching 'TRAILER!!!' /tmp/cpio.img | head -1 | cut -f 1 -d :`
inputfile=/tmp/cpio.img
else
echo "-I- Already uncompressed cpio.img, not decompressing"
start=`grep -a -b -m 1 --only-matching '070701' /tmp/kernel.img | head -1 | cut -f 1 -d :`
end=`grep -a -b -m 1 --only-matching 'TRAILER!!!' /tmp/kernel.img | head -1 | cut -f 1 -d :`
inputfile=/tmp/kernel.img
fi
# 11 bytes = length of TRAILER!!! zero terminated string, fixes premature end of file warning in CPIO
end=$((end + 11))
count=$((end - start))
if (($count < 0)); then
echo "-E- Couldn't match start/end of the initramfs image."
exit
fi
echo "-I- Extracting initramfs image from $inputfile (start = $start, end = $end)"
dd if=$inputfile bs=1 skip=$start count=$count > initramfs.cpio
And that's almost all. At this point everything works fine except the Wifi. I think I have to link it to the kernel as a module, but I am not sure where to get the module from.
Any help would be greatly appreciated.
______________________________
Device: GT-I9100
Android version: 4.0.3
Baseband: I9100BULP6
Kernel: 3.0.15-I9100G
Compilation: IML74K.BULPC

[Q]How to Unpack/Split Samsung boot.img ?

Maybe a noob question, but how do you guys split and repack SGS3 boot.img ?
The usual perl scripts don't seem to work with any S3 boot.img I came across (neither for the Galaxy Tab 7.7 boot.img's btw).
I keep getting this error :
Android Magic not found in boot.img. Giving Up.
Click to expand...
Click to collapse
Thanks for answering.
To unpack, you can do this:
Code:
abootimg -x boot.img && mkdir newramdisk && cd newramdisk && zcat ../initrd.img | cpio -i --no-absolute-filenames
Of course, that assumes you have abootimg installed. The above will split the zImage and the ramdisk from the boot.img and then proceed to extract the files from the ramdisk. Some ramdisks are not Gzip compressed so in that case use cat instead of zcat. Also: run that as root to make sure you don't mangle the files' permissions. I haven't tried repacking, though. ("find . -print | cpio -o -H newc | gzip > ../initrd.img" followed by "cd .. ; abootimg -u boot.img -r initrd.img" worked for my U8800pro, but I've had no need to try it with GS3 images.) I'd start by looking at the tools that come with the official Samsung source distribution and guides that tell you how to build a Samsung kernel.
Thanks a lot for this thorough answer
Trying this right now.
Couldn't find a specific Samsung kernel-related tutorial, though good idea to go take a look at Samsung's official kernel documentation.
qwerty12 said:
To unpack, you can do this:
Code:
abootimg -x boot.img && mkdir newramdisk && cd newramdisk && zcat ../initrd.img | cpio -i --no-absolute-filenames
Of course, that assumes you have abootimg installed. The above will split the zImage and the ramdisk from the boot.img and then proceed to extract the files from the ramdisk. Some ramdisks are not Gzip compressed so in that case use cat instead of zcat. Also: run that as root to make sure you don't mangle the files' permissions. I haven't tried repacking, though. ("find . -print | cpio -o -H newc | gzip > ../initrd.img" followed by "cd .. ; abootimg -u boot.img -r initrd.img" worked for my U8800pro, but I've had no need to try it with GS3 images.) I'd start by looking at the tools that come with the official Samsung source distribution and guides that tell you how to build a Samsung kernel.
Click to expand...
Click to collapse
Great!! Thanks for your information.
Here is what I use. Inside there are three binaries and two perl scripts,, copy the binaries into /usr/bin/ or you can add them in their own place and add that to the path. Then use this to help you use the files
Thanks for that too, ima try those scripts
Getting this error :
~$ perl unpack-bootimg.pl boot.img
could not find any embeded ramdisk images. Are you sure this is a full boot image?
Click to expand...
Click to collapse
Apparently, from what I have been reading, Samsung uses a different type of kernels than other manufacturers.
Although there's a huge number of custom samsung kernels out there. There might be a way^^
Here is the kernel i'm trying to edit if anyone wanna give a try at unpacking it for me.
That is true up until the S3 boot.img/kernel They have always used a zImage. Now Google has forced them to move over to EXT4 system and change the kernel format.
That file is only 2.88 mb's that is way too small to be a full kernel. Even for stock with no tweaks. That's why you are having an error.
This is the original boot.img from the CM9 for Galaxy Tab 7.7 update.zip
However i get the same error when trying to unpack S3 stock boot.img or even CM10 boot.img, although when i try the same scripts on my Xperia Play's kernels they unpack properly.
Good thing if Google made Samsung do kernels like others
Hi,
Did you manage to unpack/repack the SGS3 boot image? I'm trying to modify init.rc in an international SGS3 (i9300).
I've managed to unpack the boot image (from /dev/block/mmcblk0p5) as per qwerty12's command but how do I repack it?
Thanks!

[Q] Help with boot image unpack/repack please.

I've read several tutorials both here and elsewhere. I've got a few different methods down using mkbootimg, unpackbootimg, abootimg, the perl scripts, and I have gzip/gunzip/cpio commands down. Splitting and repacking go without errors.
However, I cannot, to save my life, whether I modify something or not, get a boot image that I split and repacked to boot on my device.
I have a G4 H811 the T-Mobile variant. I have been playing with boot images and kernels included with ROMs and a custom kernel, even dd'd the working boot partition from my device. I simply cannot repack something that boots.
Here's an example approach, here I'm using binaries from a custom kernel zip mkbootimg, unpackbootimg, and the busybox included in the zip. I'm doing exactly what the kernel maintainer does to split the image, replace zImage and repack, only manually in a terminal and modifying the ramdisk leaving everything else alone.
mkdir boot
cd boot/
cat /dev/block/bootdevice/by-name/boot >boot.img
chmod 755 busybox
chmod 755 mkbootimg
chmod 755 unpackbootimg
./unpackbootimg -i boot.img
mkdir initrd
cd initrd
cat ../boot.img-ramdisk.gz | ../busybox gunzip | ../busybox cpio -vid
vi init.rc(made changes)
../busybox find . | ../busybox cpio -o -H newc | ../busybox gzip >../myinitrd.img
cd ..
./mkbootimg --kernel boot.img-zImage --ramdisk myinitrd.img --cmdline "$(cat boot.img-cmdline)" --base 0x$(cat boot.img-base) --pagesize 4096 --ramdisk_offset $(cat boot.img-ramdiskoffset) --tags_offset $(cat boot.img-tagsoffset) --output myboot.img
./busybox dd if=myboot.img of=/dev/block/bootdevice/by-name/boot
I end up with with a 26.8MB myboot.img and a bootloop
Here's a really good example, I changed absolutely nothing. After unpacking and repacking I end up with two different size boot images. What am I missing here?

[S905] WeTek Hub Boot Image Modification

I recently got my hands on a WeTek Hub. All round quite a nice little box, but the default lowmemorykiller settings are a little annoying, and sometimes result in the boot failing because the kernel decided to kill one of the startup processes. I'm trying to modify the settings in the init.rc, but I'm having a spot of trouble with a boot loop after repacking the boot image.
I copied the image off the device by using dd to extract the partition to a file, and then used the built-in FTP server to copy it off the device, and extracted it using unmkbootimg. after unzipping, extracting, modifying, and re-packing, I used mkbootimg to recreate the image, and dd'd it back onto the box (commands below).
Code:
dd if=/dev/block/boot of=/sdcard/boot.img
Code:
./unmkbootimg boot.img
mv initrd.img{,.gz}
gunzip initrd.img.gz
mkdir initrd
cp initrd.img initrd
cd initrd
cpio -i < initrd.img
rm initrd.img
# change stuff here
find . | cpio -o -H newc > ../initrd.cpio
cd ..
gzip initrd.cpio
./mkbootimg --kernel kernel.gz --ramdisk initrd.img.gz -o new_boot.img
Code:
dd if=/sdcard/new_boot.img of=/dev/block/boot
Unfortunately, that left me with a flashing WeTek logo as the it continuously rebooted. examining the logs from u-boot didn't give anything useful, but luckily I was able to get it into recovery and flash Ricardo's Android TV ROM back on there. Unfortunately, I'm still stuck with the original boot failure issue. Any clues as to what I've missed?
I do so
Code:
cd boot
../mkboot boot.img unpaсk
cd unpack/ramdisk
find . | cpio -o -H newc | gzip > ../ramdisk.packed
[I][B]# (edit size ramdisk in /boot/unpack/img_info file)[/B][/I]
cd ../..
../mkboot unpack boot.img
all is working

Categories

Resources