Hey guys and welcome back. So previously we had talked about kernel configuration options,
now what I want to transition into is talking about how we can actually compile a kernel,
i.e. what this means and how we would actually do such a thing and then after that talk about
kernel installation. So we have a lot of cool content within this nugget right here, how
about we dig in and get to go in then shall we? So the first thing I want to talk to you
about is really to answer a question and that is why in earth would you want to do such
a thing? Why would you want to install a custom kernel? Well the reality is if you happen
to be running some type of distribution such as Ubuntu or maybe some type of red hat distribution,
the reality that you would want to install a custom kernel, well the probability of such
a thing is quite low. That just is the general facts of the matter but however if you happen
to be using something that is maybe a little bit more limited in its power, something like
maybe say a raspberry pi. Well a raspberry pi as you know can be a very very small device
with limited power, this could be a perfect example whereby you want to have a kernel
that is much leaner and a kernel which is much less demanding on the physical resources
and in this type of case being able to compile and install a custom kernel may be the actual
solution that you need and moreover it certainly is the thing that we have to understand for
the purposes of the LPIC2 examination. So even if you might think well you know what
I might not necessarily have a use case or a need to be able to compile and install a
brand new custom kernel, point is is that we do have to understand this so let's waste
no time and talk about what this actually entails then. Now to be honest the idea of
compiling a kernel and installing a brand new one, it can kind of be a little bit scary
and to be honest so much of what this entails all the different options and parameters that we
have available with respect to compilation and installation is way beyond the scope of the LPIC2
examination so what I'm saying here is is that you don't have to be too stressed out trying to
learn all the little details here, what we want to understand is a high level overview and understand
some of the main commands that we would use to do such a thing, having an encyclopedic knowledge
and familiarity with the process is really not so necessary. So listen in with a keen ear to the
process but don't be too stressed about or too overwhelmed by the process. Now in order to begin
the first thing that we have to do is to download some kernel source code so where in earth would
I be able to get such a thing? Well I'm glad you asked, there actually is a dedicated website
that we can get this information and that is at kernel.org once we go to this website we're going
to see a whole bunch of different kernel images that we can get all these different versions that
we talked about when we talked about the versioning numbers, we can choose the version we want,
download that and use it to compile our kernel and then to install that kernel. So the first thing
that we should do is to go to this website and we will actually download some kernel source code then
so what I'll do is I'll go to my machine and open up my browser. Okay so where we want to go to is
kernel.org if we search for this or rather go to this we can see here we have our latest release here
version 5 17 7 but we also have these different versions available to us but for now all I'm going
to do is to get this latest release so I'll click on this image here or this link here should I say
and the download should begin. Now this should only take a few minutes and as we can see here
the download has completed just about and perfect so what I can do now if I just close this down
I can open up the terminal again I'll change to the root user and it would help if I would type in
the correct password this time okay so I'm in the directory for ipv0 I should go into my download
folder where this download should actually be here now we can actually see here this has something
called xz compression this is a more modern type of compression we actually discussed this when
we talked about the lpik one exam and we ultimately want to extract the files that have been compressed
now there are some caveats I want to talk to you about first the command I want to use to extract
is going to be the tar command now in order to be able to extract this type of compression the xz
compression the option I'm going to use is going to be dash j now notice this is going to be a
capital j it's not going to be a lowercase capital j is what we need and if I happen to just in fact
let me show you go into man page for the tar and I scroll down for a little bit we can see dash
lowercase j will actually allow us to extract bzip to compression but we notice it is .xz in my case
so be careful when it's .xz we're using dash capital j so that means we can filter the archive
through xz so if I press q to quit we have that knowledge in mind now the next thing that we have
to understand is that there actually is a pretty desirable in fact certainly strongly recommended
location to where we should actually unpack this kernel now try to remember this location this location
is going to be in the forward slash user directory and then forward slash src this is where you want
to place your source code so think about this if I go to this location I go cd I go into user
src if I do an ls we can see here we have a whole bunch of different kernels here what I now want
to do is to extract this download right here using the tar command and extract into this location so
we will have another folder just like all these folders here but this time the folder will be
linux 5 17.7 so let's actually walk through this process then so what I will do is I will say tar
and I will say dash j to run the xz compression and I'm going to say xvf to extract the files
verbosely so they print out on the screen and now I have to specify what it is I want to extract
well I want to extract this file right here but I can't just specify the name of the file because
the location of where I am in the directory and the directory tree is in user source so I'm going
to give the entire path which in my case is home ipv0 downloads but of course this will be different
for you so pretty much just put in the path where the download resides I'll go into my downloads
folder and then linux 15 17 7 tar dot xz and because I am issuing the tar command from within
this folder right here user src it's going to extract it into this folder which is exactly what
I want this is the location I want to extract the source code so if I hit enter now we can see the
extraction happen okay so that is now finished again if I do a pwd we can see my current working
directory and now if I do an ls-l we can see we have this additional folder linux 5 17 7 now what
I want to do here is I actually want to create a symbolic link pointing to this particular
directory here and I want to make the symbolic link called linux so I'll do ln-s to create this
symbolic link and then I'll specify the name of the folder which is this one here and I will
give the sim link the name linux that means if I do an ls-l now we can actually see we have a
symbolic link called linux pointing to this folder so therefore if I go into cd linux within here we
have all of this information now one thing I want to point to you and this is important for the
purposes of the examination is whereabouts we can find our documentation we can see here we have
this directory here called documentation with a capital D if I go in here and I do an ls right
now so this really is a path you want to remember user src linux documentation and within here we
can find documentation doing things like explaining the actual modules at play here now at this stage
what I want to do is to install some particular packages I'm going to install make something
called gcc as well as libn curses 5-dev so if I hit enter right now I will say why hit enter again
so one of the things we just installed was called make if I do man make it says here the make utility
will determine automatically which pieces of a large program need to be recompiled and issue the
commands to recompile them ultimately this is what we're going to be using in order to stand up and
compile our kernel so I will go back to my directory right here and I'm going to say make help now
within here we're going to see a whole bunch of different information now one of the things we want
to do is to actually clean our system before we do anything this is going to remove any configurations
that may happen to be left over from an old compilation now we can see here we actually
have three different options we have the clean target the mr proper target or mr proper as I
like to call it and the dist clean targets so I will use the clean target I will say make clean
and now what we want to do is to create the configuration file now if we actually scroll
up here we're going to see a whole bunch of different options that we have so we have these
configuration targets we can use make config or we could use make nconfig or make menu config we
have all these different options the one which I want to use is a menu based configuration which is
going to be menu config okay now before I start I want to also install flex and bison so I'll say
yes okay I'll clear the screen I'll say make menu config okay and this now drops us into the graphical
user interface now if I scroll on down with my arrows I can go into particular menus let's say
for example I wanted to go into device drivers I could hit return and if you actually notice we
have all of these options now if we happen to see an asterisk this means that this particular driver
here in this case is going to be built into the kernel so you cannot even disable it like you
could a module whereas if you happen to see an m this means that it's going to be compiled with
this as a module something that can be loaded or removed so if I wanted to change something
particular let's go into block devices maybe normal floppy disk supports I can hit space bar and change
the module to an asterisk so that it will be built in to the kernel or I can hit m to change it back
to a module now if I hit space bar again and again it's actually going to be empty and when it is
empty this means it's going to be completely unavailable it cannot be loaded as a module and
it will not be built in it's just going to be unavailable for right now I'll just leave this as a
star and now at the bottom here I can use my arrows and I'll go over and click save now this part here
is something you want to remember this is the default name of the file where the configurations
are going to be saved dot config okay so if I hit enter to okay and then enter to exit and then arrow
over to exit and enter again and again and lastly one more time we have exited out and if I do an
ls-l we're not going to see this dot config file because it is hidden but if I do an ls-la now we
can actually see this dot config file so if I happen to go into nano.config here are all the
settings that we have for our configuration file that we will use to compile our kernel one thing
I want to talk to you about right now and this is something we definitely want to be aware of for
the purposes of the examination we have two different kernel image styles that we want to be
aware about the first one is called z image now the thing to note about z image is that it is
an older style of kernel image and it's limited to 512 kb so very very small indeed now we also
have another kind of image and this is called bz image now one thing I want to highlight here is
that this is often the source of incorrect information people tend to think that because they see bz
this is somehow related to bzip compression this is completely unrelated what bz image is
it just means big z image pretty much it's a larger version of z image simply puts most kernel
images are much larger than 512 kb so the original z image is not going to be sufficient so now we
have bz image which is going to allow us to handle kernel images above 512 kilobytes so try to remember
that distinction really really important so what we would do then is if we wanted to compile this
image we would take the command make bz image and that would actually take the configurations from
our .config file and actually compile it now I'm actually not going to run through the compilation
process right here the reality is this would take about well in my case at least an hour of just
watching the screen run but once that actually completes you will have your compiled kernel
image but we understand that the kernel itself is modular so we also want to compile the related
modules the way we would then do that would be the next command we would issue would be make
modules and this one here would take even longer yet again in my case this would take probably a
few hours to fully compile but again for the purposes of the examination as long as we know
these commands and understand what they're doing that is more than enough and once we have compiled
the actual modules themselves we want to install them and we can install them using the command
make modules underscore install and that is going to take our compiled modules and actually run
through the installation the next thing we would want to do is we would want to copy the compiled
bz image we created and we would want to copy that to the forward slash boot directory and then
what we would want to do is to create what is called an init ram fs file this is going to contain a
mini root file system that has the kernel modules we need when the system is getting going and
booting up now the way we actually create this file is we have a particular command in ubuntu
and that is called mk init ram fs so this is the command we would use on ubuntu if we were on a
retap based system such as rockey linux or sentos we would use mk init rd okay and what this utility
does it calls something called the drakut utility and drakut is going to create the initial image
used by the kernel for preloading block device modules and finally if you wanted to run this
particular kernel you could modify your grub configuration file and reboot into this new
kernel configuration now ultimately this process can be very very complex much more complex than
what we have to understand for the purposes of the lpik 2 examination depending on just how deep
you want to take it and it is a very very long process but really understanding the main core
concepts at play here this is what we want to focus in on we want to make our bz image we want to
make our modules this will compile the image and compile the modules we then want to install the
modules with modules install we then want to copy our bz image we create up here to the boot directory
then we want to create our init ram fs file and then we want to modify grub to actually use our new
kernel and those are the core components and processes that we really want to be focusing in on
okay so i know that was a lot to follow for a single nugget if you find it tough to digest all the
information in one go then i certainly would recommend that you rewatch this nugget a few times
and take notes just to help let the information sink in that little bit easier okay doc so i
hope this has been informative for you and i'd like to thank you for viewing