 Okay, this is part of a series. I recommend you watch the first video in this series which is on unlocking the bootloader on the Moto G and should apply to a lot of phones out there. But once you have your bootloader unlocked, you can now start changing and modifying your boot partition or your recovery partition or your system partition. Today we're going to be looking at booting our own recovery partition. So we need an image to boot. You can create, you can compile your own or you can get one pre-made. What I'm going to do today is we're going to take one that's already made and modify it a little bit and options out there are twerp or the team win recovery and then there's also clockwork mod. We're going to be looking at the twerp today. So let's go and I googled Moto G TWRP. You can see the first two links that come up here. This one says 2013 which is the first generation. I have a second generation of the Moto G which is the 2014. So I'll click on that. Come down here to the download image to select the latest image. Here are some images you can choose. Again, be sure when you're getting an image that's someone else made that you trusted. So we're putting some faith into this project here right now because when you boot this image, it can do whatever it wants to your phone. So we'll go ahead and click to download that. I've already downloaded it and I've copied it to my working directory here and renamed it just twrp.img. Now we want to make sure whether we create an image or get an image somewhere that it really is a boot image and there's two ways to do that. You can type in file. File is a command that will tell you what type of a file any file is that it knows of. So we'll go ahead and it will check the header of that file. So file the name of the image and you can see right here it says that this is an Android boot image. It contains a kernel, a RAM disk and it even shows us some of the command line for the kernel there. If for some reason you don't have file on your system, which I think is on pretty much every Linux system, we are going to, you could also check it with if we type out the head command, which by default shows the first 10 lines of a file. We're going to say dash n1 to say just look at the first line of this file and then the name of the file. Now this is a compiled binary file so if we run this you can see right away that it says Android and it even shows us some of the similar information. We do have some of the binary data here that isn't important to us. So what we could do if we wanted to clean that up a little bit is run the strings command on that and then also pipe that into head dash n and we'll say two for the first two lines and those will only show us ASCII characters, plain text characters and right there you can see the information Android and you can see some of the boot information for the kernel there. Okay so we've confirmed that this is a bootable image for Android so let's go ahead and boot it. Now you could use, oh and by the way I've mentioned this in the last tutorial, you'll want to install these three tools, the fast boot tools, the ADB tools and a boot IMG. As I've mentioned fast boot works with the boot loader, ADB is the Android debugging bridge which allows you to log into the phone through USB or Wi-Fi if you set it up that way and then the a boot IMG allows you to extract images like the one we have right now, modify it and then recompile it into a bootable image. So install those using your package manager, here's the command if you're using aptitude on a Debian-based system let's clear that out. So now that we have the image we have those files installed let's go ahead and use fast boot to boot that image and we could use the flash command to flash it which will actually modify the hard drive on our phone it will flash the recovery but another option a little bit safer of an option especially to test it out before you flash it is the boot option. So we use sudo just to make sure we have the correct permissions to access the device the fast boot is the program we're saying we want to boot and then what image we want to boot from we'll say this and I'll hit enter it's downloading that to the phone it's booting it and if you look at the screen here you can see the Motorola logo and now you see the team win and we're in the custom recovery here for twerp and so we booted it without installing it to the phone right now it's running from RAM think of this as booting like a live CD on a desktop or laptop you have a Linux live CD you put it in it boots but it doesn't necessarily affect the hard drive on the phone and you can see all the options there that's for backing stuff up at this point you probably do want to make some backups for later on recovering in case you mess stuff up so what we can do here is do it on the phone we can also at this point sudo adb shell and now I have a root shell on that phone in the custom recovery I can list out the files on the phone and it's just a Linux shell so with root access so you can run whatever programs you want on here we can type in mount and you can see what's mounted by default you can see it mounted one of the SD cards the cache from the phone the internal SD card memory and where it's mounted all that stuff and we're going to be looking into this a little bit more later on but let's go ahead and modify that image and boot it again so let's exit out of here and for right now I'm going to run our fast boot uh boot loader so we're going to say sudo adb reboot boot loader and what that's going to do is going to reboot the phone back to the boot loader which is where we started today I showed you that in the last tutorial so once we're back there now again if I list out here the only file I have in this directory is our recovery image so what I'm going to do now is I'm going to want to extract that image so I can make differences uh differences changes to it so I'm going to make a directory I'll call it boot I'll move into the boot directory and I'm going to use the uh a boot img program to extract so dash x for extract and I'm going to say dot dot back slash and our twerp image so that's saying look at the uh directory above this directory and extract this image I'll hit enter and it says writing boot image configuration so it's creating a config file for you which we're going to modify in later tutorials it's going to extract the kernel image and the ram disk image we can list out and see all three of those files we can also see you know how big they are uh so the init rd is the initial ram disk so when you boot an image it loads the kernel and initial ram disk which is a very lightweight usually a very lightweight um file system with the tools that the kernel is going to use so that's what we want to modify here is the initial ram disk so let's make another directory call it we'll call it ram disk and then we will move into that directory and now we want to extract that ram disk image I've gone over this in previous tutorials outside of this series uh but we're going to use uh geon zip dash c because it's a compressed file dot dot back slash and we're the dot dot back slash just means look at the directory above this directory this is where that image is and we're going to extract it but we're also going to pipe it into cpio dash i and we'll hit enter and if we list out now we have the file system it looks like you know a very lightweight Linux file system which is what it is so now we can make changes to anything on here uh we can uh change the initial uh the init rc which is a script that runs at boot time we can go and add files to uh the s bin so we can have other programs on there and so let's go ahead and open this up in a file browser and look around and we have this one called res which normally stands for resources let's go and that's not normal like system let's go in there oh oh look it's got some torp stuff the torp uh xml uh we can click on that and um it opens it up uh try to open up in a web browser let me close that and actually go back to my shell here we'll move into that directory rs res and i will cat out the um ui and you can see it's an xml file um that is the recovery so when we went to the recovery and it showed all those buttons and images this is the setup for that on how that looked let's go back into here and we see all fonts and images that can be interesting we'll go in there and look at this we got a bunch of images that we can modify look here's this one called curtain dot uh jpeg we'll double click on that and we know that's the main screen that we see when it boots so i'm going to do is i'm going to open that i'm going to use gimp and i'm just going to go in here i'm going to go to hue and saturation and i'll change the hue so that it's red i'll save it back to that same file export it close out of gimp and you can see that it's been updated here it's now red so now we've made a change you can make lots of changes i just changed one image let's go ahead and re compress our image so i'm in the ram disk folder here with all our our information again if i list out the file directory above us you can see the initial ram disk and and the kernel is still there let's create a new ram disk i'm not going to overwrite the old one i'm going to create a new one and if you try to overwrite it you're going to want to delete if i try to go directly back to this img file it won't work it won't allow me to write to it we're going to want to delete it first but i'll just create a new file with a new name so what i'm going to do is i'm going to do a boot img the same program we use to extract it we're going to do dash pack uh init rd for our initial ram disk we're going to go to the directory above us and i'll just call it sorry about that camera recording the phone the battery or the card got full i also realized that um it booted back into the regular system so let's go ahead and boot into the boot loader again on that and now we're back to what we're doing sorry about that okay so what we were doing was we were using a boot img pack initial ram disk we're going to put it in the directory above us i will call it new img and what directory is all our ram disk data in it's the current directory so we'll just do dot slash we'll hit enter no error output that means that things are good we'll go up a directory we'll list and you can see we have a new img and if we list out with the sizes you can see it's it's the same size because we didn't really change anything minor changes okay so now that we have that let's go ahead and recreate our our boot image so we recreate our initial ram disk image which was part of our boot image so we're going to use a boot img again we're going to say dash dash create and we'll again create the directory above us i'll call it boot to dot img you can call it whatever you want we're going to say dash f we're going to say boot config image config that's the config file right here we didn't make any changes to it but it's holding the settings for our image what kernel do we want to to repackage we haven't made any changes so we're going to use the same kernel and then dash r we're going to use our new initial ram disk and it and it rd new img and there we go seem successful we'll go back up one directory and if we list out you can see we now have well our boot folder our new boot image and our twerp image and if we file boot to you can see that it says that it's a android boot image with a kernel and a ram disk so far everything seems good let's try booting that image so our phone is at our bootloader and we will now say um sudo fast boot and we're going to boot our boot to image and now when it goes into the recovery it's booting that image we modified so instead of a blue screen at startup we should get a red screen there we go so that is how you can make changes we change just images but you can also change um you know what happens what scripts run what programs are installed uh for the recovery image here and the great thing about this is that we can do this with android images such as the boot image not just the recovery image which is something we're going to be doing in the future as always i hope you enjoyed this tutorial maybe a little advanced uh but pretty straightforward i'll try to remember to put a link to the notes of exactly everything we just did um in the description of this video so go ahead and check that out if you enjoyed this video be sure to like subscribe share and as always i hope that you have a great day okay this is an introduction to filmsbychris.com i'm chris that's chris the k that's me right there my daughter ember and my wife jennifer we pretty much live in the swamps of florida i'm a firefighter by day as well as by night we work long hours but that's not why you're here you're here about the videos i put up on youtube these videos are mainly about computers and programming which means most of my videos look something like this and if that's what you're interested in great if not that's all right i do videos on other topics too such as video editing special effects photo editing 3d design and music creation if you are one of my viewers and you enjoy my videos my patreon page is a place where you can go to help support my videos so i asked that you take the time to go to my patreon page and look at different levels of rewards you can receive for different levels of backing there should be a link in the description of this video if you were watching it on youtube otherwise you can visit patreon.com forward slash metal x 1000 and i thank you for your time and your support have a great day