Chroot is a Linux command that changes a directory to become the new root directory, creating an isolated environment where users cannot access directories above it or external programs; this feature is widely used in mobile operating systems like Android and Linux phones as a lightweight alternative to virtual machines, offering minimal overhead while providing directory-level isolation for running applications safely.
Understanding Chroot in Linux: A Comprehensive Tutorial
Added:in this tutorial we will talk about an advanced linux topic called chroot so get your brains ready for something a little bit more challenging and it's coming up next so welcome to episode 2 in simplified terms each a root is a command to change a particular directory to be the new root directory so once you're inside the two rooted space you can't access any directory above it this also locks you out from access to any programs aside this space since there will be no way to reference an external directory so in general a 2 root is a directory Jail for those of you thinking you have no use for something that's complicated it is more important to understand the concept because as it turns out each root is a frequently used alternative to a virtual machine and it's used extensively in all phone operating systems including Android and Linux so if you understand this you will get a feel of how a Linux Phone OS like and about the touch or post-market OS is made you will also grasp a little bit of the difference between each root and a virtual machine just so you understand a basic complication here if you're trying to access Linux on a pint phone or a nexus 5 once you SSH into the device you're actually being directed to eight rooted space or jail this means you can't see everything but this concept makes you understand what you're looking at when you examine the contents of a phone OS so in this video we're going to do an exercise in implementing a to root in a very simple way you can practice with this simple exercise then hopefully a light bulb will turn on in your head I've watched many videos explaining to root and most are just a little bit vague for me I hope I do a better job here ok first I'm gonna make a directory called jail and then we're gonna use the command to route jail and see what happens the director is empty without any commands in it it will try to launch bash but since it is completely empty it will fail as you can see here so in order to run something inside the jail we need to duplicate some Linux programs in it this can be from any distro that's compatible with whatever kernel you are using currently meaning the distress to be made also for your current processor you can't mix x86 and arm for example for this video we're just going to copy something from a bun to 18.04 which is the platform I'm on right now if you have a live CD of any other distro you could copy the file from that distro into the truth and you will see how it works my goal here is just make sure I can run the bash shell so to do this I will copy over the bin directory to the truth now that isn't enough because there will be some dependencies for bash to run so I will also have to copy the live directory and the live 64 directories so let me do that first let me make the directories in the jail bin live and live 64 I'm going to copy the files from the route to the jail now let's check to see if a dead copy looks like it's good there are files in each one so it looks like we've duplicated Anna Bunty Bionic install in here it's a mini installation of Ubuntu since we only have programs from bin now let's see what happens when we chew out this first let me start outside of jail sudo Carruth Jill it worked you know this because the prompt will change to say bash and the version of bash will appear 4.4 in this case once you're inside the jail you have no access to anything else but what's in the jail so you can see this is also useful in putting apps in a separate container since they can't cause damage outside of the directory by the way Windows doesn't have a true so this could be a new concept to you if you're coming from windows I can only run programs available inside jail so let's look at the bin directory to see what I can run and you can see here these are the only programs I can run for example I can run echo since this isn't the list of programs on there I can't run ifconfig it's not an accessible program now you might ask how a host OS my a bun to 18.04 here can give some selected access to system resources those can actually be done by doing something called a mount bind which we will not demonstrate here but just explaining it in theory so there's a way to pass resources from external to the truth into the truth so that's an example of how a bunt to 16.4 gives access to system resources to about to touch for example something I was trying to explain in the exploring a bunt to touch video now to take this to another level let's execute a program automatically in the truth when we launch it this is again similar to a host system running another version of Linux automatically to do this I will make a bash script that will just display a message so I'm going to use Nano here and the file we're gonna make is test dot SH and I'm gonna type in echo this is a test script which is executed into root space you now after I save the file I'm gonna change the permissions and add execution permissions to test dot Sh now I will exit the chroot bash shell by typing exit same thing is when you launch any bash shell then the chroot returns to the host OS so we're gonna test us now sudo to root Jail and then we're gonna execute test dot Sh you can see now that it executed the script immediately and to return to the hosts since there was nothing else to do in the case of a punt - 1604 running a bunt to touch as an example the truth never comes back in a typical Linux distro you start a Linux distro by executing a spin in it and that's what would have happened here if we wanted to pass control to another district completely hopefully that didn't scare you too much again think of the big picture here instead of focusing and applying this directly if you could see how this is commonly used you won't be intimidated by phone OS people that talk to roots all day now what's different between each root and a virtual machine some virtual machines like lxd are very close to it - root but let's say you're familiar with a virtual machine like VirtualBox our VMware and some of this which you may be running on Windows the difference is that a VirtualBox emulates a processor in the case of its route it is assumed to be using the same processor and in fact the same identical kernel a virtual machine has more isolation some virtual machines like coamo actually emulate a different processor a chroot has very little overheads in since it's just running inside the same space as to host a virtual machine has to translate everything back to the host CPU from the virtual machine CPU so overhead is expected in my exploring about the touch video I show that about two 16.04 actually launches Ubuntu touch in its root then a bunt the touch launches an android instance called Hal iam a sub virtual machine using something called lxd so you can see now an application of chaining two routes and virtual machines in Ubuntu touch Linux can be quite powerful for doing complex things like this very simply I hope you enjoy this lesson and subscribe to this channel to see more and thank you for watching [Music]
Up Next

Creating and Using a Chroot Jail in Ubuntu Linux | Part 2
@OneByteAtATime7
13.8K views•2010-12-23

Introduction to Secure Multiparty Computation with Yehuda Lindell
@fhe_org
7.7K views•2021-02-04

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science






































