Here is a briefmuch more complete guide to creating your own Odin images for distributing custom ROMs or making backups. Thanks to kam197, BH_MAN, chadmd23, SoulCreator, and all the other community members.
Requirements:
A Samsung Behold 2 to backup/edit/test ROMs on
Root via try3/asroot2, persistent su, or modified kernel
The Behold 2 has 14 partitions in its flash memory, but only a few of these are useful to modify. You will want to focus on different partitions depending on what you want to do. After you make a ROM dump you will need to package it using the instructions in the following section before you can flash it.
Backup your personal data?
You may want to backup your data while trying out a different ROM. It is simple to do.
Start an ADB shell session and obtain root access.
Run the following command to dump the UserData partition:
Don't include userdata in a distribution unless you don't mind everyone knowing your email, passwords, app choices, web history, etc!
Make a custom system image (ROM)?
Creating a custom ROM can involve no more than changing out a few included applications to modifying advanced features of the phone. A lot of testing should be performed before distributing a heavily customized system image. It is recommended to make multiple system image dumps as "in-progress" snapshots or saves as you work on the ROM. Otherwise messing up normally means starting over!
Once dumped a system ROM cannot be edited, so you must work with it directly on the phone (recommended while in Recovery Mode). The System dump will be an exact copy of what is already loaded so get everything set up first and test that the phone can reboot.
Start an ADB shell session and obtain root access.
Run the following command to dump the System partition:
Code:
# dd if=/dev/block/stl9 of=/sdcard/system bs=4096
Retrieve the dumped file from the SD Card.
If you want to get files out of another system image (or userdata image) without flashing, open them in an archive program that can read FAT disk image files - 7-Zip is recommended - or mount them read-only under Linux. Trying to write to the image with these methods will corrupt it as its non-standard.
Make a custom kernel or recovery image (ROM)?
ADVANCED: Modifying the kernel or recovery image can allow you to enable root, change startup logos, and tweak environment settings for boot. In addition to the other requirements you will need an decent understanding of Linux file permissions, startup, and mount process, as well as a hex editor
Start an ADB shell session and obtain root access.
Run the following command to dump the kernel partition:
Code:
# dd if=/dev/block/bml8 of=/sdcard/kernel bs=4096
Run the following command to dump the recovery partition:
Note: Copying, moving, and creating new files will reset the file system permissions on them. The ramdisk files must have specific permissions to work. Use ls -l to see what they start at.
Modify, add, or remove files as need. Check that permissions are appropriate - all files will be owned by root.root after the ramdisk file is remade.
Recreate the compressed ramdisk and then the kernel/recovery image with the following:
Edit the kernel/recovery image in a hex editor. Change the 4 bytes starting at offset 0x10 to be the size of the rd.cgz file in hex, little endian format. So if your compressed ramdisk size is 1647744 bytes that would be 0x192480 in hex and therefore "80 24 19 00" in little endian format.
Save the completed custom kernel/recovery image as "kernel" or "recovery".
Building the Odin Packages:
Odin technically allows you to use two types of packages - Specific and OnePackage.
Specific packages are labeled "BOOT", "PHONE", "PDA", and "CSC" in the software. Selecting these in Odin checks that they contain exactly the expected flash images and presents an error if anything is out of place (extra or missing files, mislabeled files). The CSC specific package is currently not used for the Behold 2.
Since you will rarely want to flash the entire phone at once the Specific Packages are not always appropriate. When someone else goes to flash your ROM they may get an ambiguous error and not know for sure why.
OnePackage allows any the partition flash files to be included with each other in one Odin package. These are easier to distribute and will not cause odd errors when someone loads them into Odin.
TL;DR: Use OnePackage to distribute ROMs!
Note: Errors during flashing are normally recoverable unless the error occurred while flashing the boot partitions (arm9boot and arm11boot). NEVER include these files in an Odin package - they do not need updating!
Open a Cygwin or *nix console and change directory to where you are storing your ROM dumps.
Run the following command to build a package tarball. Be sure to use identifiable names with versions or dates:
Code:
$ tar -H ustar -cimage_1 [image_2 ...]>your_odin_package.tar
Run the following command to sign each tarball with an md5 tail:
Please sign your Odin Packages - its the easiest way to tell if the download corrupted them!
Testing your Odin Packages:
Without clicking Start in Odin, load each of the packages you made to see if there are any errors. Be sure to mark the One Package checkbox under Options if you are using one.
If everything loads correctly you can test if Odin will flash them properly - click Start.
If your packages flashed correctly post them online or archive them for backup
Last edited by Nu11u5; July 23rd, 2010 at 01:19 AM.
The Following 12 Users Say Thank You to Nu11u5 For This Useful Post:
Open a Cygwin or *nix console and change directory to where you are storing your ROM dumps.
How do I open the Cygwin, when I click on the shortcut on my desktop, I get a quick command prompt, then it's gone
I've gotten the 3 dumps, and am stuck here. Any help would be appreciated.
__________________
Toast the work you use, thank those who have helped
How do I open the Cygwin, when I click on the shortcut on my desktop, I get a quick command prompt, then it's gone
I've gotten the 3 dumps, and am stuck here. Any help would be appreciated.
Cygwin is a command prompt, but instead of Windows it works like Linux.
It should not be closing as soon as it opens. Did you install to the default location or move the install folder afterward?
Im not Linux user,but computer literate and i could not even make a .tar file,lol.
tar --format=ustar -cf [name_of_odin_package.tar] [image_1] [image_2] [...]
tar --format=ustar -cf [name of .tar file} and then what? what do i put for [image_1],etc?
I succeeded creating empty .tar,could you explain this step in more detail,the rest i understand.
Can i use a program such as 7zip or Power Archiver to create the .tar file or it has to be done from linux command prompt?
Device(s): Behold 2 w/ BH_MAN Galaxy 1.6 / R7
Do Not PM me With Problem's
Post in Thread!
Thanks: 156
Thanked 1,673 Times in 433 Posts
I didn't think it was to hard to do, but here's an exp. for you...
Quote:
tar --format=ustar -cf BH_MAN_DONUT_R7.tar kernel system userdata cache
Quote:
Originally Posted by lviv73
Im not Linux user,but computer literate and i could not even make a .tar file,lol.
tar --format=ustar -cf [name_of_odin_package.tar] [image_1] [image_2] [...]
tar --format=ustar -cf [name of .tar file} and then what? what do i put for [image_1],etc?
I succeeded creating empty .tar,could you explain this step in more detail,the rest i understand.
Can i use a program such as 7zip or Power Archiver to create the .tar file or it has to be done from linux command prompt?
The Following User Says Thank You to BH_MAN For This Useful Post:
I have also noticed a cache file in you roms.This tutorial only mentions on how to dump UserData,System and Kernel.Could you give us the command to create Cache dump also.
I just thought it must be important sense you include it in your roms,thanx.
Can i use a program such as 7zip or Power Archiver to create the .tar file or it has to be done from linux command prompt?
Odin needs the tar files to be in the USTAR format. I haven't seen a free program that can write these other than the gnu linux tools - hence why I use Cygwin.
Quote:
Originally Posted by lviv73
I have also noticed a cache file in you roms.This tutorial only mentions on how to dump UserData,System and Kernel.Could you give us the command to create Cache dump also.
I just thought it must be important sense you include it in your roms,thanx.
'cache' is on /dev/block/stl12
The cache images T-Mobile provide are pretty much blank, with just a few KB of locality info on it, so I was only including copies of those.
The Following User Says Thank You to Nu11u5 For This Useful Post:
Thanx,so cache partition i can do without or is it needed for things like settings and wallpapers on first boot?
I have also tryed to dump other partitions,and noticed that almost all of them are are over 50mb,whats on them?I have made my custom rom sucessfuly,i removed alot of things i dint want,but when i flashed the rom i had double ringrltones in settings!So i did factory reset and it dint help,so i did another flash and i had triple ringtones in my settings,lol.Now after numerous flashes to stock and back they disapeared,but i dont know exactly what i did to make them disapear.
To make a long story short,is there a way to do a clean flash where everything is wiped clean?cause i noticed that even after stock flash there is still files left over on some of the partitions(18 partititions).
Device(s): Mytouch 3G Slide (Soon, Waiting on it to be shipped to me order today 6-2), Samsux Behold II
Thanks: 5
Thanked 8 Times in 6 Posts
I was wondering, If I use this method to create a backup of my phone (System, UserData and Kernel), is it possible to create an android AVD emulator and Odin the files into the emulator? I would like to do some testing, but for safety reasons...run in this mode....
Sorry if this is the wrong thread for this question, and thanks a lot guys for what you're doing here for the BH2 community!..
I tried a few different ROMs, and finally decided on using the official OTA 1.6 from this thread. Although I like the BH' mods a lot, there are a few issues with these mods that might be insignificant for some but very annoying for me...
Unfortunately, the stock ROM has a problem with wifi driver. Normally I run my home N/G router in 40MHz mode, but BH2 with the stock driver can't connect to it in this mode - I have to switch the router to 20MHz to be able to connect. This problem exists in all stock T-Mobile ROMs - the original 1.5 and the new 1.6 OTA - as well as in the tweaked 1.6 OTA by microhaxo.
However, the wifi driver used in this BH_MAN' mod doesn't have this problem - it works perfectly, and with this driver I can connect to the router even when it runs in 40MHz mode. The BH_MAN mod' change log mentions the "WiFi fix" - I assume that is what makes it to work properly?
Anyway, since the WiFi works for me in BH_MAN' mod but doesn't work in the stock ROM, my question is - is it possible to replace the wifi driver in the stock ROM by the one used in the BH_MAN's mod, and if so - how to do it? The instructions in this thread don't go that deep... I'd appreciate any help - thank you!
Updated the guide with "almost everything". I've combined and streamlined some commands, corrected some wrong descriptions from before, and added a section on making a custom kernel or recovery image.
Let me know if anything isn't clear or just doesn't work. If there is a wiki somewhere this type of thing would be appropriate for point it out.
tar --format=ustar -cf [name_of_odin_package.tar] [image_1] [image_2] [...]
Correct way *
tar -H ustar -c file_1 [file_2 ...] > tarball.tar
..is correct too. It uses the short option for --format which is -H, and leaving out -f lets you have the output file name at the end. I just thought it looked more logical.
EDIT: I saw that I did indeed have it wrong in the main post, the option -H does not take "=" as part of the argument. Fixed.
Last edited by Nu11u5; July 22nd, 2010 at 03:30 PM.
Someone can try using my kernel/recovery customization instructions to extract and rebuild the image leaving the files untouched. Let me know if its clear enough.
I'd give it a try, had some problems with the hex portion. I put that aside to work on this Dialer / contacts problem that will most likely never get solved.
I'd give it a try, had some problems with the hex portion. I put that aside to work on this Dialer / contacts problem that will most likely never get solved.
I'm working to see if I can make a shell script to handle the hex editing. Right now I can read the file size, convert that to hex, and (a few steps later) overwrite the byte range with dd. I still need to get the size into little endian format, and output that as binary instead of ASCII.
An alternative would be to make a few simple modifications to Google's mkbootfs program that would do everything for us. I think already know what needs changing, but for whatever reason I haven't done that yet.
Someone can try using my kernel/recovery customization instructions to extract and rebuild the image leaving the files untouched. Let me know if its clear enough.
I'm giving it a go but I am running into problems after splitting the kernel/recovery images.
When I run:
$ gzip -cd ../rd.cgz | cpio -imv 2> ../rd.lst
on the recovery image I get:
gzip: ../rd.cgz: not in the gzip format
also the rd.lst file in both kernel and recovery working folders contians only the following line:
bash: cpio: command not found
I'm using Cygwin to run the commands, maybe I have something configured incorrectly? Can you shed any light on the issue?
I'm giving it a go but I am running into problems after splitting the kernel/recovery images.
When I run:
$ gzip -cd ../rd.cgz | cpio -imv 2> ../rd.lst
on the recovery image I get:
gzip: ../rd.cgz: not in the gzip format
Its possible the recovery image isn't in the exact same layout as the kernel iamge. I'll confirm this and make any necessary changes to the script tomorrow.
Quote:
Originally Posted by slmar123
also the rd.lst file in both kernel and recovery working folders contians only the following line:
bash: cpio: command not found
I'm using Cygwin to run the commands, maybe I have something configured incorrectly? Can you shed any light on the issue?
You are probably missing the cpio program. Run the Cygwin installer again and when prompted to choose packages search for "cpio" and add it. It should be listed under the Archive category.
Its a shame they don't include a package manager as part of the Cygwin install. Or do they?
I've updated the script to use "find" instead of redirecting the cpio directory to the rd.lst file and reloading that. Its easier and cleaner, but there is a hitch... Windows has its own "find" program that is not compatible with the operation of GNU find. If you are not running in the default bash shell or don't have the PATH environment variable set right it'll use the wrong one and fail.
Try "$ which find" to see what ones you will be using.
Last edited by Nu11u5; July 23rd, 2010 at 01:24 AM.
I had a fresh recovery dump laying around. The ramdisk starts at offset 0x1D9000 which is different than the kernel image. I've updated the instructions to reflect that.
You are probably missing the cpio program. Run the Cygwin installer again and when prompted to choose packages search for "cpio" and add it. It should be listed under the Archive category.
Yes, "cpio" was not there. I reinstalled a bunch of packages and I finally got it .
Quote:
Try "$ which find" to see what ones you will be using.
My system is using the correct find.
I have a question on permissions. I list the files but it doesn't list "root" or "root.root" as owners. It only lists my Windows username and group as having ownership, ie: "steven" "Domain Admins". Is this ok or do I need to change something in my Cygwin profile so that I am using root?
I have a question on permissions. I list the files but it doesn't list "root" or "root.root" as owners. It only lists my Windows username and group as having ownership, ie: "steven" "Domain Admins". Is this ok or do I need to change something in my Cygwin profile so that I am using root?
Thanks
The cpio command uses "-R 0.0" which will assign root.root as owner for all files when copied into the archive.
You could chmod 0.0 * the files in the directory before if you want. You will see that you are still listed as the owner and "root" is now the group. But if you do "ls -ln" you will see the uid's and gid's are actually 0 and 0.
I guess that since Windows doesn't do ACL's the same way as Linux, nor does it have a "root" user, Cygwin will just interpret uid 0 as the current Windows user. The uid number is what matters, though.
I don't know what the uid's and gid's are for users and groups on the phone. I would keep everything as root and then change them with the init.rc on boot. Root is always '0'.
Last edited by Nu11u5; July 23rd, 2010 at 11:35 AM.
Someone can try using my kernel/recovery customization instructions to extract and rebuild the image leaving the files untouched. Let me know if its clear enough.
Ok, I have successfully rebuilt the images from my phone and downloaded them via Odin One Package. My phone boots back up but there are a few apps giving me issues. Some FC and others appear to be there but aren't installed or something. I'll have to try a few things to see if I can get them back.
I built the package using the kernel and recovery files that I extracted and then rebuilt. I also added my untouched userdata and system files that I dumped along with the others. Maybe I shouldn't have added these two and just built the package from the kernel and recovery.
Anyway I was able to follow along with the instructions but a few things were no very clear.
1. Do I need to do all of the dumps from recovery mode or should just the 'system' ROM be dumped in recovery?
2. At first I didn't realize that the instructions jumped from adb dumps to working in Cygwin/linux ie:
Run the following command to dump the recovery partition:
Code:
# dd if=/dev/block/bml6 of=/sdcard/recovery bs=4096
Retrieve the dumped file from the SD Card.
Make a copy for backup purposes! We will be editing these.
Create a working folder for each of the dumped kernel and/or recovery images and move them there.
The commands that follow are from Cygwin:
Split the images in each working folder into the binary and ramdisk.
3. I guessed and changed directories inbetween these commands:
ran from the /initramfs directory
$ find | cpio -H newc -R 0.0 -oa | gzip -cn1 > ../rd.cgz
then cd ..
$ cat rd.cgz >> krnl.bin
hopefully this was correct.
That's it, everything else seemed clear. Thanks for the information. I guess the next step will be to figure out where to customize the rom and get really dangerous.
So I ended up unable to restore the Samsung Camera and what appeared to be a corrupt /data/app directory. When I listed the directory there were some files listed but many entries with just '~'. I could not remove the directory or any files and try to restore them.
At this point I just did a Master Reset, restoring factory settings. One good thing that I learned and was surprised at, is that the reset put me back to microhaxo's 1.6 ota V2 rom along with a rooted kernel! Talk about persistent root, well done guys.
So I ended up unable to restore the Samsung Camera and what appeared to be a corrupt /data/app directory. When I listed the directory there were some files listed but many entries with just '~'. I could not remove the directory or any files and try to restore them.
At this point I just did a Master Reset, restoring factory settings. One good thing that I learned and was surprised at, is that the reset put me back to microhaxo's 1.6 ota V2 rom along with a rooted kernel! Talk about persistent root, well done guys.
Thanks for the feedback. I'll update the instructions to be more clear at those points.
As for what needs to be extracted in recovery mode..
When you make the dump you are reading out from an active device. Basically you don't want the ROM's state to change while the dump is underway.
Normally /system is read only (not so when rooted but still minimal activity here). /data will be pretty busy, though.
The best way to prevent this would be to make the ROM dump while in the simplest environment possible. You could try copying busybox into / so its loaded into the ramdisk, unmounting all the flash file systems, mount the sdcard, and do the dump then. That would be pretty thorough.
Laid out that would be:
boot into recovery
copy busybox to / or /sbin
unmount /data, /system, and /cache
mount the sdcard
busybox dd the flash block devices out to the sdcard
I hope that isn't too much. If you need help with the exact commands I can get those to you.
This means I better make "Dumping your ROMs rev2" before people start making corrupt backups...
If I just want to backup the kernel and recovery partitions without altering them, do I have to do the 'head' 'tail' stuff or can I just dump it and go.
If I just want to backup the kernel and recovery partitions without altering them, do I have to do the 'head' 'tail' stuff or can I just dump it and go.
Just the dump is sufficient. The extra stuff is if you want to modify them.
The Following User Says Thank You to Nu11u5 For This Useful Post:
The kernel and recovery dumps don't include the boot stuff do they (I don't want to backup the boot loader).
The boot process is multipart and uses 3 different partitions before loading the kernel and the Android environment. I didn't include those 3 partitions in the dump instructions because they don't ever need to be updated and it would be dangerous to try.
The kernel and recovery images only contain the kernel binary and ramdisk filesystem (and its contents) in Android format.
The kernel and recovery partitions can be backed up and reflashed without risk as the flash control software is actually in the 3rd boot partition.
If you want to modify the kernel boot parameters, init.rc script, ramdisk filesystem, or recovery tools you will want to dump kernel and/or recovery.
Last edited by Nu11u5; August 11th, 2010 at 08:33 AM.
The Following User Says Thank You to Nu11u5 For This Useful Post:
The Samsung Behold 2 for T-Mobile greatly improves on the first version of the phone by adding Android to the mix, providing for a powerful combination of hardware and sowftware. With Android, Samsung's custom TouchWiz UI, a 3.2-inch AMOLED Tou... Read More