You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

110 lines
8.2 KiB

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Learning Website</title>
<link href="/styles/styles.css" rel="stylesheet" type="text/css">
<link href="/linux/styles/styles.css" rel="stylesheet" type="text/css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="banner">
<h1 class="courselink">Learning Linux Command Line</h1>
<h2 class="lecturer">LinkedIn Learning : Scott Simpson</h2>
<h2 class="episodetitle">Appendix B</h2>
</div>
<article>
<h2 class="sectiontitle">How to Upgrade the Linux Kernel on CentOS 7</h2>
<p>For this, I am following the process found on the <a href="https://www.howtoforge.com/tutorial/how-to-upgrade-kernel-in-centos-7-server/">How
to Forge</a> website.</p>
<h3>STEP 1</h3>
<p>The first step is to update and upgrade CentOS 7 with</p>
<pre class="inset">$sudo yum -y update</pre>
<p>The y option has the effect of automatically answering yes to any question the user might be asked such as “Do you want to continue?”.</p>
<p>Next, we will install (if it is not already installed) yum-plugin-fastestmirror with</p>
<pre class="inset">$sudo yum -y install yum-plugin-fastestmirror</pre>
<p>In my case, it is already installed so the command has no effect.</p>
<h3>STEP 2</h3>
<p>The second step is to check the existing kernel version which we can do with</p>
<pre class="inset">$uname -snr</pre>
<p>Of course, we had already done this in an earlier lesson although we are using different options with uname but the result is the same – the command confirms that we are using version 3.10.0 of the kernel.</p>
<h3>STEP 3</h3>
<p>The next step is to add a repository, the ELRepo repository and we will start this process by adding the ELRepo gpg key to the system. Note that gpg stands for GNU Private Guard and more information can be found <a href="http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/">here</a>.</p>
<p>The command to do this is</p>
<pre class="inset">rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</pre>
<p>We can now add the ELRepo repository with the command</p>
<pre class="inset">$rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.e17.elrepo.noarch.rpm</pre>
<p>Before we move on to step 4, we will list our repositories just to make sure elrepo is there and we do that with</p>
<pre class="inset">$yum repolist</pre>
<p>I can see that ELRepo is listed and it looks the same as that listed on the tutorial website I am following so I am satisfied that this step was successful.</p>
<h3>Step 4</h3>
<p>In this step, we are going to install the latest kernel version which is 5.3.10, the latest version on kernel.org (kernel.org is the Linux Kernel Archives and can be found <a href="https://www.kernel.org/">here</a> and it also displays the version number of the latest stable kernel quite prominently).</p>
<p>The command to do this is</p>
<pre class="inset">$sudo yum --enablerepo=repo-kernel install kernel-ml</pre>
<p>The --enablerepo option is used to enable a specific repository in CentOS. The elrepo repository is enabled by default, but the elrepo-kernel repository is not.</p>
<p>We listed repositories in step 3 but this only listed enabled repositories. We will list them again, but this time we will list all of them whether enabled or not.</p>
<pre class="inset">$yum repolist all</pre>
<p>Actually, it looks as though elrepo-kernel is disabled so I guess that the option used in this way only enables it for the purpose of running the command and then disables it again.</p>
<h3>Step 5</h3>
<p>At this stage, we have already installed the new kernel but we need to configure Grub to load it when the system starts up. We can see what versions of the kernel are available in Grub with</p>
<pre class="inset">$sudo awl -F\ ‘ ‘$1==”menuentry” {print i++ “:“ $2}’ /etc.grub2.cfg</pre>
<p>From this, I can see that we have several versions of 3.10.0 available with minor differences and we also have 5.3.10 available.</p>
<p>We can also see that each version of the kernel has an ordinal number with 0 being at the top and in this case, it runs to 4 at the bottom and these are the order in which these appear on the screen when booting up.</p>
<p>We want our upgrade kernel to be the default option so that we don’t have to select it every time the system starts and we can do that with</p>
<pre class="inset">$sudo grub2-set-default 0</pre>
<p>If we need to return to the previous kernel version, we can obviously select it when the system starts up or we can set it to the default value with the same command but with a default of 1.</p>
<p>Next, we need to generate the grub2 config file with</p>
<pre class="inset">$sudo grub2-mkconfig -o /boot/grub2/grub.cfg</pre>
<p>and we can restart the system from the command line with</p>
<pre class="inset">$sudo reboot</pre>
<p>Once the system has rebooted, we can run uname again and see that we now have version 5.3.1.</p>
<h3>Step 6</h3>
<p>The final step is optional and this is to remove the old kernel which you may want to do if you are short of disk space.</p>
<p>To start with, we need to install yum-utils from the repository with</p>
<pre class="inset">$yum install yum-utils</pre>
<p>Again, this did nothing on my system because I already had the package installed. The final step is to run the package-cleanup command. This will actually not remove all the old kernels, but if you have more than three, it will get rid of all of them except the three most up to date versions.</p>
<p>To demonstrate this, let’s take a quick look at our kernel versions again. The results are shown in figure 14.</p>
<figure>
<img src ="images\figure14.png" alt="Figure 14 - the different versions of the kernel we have after upgrading to version 5.3.10">
<figcaption>Figure 14 - the different versions of the kernel we have after upgrading to version 5.3.10</figcaption>
</figure>
<p>The package-cleanup command is</p>
<pre class="inset">$package-cleanup --oldkernels</pre>
<p>and we can run this command and check the outcome. Note that if you only have 3 or fewer kernels, you will see a message stating that there are no old kernels to remove (although you can actually set an option with package-cleanup to change the number of versions it keeps). Otherwise you will see a confirmation of the kernel to be removed as it executes and a summary showing which version or versions were removed when the command is completed.</p>
<p>Now, we can check the kernel versions for a last time and we see the results shown in figure 15.</p>
<figure>
<img src ="images\figure15.png" alt=" Figure 15 - the different versions of the kernel as shown in figure 14 but after package-cleanup --oldkernels has been executed ">
<figcaption> Figure 15 - the different versions of the kernel as shown in figure 14 but after package-cleanup --oldkernels has been executed</figcaption>
</figure>
<p>Comparing figures 14 and 15, we can see that one old kernel has been removed leaving us with three versions as well as the rescue disk.</p>
<p>For more information on this see</p>
<pre class="inset">
&bull; <a href="https://elrepo.org/">https://elrepo.org/</a>
&bull; <a href="https://wiki.centos.org/HowTos/Grub2">https://wiki.centos.org/HowTos/Grub2</a></pre>
</article>
<div class="btngroup">
<button class="button" onclick="window.location.href='appendixa.html';">
Previous Chapter - A Peek at Some More Advanced Topics
</button>
<button class="button" onclick="window.location.href='learninglinuxcommandline.html'">
Course Contents
</button>
<button class="button" onclick="window.location.href='/linux/linux.html'">
Linux Page
</button>
<button class="button" onclick="window.location.href='/index.html'">
Home
</button>
</div>
</body>
</html>