[Samsung Galaxy Nexus] dlhxr:
Step 2: How to Modify the Kernel

There are three ways to modify the kernel.

First one is called image boot, which means we can boot just from images on our device, like system.img, data.img, cache.img.

Second one is called image folder mix boot, which means we can boot from system.img and /data/media/2nd/data, /data/media/2nd/cache folders.

Third one is called folder cache boot, which means we boot from cache partition (mmcblk0p11) and /data/media/2nd/data, /data/media/2nd/cache folders.

I recommand the image boot, because it won't have the possiblity to influence our real system.

Let's begin.

Part I: Image Boot --Booting from images.

See details in https://github.com/dlhxr/2nd-kernel-for-galaxy-nexus/tree/image_boot

An image boot kernel based on learnkernel 6.2 for 4.2

View attachment 1841614

This one is color-fixed.

View attachment 1877152

Partition relation in the kernel

system /rdata/media/rom/system.img
data /rdata/media/rom/data.img
cache /rdata/media/rom/cache.img

rdata is the original data partition /dev/block/platform/omap/omap_hsmmc.0/by-name/userdata and I mount it to /rdata instead of /data.

Modify your own kernel

After some study in xda developer Jijonhyuni’s dual boot kernel and a Chinese DHD Multi-boot thread, I managed to change the partition relation in the kernel. There are two files needing to be modified and one file need to be added.

But firstly we should unpack a compiled boot.img for the modification. Using unpackbootimg.

(

One script modified by me. View attachment 1841619

See details in extract.sh and pack_boot.sh

Remember to use chmod command to make files in tools folder executable.

chmod +x ./tools/mkbootimg ./tools/mkbootfs ./tools/unpackbootimg

)

unpackbootimg –i boot.img

You can get five files.

boot.img-base
boot.img-cmdline
boot.img-pagesize
boot.img-ramdisk.gz
boot.img-zImage

Unpack the boot.img-ramdisk.gz using

mkdir ramdisk
cd ramdisk
gzip -dc ../boot.img-ramdisk.gz | cpio –i

OK, let's add a busybox binary.

View attachment 1841620

Unzip it and copy busybox to /ramdisk/sbin/busybox.

Then modify two files in ramdisk folder, init.tuna.rc and fstab.tuna.

Find fstab.tuna and modify the system, cache and data mounting line. (Don't forget to delete the check parameter in the data mounting line!)

[COLOR="Red"]#[/COLOR]/dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 ro wait
/dev/block/platform/omap/omap_hsmmc.0/by-name/efs /factory ext4 ro wait
[COLOR="Red"]#[/COLOR]/dev/block/platform/omap/omap_hsmmc.0/by-name/cache /cache ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic wait,check
/dev/block/platform/omap/omap_hsmmc.0/by-name/userdata [COLOR="Red"]/rdata[/COLOR] ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic [COLOR="Red"]wait,encryptable[/COLOR]=/dev/block/platform/omap/omap_hsmmc.0/by-name/metadata

Then find init.tuna.rc.

The on fs part. Change it to this.

on fs
mkdir /factory 0775 radio radio
mkdir /rdata 0771 system system
mount_all /fstab.tuna
exec /sbin/busybox mount -t ext4 -o ro /rdata/media/rom/system.img /system
exec /sbin/busybox mount -t ext4 -o noatime,nosuid,nodev,nomblk_io_submit,errors=panic,rw /rdata/media/rom/data.img /data
exec /sbin/busybox mount -t ext4 -o noatime,nosuid,nodev,nomblk_io_submit,errors=panic,rw /rdata/media/rom/cache.img /cache
setprop ro.crypto.fuse_sdcard true

Modifications are done and we need to repack the kernel using following command.

mkbootfs ramdisk | gzip > ramdisk-new.gz
mkbootimg --cmdline "no_console_suspend=1 console=null " --base 0x10000000 --pagesize 2048 --kernel boot.img-zImage --ramdisk ramdisk-new.gz -o 2nd.img

The parameters like cmdline, base and pagesize can be found in the exact files boot.img-base, boot.img-cmdline, boot.img-pagesize.

If you have a serious color problem using this kernel, you need to add "mms_ts.panel_id=18" to cmdline parameter when repacking the kernel.

Put it in /data/media/boot/2nd.img.

Make some img files by dd command in Ubuntu or other linux system.

dd if=/dev/zero bs=1M count=500 >> 500.img

And then use mke2fs format the image to ext4 file system.

mke2fs –T ext4 500.img

Rename them and put them into /data/media/rom/xxx.img

View attachment 1931497 Images from 50M to 800M pre-made by me.

Part II: Image Folder Mix Boot --Booting from image and folders.

See details in https://github.com/dlhxr/2nd-kernel-for-galaxy-nexus/tree/image_folder_boot

An Image folder boot kernel based on learnkernel 6.2 for 4.2

View attachment 1841627

Partition relation in the kernel

system /rdata/media/2nd/system.img
data /rdata/media/2nd/data
cache /rdata/media/2nd/cache

rdata is the original data partition /dev/block/platform/omap/omap_hsmmc.0/by-name/userdata and I mount it to /rdata instead of /data.

Modify your own kernel

Firstly, unpack the boot.img using the method in the second post.

Find fstab.tuna and modify the system, cache and data mounting line. (Don't forget to delete the check parameter in the data mounting line!)

[COLOR="Red"]#[/COLOR]/dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 ro wait
/dev/block/platform/omap/omap_hsmmc.0/by-name/efs /factory ext4 ro wait
[COLOR="Red"]#[/COLOR]/dev/block/platform/omap/omap_hsmmc.0/by-name/cache /cache ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic wait,check
/dev/block/platform/omap/omap_hsmmc.0/by-name/userdata [COLOR="Red"]/rdata [/COLOR] ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic [COLOR="Red"]wait,encryptable[/COLOR]=/dev/block/platform/omap/omap_hsmmc.0/by-name/metadata

Then find init.tuna.rc.

The on fs part. Change it to this.

on fs
mkdir /factory 0775 radio radio
mkdir /rdata 0771 system system
mount_all /fstab.tuna
exec /sbin/busybox mount -t ext4 -o ro /rdata/media/2nd/system.img /system
mkdir /rdata/media/2nd
mkdir /rdata/media/2nd/data 0775 system system
mkdir /rdata/media/2nd/cache 0775 system cache
exec /sbin/busybox mount --bind /rdata/media/2nd/data /data
exec /sbin/busybox mount --bind /rdata/media/2nd/cache /cache
setprop ro.crypto.fuse_sdcard true

Thirdly, put busybox binary into /ramdisk/sbin/busybox

At last repack the boot.img.

You can find how to make images in Part I: Image Boot.

Part III: Folder Cache Boot

See details in https://github.com/dlhxr/2nd-kernel-for-galaxy-nexus/tree/folder_boot

I call this way to modify the kernel ----Folder Boot.

here is one folder boot kernel packed by me based on leankernel 6.2

View attachment 1841628

The partition relation in the 2nd kernel is

system /dev/block/platform/omap/omap_hsmmc.0/by-name/cache
data /rdata/media/2nd/data
cache /rdata/media/2nd/cache

rdata is the original data partition /dev/block/platform/omap/omap_hsmmc.0/by-name/userdata and I mount it to /rdata instead of /data.

There are two files needing to be modified and one file need to be added.

Unpack the boot.img.

Firstly, let's add a busybox binary.

View attachment 1841620

Unzip it and copy busybox to /ramdisk/sbin/busybox.

Then modify two files in ramdisk folder, init.tuna.rc and fstab.tuna

fstab.tuna

Change like this

/dev/block/platform/omap/omap_hsmmc.0/by-name/[B][COLOR="Red"]cache[/COLOR][/B] /system ext4 ro wait
/dev/block/platform/omap/omap_hsmmc.0/by-name/efs /factory ext4 ro wait
[B][COLOR="Red"]#[/COLOR][/B]/dev/block/platform/omap/omap_hsmmc.0/by-name/cache /cache ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic wait,check
/dev/block/platform/omap/omap_hsmmc.0/by-name/userdata /[B][COLOR="Red"]rdata[/COLOR][/B] ext4 noatime,nosuid,nodev,nomblk_io_submit,errors=panic wait,check,encryptable=/dev/block/platform/omap/omap_hsmmc.0/by-name/metadata

Init.tuna.rc

Find on fs and change like this

on fs

mkdir /factory 0775 radio radio
[B][COLOR="Red"]mkdir /rdata 0771 system system[/COLOR][/B]
mount_all /fstab.tuna
[B][COLOR="Red"]mkdir /rdata/media/2nd
mkdir /rdata/media/2nd/data 0775 system system
mkdir /rdata/media/2nd/cache 0775 system cache
exec /sbin/busybox mount --bind /rdata/media/2nd/data /data
exec /sbin/busybox mount --bind /rdata/media/2nd/cache /cache[/COLOR][/B]
setprop ro.crypto.fuse_sdcard true

Then find # virtual sdcard daemon running as media_rw (1023)

Change from

service sdcard /system/bin/sdcard /data/media /mnt/shell/emulated 1023 1023

to

service sdcard /system/bin/sdcard[B][COLOR="Red"] /rdata/media[/COLOR][/B] /mnt/shell/emulated 1023 1023

Repack the 2nd.img and put it in /data/media/boot/2nd.img.