This is heavily based on: 
HOWTO: Unpack, Edit, and Re-Pack Boot Images

Android Magic
.img file is special (it is not regular, it has magic), it is the image file of a particular NAND partition...

  1. Use Linux
  2. Get mkbootfs & mkbootimg
    • these are tools made when compiling Android OS source code
    • If you do not want to compile your own source code just download the binaries
    • This download link is from an XDA forum post
    • the zip has the correct binaries but they are named with "-linux-x86", feel free to rename
    • This is just to let you know it was compiled for Linux (maybe you can find one for Windows?) and x86 architecture

  3. Get split_boot.zip from HOW TO post mentioned in the beginning
  4. Grab a boot.img or recovery.img (my examples will be based on recovery) - see post #3 for grabbing these from your device
  5. Split it
    • Code:
      ./split_bootimg.pl recovery.img
    • It could tell you that there is no Android Magic... in which case this file cannot be split this way... tell us about it...

  6. Examine
    • You will have two new files based on whatever file name you gave above
    • kernel will have "-kernel"
      • YES this is the kernel (compressed) for this .img
      • you have successfully extracted the kernel
      • you cannot edit these 
      • you can mix and match 
      • if I know the kernel from older boot works I can just use it with my newly edited ramdisk 

    • ramdisk will have "-ramdisk.gz"
    • feel free to rename

  7. Unpack Ramdisk
    • Code:
      mkdir ramdisk_recovery
      cd ramdisk_recovery
      gzip -dc ../recovery.img-ramdisk.gz | cpio -i

  8. Examine
    • In all ramdisk you will have a few folders and files:
      • data
      • dev
      • etc
      • proc
      • res
        • images for recovery go here

      • sbin
        • the actually recovery binary goes here
        • also adbd

      • sys
      • system
      • tmp
      • default.prop
      • init
      • init.goldfish.rc
      • init.rc
      • init.yuhua.rc
      • init.yuhua.sh
      • initlogo.rle

    • obviously recovery and boot will be different
    • Compare stock ones with ones I edited
    • Use Beyond Compare or Meld

  9. Pack-up Ramdisk
    • Code:
      mkbootfs ./ramdisk_recovery | gzip > ramdisk_recovery-edited.gz

  10. Back to IMG
    • Code:
      mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel recovery.img-kernel --ramdisk ramdisk_recovery-edited.gz -o recovery-edited.img
    • use file good file names! Or you might end up with many test tries and cannot figure out what you did for each
    • Here you can mix and match kernels

  11. Now Flash via recovery or something
    • Only mess with boot or recovery if you break both you will have a bricked device