How to remove old unused kernel from CentOS/RHEL systems with yum-utils utility

To remove unused  old kernels from CentOS/RHEL systems , you can use   package-cleanup command which is the part of yum-utils package.

Firstly you install yum-utils with yum command.

root@localhost ~]# yum install yum-utils -y
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
google-chrome | 951 B 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: centos.mirror.net.in
* extras: centos.mirror.net.in
* updates: centos.excellmedia.net
Resolving Dependencies
–> Running transaction check
—> Package yum-utils.noarch 0:1.1.31-42.el7 will be updated
—> Package yum-utils.noarch 0:1.1.31-45.el7 will be an update
–> Finished Dependency Resolution

Dependencies Resolved

============================================================================
Package                                Arch                     Version                  Repository             Size
============================================================================
Updating:
yum-utils                             noarch                  1.1.31-45.el7           base                        119 k

Transaction Summary
============================================================================
Upgrade 1 Package

Total download size: 119 k
Downloading packages:
No Presto metadata available for base
yum-utils-1.1.31-45.el7.noarch.rpm | 119 kB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : yum-utils-1.1.31-45.el7.noarch 1/2
Cleanup : yum-utils-1.1.31-42.el7.noarch 2/2
Verifying : yum-utils-1.1.31-45.el7.noarch 1/2
Verifying : yum-utils-1.1.31-42.el7.noarch 2/2

Updated:
yum-utils.noarch 0:1.1.31-45.el7

Complete!
[root@localhost ~]#

Now remove all kernels except the latest currently running .

[root@localhost ~]# package-cleanup –oldkernels –count=2

Loaded plugins: fastestmirror, langpacks
–> Running transaction check
—> Package kernel.x86_64 0:3.10.0-514.10.2.el7 will be erased
—> Package kernel.x86_64 0:3.10.0-693.11.1.el7 will be erased
—> Package kernel-devel.x86_64 0:3.10.0-514.16.1.el7 will be erased
—> Package kernel-devel.x86_64 0:3.10.0-693.5.2.el7 will be erased
—> Package kernel-devel.x86_64 0:3.10.0-693.11.1.el7 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

============================================================================
Package               Arch                         Version                     Repository                Size
============================================================================
Removing:
kernel                  x86_64                3.10.0-514.10.2.el7         @updates                148 M
kernel                  x86_64                3.10.0-693.11.1.el7          @updates                  59 M
kernel-devel      x86_64                3.10.0-514.16.1.el7          @updates                  34 M
kernel-devel      x86_64                3.10.0-693.5.2.el7             @updates                  36 M
kernel-devel      x86_64                3.10.0-693.11.1.el7           @updates                  36 M

Transaction Summary
============================================================================
Remove 5 Packages

Installed size: 312 M
Is this ok [y/N]: y

Ho to Configure yum utility to auto-remove old unused kernels

To Configure yum utility to auto-remove old  kernels, you can use yum coniguration file reside in /etc directory, named  yum.conf  . By default CentOS will keep last 5 kernels installed on your system. You can keep desired number of old kernels on your system after update . For this purpose you can change installonly_limit = to any  no. ( ie.2,3,4 etc. ) in the /etc/yum.conf configuration file .

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

How to remove old unused Kernel from CentOS 7

https://linuxgeeksin.com/2018/07/03/how-to-remove-old-unused-kernel-from-centos-7/


How to remove old unused Kernel from CentOS 7

When you update the CentOS Linux, the update add a new kernel image in the system but update will not remove your old kernel. To remove these unused kernel .you can used yum command .

Firstly you check which kernel is running on your Machine.

[root@localhost ~]# uname -r
3.10.0-693.21.1.el7.x86_64

Below are the list of installed kernel on your CentOS machine

[root@localhost ~]# rpm -qa kernel
kernel-3.10.0-693.5.2.el7.x86_64
kernel-3.10.0-693.11.1.el7.x86_64
kernel-3.10.0-514.10.2.el7.x86_64
kernel-3.10.0-693.21.1.el7.x86_64
kernel-3.10.0-693.17.1.el7.x86_64
[root@localhost ~]#

You can use yum command to remove old unused kernel from the CentOS Linux

[root@localhost ~]# yum erase kernel-3.10.0-693.5.2.el7.x86_64
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
–> Running transaction check
—> Package kernel.x86_64 0:3.10.0-693.5.2.el7 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

============================================================================
Package                                      Arch                      Version             Repository             Size
============================================================================
Removing:
kernel                                        x86_64            3.10.0-693.5.2.el7    @updates               59 M

Transaction Summary
============================================================================
Remove 1 Package

Installed size: 59 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : kernel-3.10.0-693.5.2.el7.x86_64 1/1
Verifying : kernel-3.10.0-693.5.2.el7.x86_64 1/1

Removed:
kernel.x86_64 0:3.10.0-693.5.2.el7

Complete!
[root@localhost ~]#

How to install Apache HTTP Server on FreeBSD

Apache is a well known web server used by world-wide to host their websites.To install Apache HTTP web Server on FreeBSD you can use ‘pkg’ utitlity with ‘install ‘option.

root@:~ # pkg install apache24
Updating FreeBSD repository catalogue…
FreeBSD repository is up to date.
All repositories are up to date.
The following 11 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
apache24: 2.4.29
libnghttp2: 1.29.0
libxml2: 2.9.7
expat: 2.2.5
pcre: 8.40_1
apr: 1.6.3.1.6.1
gdbm: 1.13_1
indexinfo: 0.3.1
readline: 7.0.3_1
gettext-runtime: 0.19.8.1_1
db5: 5.3.28_6
Number of packages to be installed: 11
The process will require 85 MiB more space.
20 MiB to be downloaded.
Proceed with this action? [y/N]: y

After Apache web server has been succefully installed on the system, you  enable Apache as a service, add apache24_enable=”YES” to the /etc/rc.conf file or you can use sysrc command to add this line in the /etc/rc.conf file.

root@:~ # sysrc apache24_enable=”yes”
apache24_enable: -> yes
root@:~ #

Now you start Apache deamon with the service command.

root@:~ # service apache24 start
Performing sanity check on apache24 configuration:
AH00557: httpd: apr_sockaddr_info_get() failed for
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message
Syntax OK
Starting apache24.
AH00557: httpd: apr_sockaddr_info_get() failed for
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message
root@:~ #

Now Apache web server run successfully and you can test it by accessing the server IP address through the web browser.

testappache

The default webroot directory of Apache web server in FreeBSD 11.1 is located in /usr/local/www/apache24/data/ .

How to install tree command on FreeBSD

To install tree command on FreeBSD you can use the ‘pkg’ command with’ install’ option as a root. Tree command generally used to  list contents of directories in a tree-like structure.

root@:~ # pkg install tree

Updating FreeBSD repository catalogue…
Fetching meta.txz: 100% 944 B 0.9kB/s 00:01
Fetching packagesite.txz: 100% 6 MiB 23.0kB/s 04:27
Processing entries: 100%
FreeBSD repository update completed. 28736 packages processed.
All repositories are up to date.
New version of pkg detected; it needs to be installed first.
The following 1 package(s) will be affected (of 0 checked):

Installed packages to be UPGRADED:
pkg: 1.10.1 -> 1.10.3_1

Number of packages to be upgraded: 1

3 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/1] Fetching pkg-1.10.3_1.txz: 100% 3 MiB 21.0kB/s 02:11
Checking integrity… done (0 conflicting)
[1/1] Upgrading pkg from 1.10.1 to 1.10.3_1…
Extracting pkg-1.10.3_1: 100%
Updating FreeBSD repository catalogue…
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
tree: 1.7.0

Number of packages to be installed: 1

39 KiB to be downloaded.

Proceed with this action? [y/N]: y
[1/1] Fetching tree-1.7.0.txz: 100% 39 KiB 39.7kB/s 00:01
Checking integrity… done (0 conflicting)
[1/1] Installing tree-1.7.0…
Extracting tree-1.7.0: 100%
root@:~ #

How to display complete list of login and logout with times & dates in the Linux server

To display complete list of login and logout with times  and dates in the Linux server  ,you can use ‘ last ‘ command with -F option.

 [root@localhost ~]# last -F
root pts/0 192.168.26.1 Wed Jan 10 20:56:02 2018 still logged in
reboot system boot 3.10.0-693.11.1. Wed Jan 10 20:55:19 2018 – Wed Jan 10 21:21:44 2018 (00:26)
root pts/0 192.168.26.1 Wed Jan 10 20:46:37 2018 – crash (00:08)
root pts/0 192.168.26.1 Wed Jan 10 20:06:19 2018 – Wed Jan 10 20:38:34 2018 (00:32)
reboot system boot 3.10.0-693.11.1. Wed Jan 10 19:58:23 2018 – Wed Jan 10 21:21:44 2018 (01:23)
root pts/0 192.168.26.1 Wed Jan 10 19:50:41 2018 – crash (00:07)
reboot system boot 3.10.0-693.11.1. Wed Jan 10 16:49:29 2018 – Wed Jan 10 21:21:44 2018 (04:32)
root pts/0 192.168.26.1 Wed Jan 10 19:46:32 2018 – crash (-2:-57)
root pts/1 192.168.26.1 Wed Jan 10 15:28:30 2018 – crash (01:20)
root pts/0 192.168.26.1 Wed Jan 10 12:57:04 2018 – Wed Jan 10 15:42:32 2018 (02:45)
reboot system boot 3.10.0-693.11.1. Wed Jan 10 12:55:15 2018 – Wed Jan 10 21:21:44 2018 (08:26)
root pts/0 192.168.26.1 Wed Jan 10 12:36:57 2018 – down (00:17)
reboot system boot 3.10.0-693.11.1. Tue Jan 9 23:05:42 2018 – Wed Jan 10 12:54:43 2018 (13:49)
root pts/0 192.168.26.1 Tue Jan 9 23:01:20 2018 – down (00:04)
reboot system boot 3.10.0-693.11.1. Tue Jan 9 23:00:16 2018 – Tue Jan 9 23:05:27 2018 (00:05)

..

..

wtmp begins Wed Dec 28 17:12:53 2016
[root@localhost ~]#.