Android - How To Unpack - Pack Factory Images
Android - How To Unpack - Pack Factory Images
Android:HowtoUnpack/PackFactoryImages
HomeTechAndroidAndroid:HowtoUnpack/PackFactoryImages
Android:HowtoUnpack/PackFactory
Images
4
Thisentrywaspostedin Android
TableofContents
boot.imgandrecovery.img
Unpack
Pack
system.img,userdata.img,cache.img,etc.
Unpack
Pack
AtypicalAndroidfactorypackagecontainsseveralimagefiles,suchassystem.img,cache.img,
userdata.img,boot.img,recovery.img,etc.Althoughallthesefilescontainstheimgintheirnames,they
arenotallofthesameformat.
Accordingtomyexperience,therearetwofileformatforthesefiles.
boot.imgandrecovery.img
Unpack
ThesefilesarepackedtoaAndroidbootimageformat,ifyouusefilecommandtoseetheirtype,the
commandwilltellyouthatitisadatafile.
fileboot.img
#boot.img:data
ifyouuseinspectintothefilescontent,youwillseeANDROIDintheverybeginning.
headn1recovery.img
#ANDROID!H=aY(6GGBXH=KERNEL
http://rexshen.net/androidunpackpackfactoryimages/
1/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
Howtounpackthesefiles?IfyouareusingUbuntu(orotherLinuxdistributions,Ibelieve),thereisahandy
tool:abootimg,itcancreateorextractsuchkindofimagesforyou.Simplytypethefollowingcommandto
install:
sudoaptgetinstallabootimg
Nowyouhaveabootimginstalledinyoursystem,youcaneasilyextractboot.img:
mkdirboot
cdboot
abootimgx../boot.img
#afterthesuccessfulexecutionofthelastcommand,wewillhaveinitrd.img,zImage,
etc.
#insidethebootfolder.
Sometimesweneedtochangetheinitramfs(packedininitrd.img),thenweneedtounpacktheinitrd.img.
Firstofall,weneedtomakesuretheinitrd.img(somevendormightaddawrapperheadertotheoriginal
image):
fileinitrd.img
BeautyofLife,BeautyofCS
#theoutputshouldbesimilartothefollowingline:
#initrd.img:gzipcompresseddata,fromUnix
Nowweknowtheinitrd.imgisagzipfile,wecanunpackitusegunzip(gzipd)combinedwithcpio:
mkdirramdisk
cdramdisk
#"gunzipc../initrd.img"meansunpacktostandardoutput
gunzipc../initrd.img|cpioi
Thatall,youcandigintotheramdiskfoldernow^_^.
Oh,forgottotellyou,theabootimgunpackinitrdalongwithabootimgpackagedothesamethingforyou
andcansaveyoufromtypingalotofcommand^)^.
abootimgunpackinitrdinitrd.img
#thiscommandwillcreatearamdiskfolderautomaticallyand
#unpacktheimagetotheramdiskfolder
Pack
initrd.img
http://rexshen.net/androidunpackpackfactoryimages/
2/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
Toreversetheunpackaction,abootimgpackageprovidesanothercommandnamedabootimgpack
initrd,hereisitsusage:
abootimgpackinitrd[f][initrdimg_path][ramdisk_folder_path]
#f:forcewrite.ifyouwouldliketousethisflag,makesuretoplaceitasth
efirstargument
#initrdig_path:thepathofthetargetinitrd.imgfile
#ramdisk_folder_path:theramdiskfolderpath
boot.img/recovery.img
Togenerateaboot.imgorrecovery.img,again,weneedtheabootimgtool.
#tocreateanimage:
abootimgcreate<bootimg>[c"param=value"][f<bootimg.cfg>]k<kernel>r
<ramdisk>[s<secondstage>]
#toupdateanexistingimage:
abootimgu<bootimg>[c"param=value"][f<bootimg.cfg>][k<kernel>][r<ram
disk>][s<secondstage>]
#Note:theoption"r<ramdisk>",whereramdiskisinitrd.img,nottheramdiskfo
lder.
system.img,userdata.img,cache.img,etc.
Unpack
Distinguishfrombootimage,imagessuchassystem.imgiscalleduserimageinAndroid.Earlyversionof
Android(previoustoAndroid2.3Gingerbread)useyaffs2asitsfilesystem,anduseext4asitfilesystem
fromGingerbread(readthisposttogetsomedetailabouttheswitch:Ext4filesystemhitsAndroid,noneed
tofeardataloss).
Todecidewhatformatisyourimage,wecanmakeuseofthefilecommand:
filesystem.img
#iftheiamgeisayaffs2image,theoutputmightlooklike:
#system.img:VMSAlphaExectutable
#iftheimageisaext4image,theoutputmightbe:
#system.img:data
Ifyourimageisayaffs2image,youcanusetheyaffs2utilstoolstounpackorpacktheimage.Iwontdig
intothedetailofyaffs2imagebecauseIhaveverylimitedexperienceonit.
http://rexshen.net/androidunpackpackfactoryimages/
3/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
Nowyouhaveasystem.imgthatitstypeisdata,howcanyouknowwhetheritisaext4image?Android
provideatoolnamedsimg2img(whichmeans:sparseimagetoimage)todothejob.Wecangetthesource
codeofsimg2imgintheAOSP(AndroidOpenSourceProject),insidethesystem/extras/ext4_utils/folder.
ReadthisforaninstructiontocompileitwithoutcompilingthewholeAOSP:Howtopackandunpack
system.imganduserdata.imgfromanAndroidfactoryimage.
Onceyouhavesimg2imginstalled,youcansimplytypethiscommandintheterminal:
simg2imgsystem.imgsystem.ext4.img
Ifthecommanddidntyieldanyerror,congratulation!Doublecheckwiththefilecommand:
filesystem.ext4.img
#shouldoutputsomethinglike:
#system.ext4.img:Linuxrev1.0ext4filesystemdata,UUID=57f8f4bcabf40000675f946
fc0f9f25b(extents)(largefiles)
Mounttheimageusingthis:
sudomounttext4oloopsystem.ext4.img/mnt
#makesureyouhavetheprivilege(sudoorroot)tomounttheimage
Dowhateveryouwanttothefilesunder/mnt(themountpoint),andallyourmodificationwillbesavedwhen
youumounttheimage.
Pack
Whenwedonewiththemodifications,wemaywanttorepackthesystemimage(noteIwonttouchthetopic
thathowtocreateayaffs2imagehere).Inthatcase,weneedanothertools:make_ext4fsand
mkuserimg.sh,thesourcecodeofthesetoolsalsoinsystem/extra/ext4_utils/,youcanfollowthe
instructionsinHowtopackandunpacksystem.imganduserdata.imgfromanAndroidfactoryimageto
compilethemake_ext4fs.Themkuserimg.shisawrapperprogramthatitwillcallmake_ext4fseventually.
http://rexshen.net/androidunpackpackfactoryimages/
4/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
mkuserimg.sh
#Usage:
#mkuserimg.sh[s]SRC_DIROUTPUT_FILEEXT_VARIANTMOUNT_POINTSIZE
#Example:
sudomkuserimg.shssystem/system.imgext4/system500m
#ths"s"flagindicatesthatwewanttogenerateasparseimage,otherwiseitwillge
ngerate
#amimagethatwecanmountitdirectlywithoutusingsimg2img.
#thefirst"system/"isthesystemfolder(forexample,themountpointofthesystem.e
xt4.img)
#thesecond"/system"specifythemountpointinsideAndriodsystem.
#thelastargument(500m)specifytheimagesize.whenmountedinthetargetAndroidsy
stem,the
#actualpartitionsizewouldbe10m(approximately)lessthanthissize.theimagesize
must
#conformtothepartitionsizedefinedinMBRorEBR,orsomeimagedatamightbeover
ridedby
#subsequentimage.
Author:RexShen
Created:20140924Wed14:06
Emacs24.3.1(Orgmode8.2.7c)
Validate
Leaveacomment
Youremailaddresswillnotbepublished.Requiredfieldsaremarked*
Name*
Email*
Website
Comment
http://rexshen.net/androidunpackpackfactoryimages/
5/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
YoumayusetheseHTMLtagsandattributes: <ahref=""title=""><abbrtitle=""><acronymtitle="">
<b><blockquotecite=""><cite><code><deldatetime=""><em><i><qcite=""><s><strike><strong>
PostComment
4thoughtsonAndroid:HowtoUnpack/Pack
FactoryImages
Viranjan
Reply
April1,2015at10:19pm
Nicearticletounderstandaboutboot.img,system.imgetc.
Canyoupleaseaddsomeknowledgeaboutvendor.imgandcache.imgaswell.
Thereisjustamentionofit.
Thanks.
Rex
Postauthor
Reply
April8,2015at6:44am
Viranjan,
vendorspecificfilesusuallyresidein/system/vendor,ratherthanastandalone
partition.Anyway,ifthereisavendor.img,thefilestructureinsidethepartitionmaybesimilarto
system.img.
cache.imgusuallyanemptyimage(withonlyfilesystemdata).Androidusesuchemptyimagesto
initialisethepartitions,soAndroiddonottocallmkfs.ext4toformatsuchpartitions.Someusage
ofthe/cachepartitionare:
1)whenwedownloadfromGooglePlay,thefilesarestoredin/cachetemporarily
2)thedownloadedotapackage(update.zip)issavedin/cache
3)whendoinganotaupdate,thelogfilesthataregeneratedbyrecoveryaresavedin
/cache/recovery
4)storesomebackupdata
http://rexshen.net/androidunpackpackfactoryimages/
6/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
Aamir
Reply
July9,2015at7:48pm
howdoiunmountthatmntfolderaftermodificatoin.plzhelp
andotherproblemisthatmysystemsaysaboutmkuserimg.shthatcommandnot
found.helpplzimwaiting
Rex
Reply
Postauthor
July11,2015at9:22am
Aamir,
1)tounmount,youcansimplyrunthiscommand:sudoumount/mnt.note
thatthecommandisumountratherthanunmount
2)youcangetacopyofmkuserimg.shfromtheAndroidssourcecode:system/extra/ext4_utils/
Postnavigation
UnderstandingMTKsMBR/EBRFileFormat
CustomizeandFlashMT6589ROM
Searchfor:
Search
Categories
InsightsonLife(1)
[]Tech(34)
Android(6)
Editors(5)
NodeJS(3)
[]Travelling(3)
[]China(3)
EastChina(1)
Northeast(2)
RecentPosts
AnWorkaroundforsslwrapProbleminevent
PortAndroidtoNVIDIAJetsonTK1
CustomizeandFlashMT6589ROM
Android:HowtoUnpack/PackFactoryImages
http://rexshen.net/androidunpackpackfactoryimages/
7/8
7/16/2015
Android:HowtoUnpack/PackFactoryImages
UnderstandingMTKsMBR/EBRFileFormat
RecentComments
RexonPortAndroidtoNVIDIAJetsonTK1
RexonAndroid:HowtoUnpack/PackFactoryImages
AamironAndroid:HowtoUnpack/PackFactoryImages
GregonPortAndroidtoNVIDIAJetsonTK1
RexonUnderstandingMTKsMBR/EBRFileFormat
Tags
algorithm
androidC/C++cedetclangclangcompleteclassdell1420nemacsFightingflycheckfstabgccgnome
googlehostshtmlIceandSnowWorldindentionkde
kubuntulinkerlinuxmakefilemountnodejsNortheastosxpptp
pthreadrootscreenscreenshotsizeofsmarthostsstackoverflowStartupterminalthunderbirdttyS
ubuntuunittestunityvpn
wirelessdriver
2015BeautyofLife,BeautyofCSDesignedbyPressCustomizr
Backtotop
http://rexshen.net/androidunpackpackfactoryimages/
8/8