2010年11月20日 星期六

[Android] Modify ramdisk.img on Android

ramdisk.img
A small partition image with gzipped cpio archive that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature.

system.img
A partition image that will be mounted as /system and thus contains all system binaries

userdata.img
A partition image that can be mounted as /data and thus contains all application-specific and user-specific data.

Here is the steps:
1.Change directory to whatever/path
$ cd whatever/path
2.Copy the original ramdisk.img
$ cp /path/to/ramdisk.img .
3.Create a temporary folder, say ramdisk-ext
$ mkdir ramdisk-ext
4.Change directory to ramdisk-ext
$ cd ramdisk-ext
5.Extract the ramdisk.cpio in the ramdisk-ext folder
$ gunzip -dcv ../ramdisk.img | cpio -idm
6.Check out the directories in ramdisk.img
$ ls
data          dev   init.goldfish.rc  proc  sys
default.prop  init  init.rc           sbin  system
7.Do some modifications
$ touch foo
$ mkdir bar
8.Recreate the ramdisk.cpio
$ find . | cpio -H newc -o | gzip -9 >../ramdisk.img
9.Start the emulator
$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img
10.Check out the directories in the emulator
$ adb shell ls -l
drwxrwxrwt root     root              2010-11-26 16:54 sqlite_stmt_journals
drwxrwx--- system   cache             2010-11-26 16:54 cache
d--------- system   system            2010-11-26 16:54 sdcard
lrwxrwxrwx root     root              2010-11-26 16:54 etc -> /system/etc
drwxr-xr-x root     root              2010-11-15 07:33 system
drwxr-xr-x system   system            2010-11-26 16:53 bar
drwxr-x--- system   system            2010-11-26 16:52 sbin
-rwxr-x--- system   system       1677 1970-01-01 00:00 init.goldfish.rc
dr-xr-xr-x root     root              1970-01-01 00:00 proc
-rw-r--r-- system   system          0 2010-11-26 16:52 foo
-rwxr-x--- system   system     106696 1970-01-01 00:00 init
-rwxr-x--- system   system      10700 1970-01-01 00:00 init.rc
drwxr-xr-x root     root              1970-01-01 00:00 sys
-rw-r--r-- system   system        118 1970-01-01 00:00 default.prop
drwxrwx--x system   system            2010-11-16 09:04 data
drwx------ root     root              2009-08-07 03:35 root
drwxr-xr-x root     root              2010-11-26 16:54 dev

gunzip options:
-c, --stdout      write on standard output, keep original files unchanged
-d, --decompress  decompress
-v, --verbose     verbose mode
-1, --fast        compress faster
-9, --best        compress better

cpio options:
-i, --extract                    Extract files from an archive (run in copy-in mode)
-d, --make-directories           Create leading directories where needed
-m, --preserve-modification-time Retain previous file modification times when creating files
-H, --format=FORMAT              Use given archive FORMAT
-c                               Use the old portable (ASCII) archive format
-o, --create                     Create the archive (run in copy-out mode)
-v, --verbose                    Verbosely list the files processed
-B                               Set the I/O block size to 5120 bytes
-u, --unconditional              Replace all files unconditionally

Examples:
  cpio -covB  > [file|device]<== Backup
  cpio -icduv < [file|device]<== Restore

"-H newc" use the new (SVR4) portable format. If you wish the old portable (ASCII) archive format, use "-H odc" instead. 

reference:
* Android ramdisk.img system.img userdata.img
* android ramdisk的壓縮與解壓縮

沒有留言: