Basics of the Linux Boot Process

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the goal of this video lecture is to give you a general idea of what happens from the time you push the power button on your computer up until the time you get a Linux login prompt in the terminal and this is really meant to be kind of a high-level overview of this process by the end of this there is no expectation that you'll be an expert but hopefully you'll have a better general idea of how this process works and you'll have some good jumping-off points to explore this process in more detail so let's talk about the general overflow or the general overview of this entire process you're gonna press the power button on your computer at the time you press this power button your computer's BIOS is going to go through a hardware check and it's going to make sure that everything is okay next up it's going to go ahead and launch a small piece of software called the bootloader which is located in a special location on your computer's hard disk and the boot loaders job is to go ahead and look in other parts of the hard disk and try to find an operating system kernel to boot and again this is a fairly complex process but the bootloader stages job is really just to go ahead and get a kernel up and running and in our case that'll be the Linux kernel the kernel does all types of initializations the kernel handles remember inner basically all the communications between it basically understands how to work with the hardware right so there's drivers that know how to talk to various parts of the hardware the motherboard expansion cards that are in there deal with memory allocation and knows how to manage a CPU resource allocation so again the kernel really is that low-level worker for your Linux environment once the kernel gets itself up and configured and the way that it's happy and it's ready to go it will launch a process called init or a similar process which handles all of the user space configurations and this is really where the system gets ready for the user everything from the bios the bootloader and the kernel is really to get the computer ready for the computers own sake and that initialization process is really the first time where you're going to start to see the computer start to set itself up for the user and once all of those initialization processes are completed and there are many of them depending on your system and what you've got configured at some point you will end up with a login prompt after the hardware has been configured and all of the services that are necessary to get your user space up and running and configured and finally you get a login prompt again this is a fairly complex process but one of the cool things about this process and Linux is you have the ability at every step of the phase to intervene and customize and see and learn exactly how everything works so again not to make you an expert in this process but let's talk a little bit about how some of these things are relevant and and some terminologies and one of the things that'll be unique in this discussion is I'll be using Ubuntu for the sample system but what I'm mostly going to talk about is the kind of the classic init process for Linux because it's the one I'm most familiar with but I will also mention one - uses a special process for getting user space configured called upstart so I'll also mention kind of how the classical UNIX boot initialization process maps to upstart which I'm not an expert in but I can kind of tell you how it maps and again I'm a little old-school when it comes to this stuff but that's ok when it comes to running UNIX so all this stuff happens what can we find some information about this well there are boot logs and all the stuff that would normally scroll by on your computer screen when you boot a computer could be found in your boot logs and you will without doubt find your logs on your hard drive and a directory called slash var slash log and in there you will be able to see a log called DM ESG and the D message log is going to contain all of your boot commands there's also a command that you can run called D message that'll just dump that log to the command line so either way you can run D message or you can go dig into the VAR log system and take a look so we'll jump over there now and take a peek so my prompt I'm gonna go to the VAR log directory and do an LS you'll see that there's a number of logs in this directory the one I'm most interested in is the D message log and this contains information from my boot you'll also notice there's some older D message logs so these are archived logs and if I were to look at this I could just cat this or look at it using less or I could use the D message command so I'm just if I run D message from the prompt it just dumps that file to the to the screen and you see a lot of stuff but that's not really useful so what I'll do is I'll run D message and pipe it through less so we can kind of walk through this and as you kind of look through this you'll see that these are all basically the bhoot messages as your system comes online it's a cool file to look at because you can kind of see how it starts to initialize all of your hardware information about your hardware is contained in here you'll see things like if you're during the boot process bad memory is found or other really you know kind of subtle errors well that could be a big error but any type of errors that might occur during the boot process as well a lot of stuff you know is indecipherable to most people or might not be of interest to you but can be helpful when troubleshooting certain hardware issues so along with this process of once we say we hit power then we you know the BIOS checks the hardware and then the bootloader is then called upon to go find a kernel and load the kernel the message is going to give you what's happening during that kernel initialization process whenever you're using a computer you can think of that computer having multiple capabilities to be in states of various levels of functionality which is just a fancy way to saying sometimes you want to have a lot of services up and running and other times you want to have less services up and running and in a Windows environment this is most often seen when you say boot into recovery mode which is a very limited state of the operating system in other words it's you know only allows a single user networking is probably not enabled a lot of drivers are disabled and you can go in and kind of troubleshoot the system and linux has this idea as well and in the classic sense we call these run levels and run levels define a specific you know level of functionality that a computer is in or has at any given time over the years this has been redefined in many cases and you know it you'll have to check your distribution and in newer systems that use the upstart process there's really not there's there's there's still a sense of runlevels because there's still a lot of backwards compatibility but this concept of runlevel seems to be like it's it's something that might be going away slowly as the as we creep into the future but anyway let's talk about the idea of run levels so UNIX says this idea where you can be in single user mode which is a really basic recovery mode so if you're having your computer constantly crashes as it tries to load a driver or if you think you've think there's been infiltrated you know in some case or been compromised you know you might want to boot into a single user mode where no one else can login and you can perform maintenance tasks so run level one is usually single user mode under the bun two system you're kind of basic Rhuddlan system is going to be run level two and this is kind of running with a GUI and you've got multiple people that can log in and this is pretty much as normal usage on RedHat systems and other systems that might also be run level 5 so notice that even in this case you kind of get the same type of run level between 2 & 5 depending on the distribution that you're using run level 3 is the usually be full multi-user with no x windows up and running or no GUI so that'll just be a straightforward that's pretty typical for server environments so pretty standard run level if you don't use it GUI 4 is undefined you could go ahead and define your own run level it's kind of one available and six is reboot your computer has a configuration file to dictate what the default run level is and if you want to be really mean to somebody you can set their default long run level to 6 so then every time they log into their computer it reboots these are like kind of fun little standard UNIX tricks that everybody pulls on other UNIX users don't do that but anyway these are the different states and run levels that your computer can be in and we'll take a look in a bit when we jump over the command line to see how one can set what the default run level is and where you can find these things and what run level you're currently in there's a couple different ways to boot into single user mode single user mode being again that kind of recovery mode equivalent to Windows and the best and easiest way to do this is on a reboot when you are presented with your basically the logo of your Linux distribution will often be a command at the bottom of the screen that you know says press escape or press a certain key to interact with the boot sequence you might get a menu you might not and in the case of a bun to a bun to uses grub to is its bootloader and you could actually interact with the bootloader I'd say at that point and select an option to boot into single user mode if that option is not available there's also ways within boot loaders to get a limited command prompt that allows you to pass in some boot parameters as well again not really trying to talk about specifics on how you would do this but the idea being that the bootloader stage once you hit the buy it power button the bias does its check and starts the bootloader process many boot loaders will present you with a menu that allows you to select an option to go ahead and boot into various user modes or various different kernels if you have multiple kernels and installed so just know that there is some flexibility in the bootloader phase that can allow you to just like in Windows select different levels so before we look at this let's talk a little about about this idea of run levels you can change from one run level to another and you will notice that you can use the command in it or telling it to do that so if I wanted to switch from run level 2 to run level 3 I would type and knit 3 and if I wanted to go to run level 1 I would type in it 1 and these are you know pretty standard commands so a probably will not run these in the video lecture but and it can allow you while you are logged in and have root privileges to change a machine's active run level and on more classic systems that don't use the upstart process you can change the default run level of the system in a file called slash edge / @ c / init tab on a bun - based systems you would be able to change the default run level in a file called slash @ c / init /r c - isn't it tough and if you ever want to see your current run level you have the ability to run the command called run level so let's take a look at a few of these things on the command prompt so one of the things we can do is see what current run level our machine is in and if I use the command run level it will tell me that my machine is currently running in run level 2 and because of 1/2 is based on Debian that makes sense because I've got a full graphical user environment up and running I've got full networking full multi-user environment so that is in line with what I said before that Ubuntu systems would have run level 2 as their full GUI multi-user run level where as say a different distribution might use run level 5 so again everything's distribution versus distribution specific we can use the init command if I wanted to along with sudo to switch my run level and I'm not actually gonna execute this because it caused a problem last time I tried it and so but the really nice thing is you can have coming back to this idea with UNIX that you don't always need to restart the computer or take it down you can actually just change run levels and change functionality right within the system so if for some reason you would need to do some system maintenance you could you know make sure that all you get all the users logged off of the system and without rebooting into you could just reinitialize or rien it in to run level 1 and in run level 1 you know you there were nobody else will be able to log in you could do your do your work and then you could knit back into run level 2 and you should be back up and running depending on what you did and again the reason why me and knitting tool run level 1 here might not work is is possibly you know my being new and not having a full understanding of the upstart process used in a Bunter so again there's a different way to really start and stop functionality using the Ubuntu upstart process and definitely Google abun to an upstart and run levels and you'll get some really good information on that so again kind of looking at the classical approach here so we can take a look at where this default run level is set and that default run limo is gonna be in Etsy and it if we look in this directory an Etsy in it there's gonna be a bunch of stuff in here the one we want to look at is our CC isn't it and so I'm gonna take a look at that file and I will yes RC yes sis in it and you will notice that in this file this is where you can find the default run level for the system so again back to just being mean to people if you change that to six your computer will infinitely reboot if for whatever reason you decide to have a different run level you don't want your computer to have a full GUI every type of boot just want to go straight into the terminal you could change your default run level to 3 which should give you a formal to user environment without the graphical user environment again your mileage may vary on that but you could give it a shot so how our run levels managed run levels are managed a couple different ways based upon the system that you're using in the classic and NIT process all of your enabled functionality in a given run level is dictated by a series of scripts that are stored in a directory or series of directories in the slash et Cie directory and these are our CD directories and we'll take a look at those in a second on the command line and essentially the way this works in the classic init process is that you just have a series of scripts in a folder and there are a number of folders that represent different run levels and those run levels are linked back to the main scripts and those scripts are the links to those scripts have names that either start with an S or a K a script that starts with a capital letter s start to process a script with a capital letter K kills a process and then finally each of these scripts will be followed by a number and a name and the number dictates the order in which those scripts are executed so you can change the order in which scripts are started and the order in which they're killed in case you have scripts that depend on other scripts being up and running as you go and we'll take a look at that it's a pretty simple process in terms of its design it's pretty elegant and simple but it is the classic approach and what you'll notice is that even in an upstart based system like a bun to this naming convention is still utilized because it's backwards compatible and again I think everybody's just used to the classic way of doing things but what you'll note is that upstart again even though it looks like the classic init process because of backwards compatibility issues and supporting lots of different services that are expecting that process we can look at and find upstart specific scripts in the Etsy / init directory and there are some specific files related to the upstart process they're specific like upstart so just like these S&K scripts are going to be compatible with the old-school anit process upstart has its own way of having its own customized services being defined and also which of those services should be enabled or disabled based upon a given run level and again that's not really something I want to discuss specifically in this class we'll kind of look at the classic scripts because that's what I understand the most but the reality being that you know depending on what your distribution is it may or may not use upstart so just a couple of different options the real key here is to know that run levels how do things get put and made available in a given run level there's just a script run you say run run level three and a bunch of scripts and a folder get run to enable or disable the services that are supposed to be on or off at that run level it's not well it is a super complex process in the sense that there's a lot of stuff going on the the basic theory of what's happening is not really all that difficult so let's explore this some of these directories on the command line so if I go into my Etsy directory and take a look around you'll notice that there's going to be a number of directories in this directory called various things and here's a bunch of RC directories called RC zero dot d through RC 6d and these directories are corresponding to various run levels on the system and again this is all for backwards compatibility with the traditional init process so at run level - all the things that get started and stopped we could expect to find scripts in there let's take a look at that directory let's pull that up top so we can zoom in a little bit and so what you'll notice is there's a couple of scripts in this directory and all of the items in this directory will be started because they start with the letter S and the order in which these items will be started is dictated by the number after the letter s so Colonel loops get started first and then speech dispatcher and then V box ad and so forth all the way up through the higher numbers again if you wanted to have your own scripts execute at start time for this run level you would just name them using this convention and drop them in here one of the things that's important to notice though is if we look at what's actually happening these are all links and you will notice that all of these links that use the traditional init process naming convention link back to the D directory which is more of the way that upstart handles things today so you're still seeing this transition and again like I said it's a little confusing even to me because I'm so used to the old way of doing it anyway this is why stuff gets started and stopped at a given time when a different run level is executed and notice by the way that this isn't everything that happens at a given run level these are some of the items so again the other process is that that are running on your system could be executed at any time in that brew process and you know we could look through and see what all of these do are see local good place to put some local scripts or some stuff that you want executed or you could write transcripts up to you anyway that's the general idea of how run levels work and how your computer kind of gets up into a runnable state and how you have the ability to enable or disable functionality to give it run level just an overview and also give you some ideas of the way it was done and the way it's being done in the future and again this is totally not enough information for you to go out and administer a system but hopefully it's enough information to give you a general idea what happens when your computer boots and hopefully that can interest you to go learn some more
Info
Channel: Jason Wertz
Views: 105,242
Rating: 4.9031944 out of 5
Keywords:
Id: yeMA7AJFtb8
Channel Id: undefined
Length: 19min 58sec (1198 seconds)
Published: Fri Dec 06 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.