How to install docker in Linux

Learn how to install Docker in Linux. Docker is the next step of virtualization which does Operating system level virtualization also known as containerization.

Install docker in Linux

In this article, we will walk you through the procedure to install Docker in any Linux distro like RHEL, SUSE, OEL, CentOS, Debian, Fedora, Ubuntu, etc. Sometimes your package manager like YUM or apt-get may offer package docker* to install docker on your server but it’s always good to get a fresh Docker setup. Since Docker is changing fast and it’s always advisable to install the latest version of Docker which might not be available with your package manager.

Read all docker or containerization related articles here from KernelTalk’s archives.

Install docker using package

If your package manager has a Docker package available to install then it’s an easy way to get Docker on your system.

Before going got Docker installation you should install below packages on your system to use the full flexible functionality of Docker. These packages are not dependencies but its good to have them pre-installed so that all Docker functions/drivers you can use.

  • For CenOs, Redhat etc YUM based systems – yum-utils device-mapper-persistent-data lvm2
  • For Debian, Ubuntu etc apt based systems – apt-transport-https ca-certificates curl software-properties-common

But you may not be getting the latest version of Docker in this case. You can install a package simply using yum or apt-get command. Below sample output for your reference from the OpenSuse server.

root@kerneltalks # zypper in docker
Building repository 'openSUSE-13.2-Update' cache .................................................................................................................[done]
Retrieving repository 'openSUSE-13.2-Update-Non-Oss' metadata ....................................................................................................[done]
Building repository 'openSUSE-13.2-Update-Non-Oss' cache .........................................................................................................[done]
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  docker

1 new package to install.
Overall download size: 6.2 MiB. Already cached: 0 B  After the operation, additional 22.9 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package docker-1.9.1-56.1.x86_64                                                                                        (1/1),   6.2 MiB ( 22.9 MiB unpacked)
Retrieving: docker-1.9.1-56.1.x86_64.rpm .............................................................................................................[done (2.5 MiB/s)]
Checking for file conflicts: .....................................................................................................................................[done]
(1/1) Installing: docker-1.9.1-56.1 ..............................................................................................................................[done]
Additional rpm output:
creating group docker...
Updating /etc/sysconfig/docker...

Install docker using the script

In the below procedure, we will be using the script from Docker’s official website which will scan your system for details and automatically fetch the latest and compatible docker version for your system and installs it. We will be fetching script from this docker URL and using it to install the latest Docker on the list of Linux distros.

Fetch the latest script from docker official website using curl. If you read this script, SUPPORT_MAP variable shows the list of Linux distros this script support. If you are running any other Linux version than listed here then this method won’t be useful for you.

root@kerneltalks # curl -fsSL get.docker.com -o get-docker.sh
root@kerneltalks # ls -lrt
-rw-r--r--. 1 root root 13847 May 30 18:59 get-docker.sh

Now we have latest get-docker.sh script from docker official website on our server. Now, you just have to run the script and it will do the rest!

# sh get-docker.sh
# Executing docker install script, commit: 36b78b2
+ sh -c 'yum install -y -q yum-utils'
Package yum-utils-1.1.31-45.el7.noarch already installed and latest version
+ sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
+ '[' edge '!=' stable ']'
+ sh -c 'yum-config-manager --enable docker-ce-edge'
Loaded plugins: fastestmirror
========================================================================= repo: docker-ce-edge =========================================================================
[docker-ce-edge]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = https://download.docker.com/linux/centos/7/x86_64/edge
cache = 0
cachedir = /var/cache/yum/x86_64/7/docker-ce-edge
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = 1
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge/gpgdir
gpgkey = https://download.docker.com/linux/centos/gpg
hdrdir = /var/cache/yum/x86_64/7/docker-ce-edge/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = Docker CE Edge - x86_64
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/docker-ce-edge
pkgdir = /var/cache/yum/x86_64/7/docker-ce-edge/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = docker-ce-edge/x86_64
ui_repoid_vars = releasever,
   basearch
username =

+ sh -c 'yum makecache'
Loaded plugins: fastestmirror
base                                                                                                                                             | 3.6 kB  00:00:00
docker-ce-edge                                                                                                                                   | 2.9 kB  00:00:00
docker-ce-stable                                                                                                                                 | 2.9 kB  00:00:00
epel/x86_64/metalink                                                                                                                             |  21 kB  00:00:00
extras                                                                                                                                           | 3.4 kB  00:00:00
updates                                                                                                                                          | 3.4 kB  00:00:00
(1/15): docker-ce-stable/x86_64/filelists_db                                                                                                     | 7.7 kB  00:00:03
(2/15): base/7/x86_64/other_db                                                                                                                   | 2.5 MB  00:00:04
(3/15): docker-ce-edge/x86_64/filelists_db                                                                                                       | 9.6 kB  00:00:04
(4/15): docker-ce-edge/x86_64/other_db                                                                                                           |  62 kB  00:00:04
(5/15): docker-ce-stable/x86_64/other_db                                                                                                         |  66 kB  00:00:00
(6/15): base/7/x86_64/filelists_db                                                                                                               | 6.9 MB  00:00:05
(7/15): epel/x86_64/filelists_db                                                                                                                 |  10 MB  00:00:01
(8/15): epel/x86_64/prestodelta                                                                                                                  | 2.8 kB  00:00:00
(9/15): epel/x86_64/other_db                                                                                                                     | 3.1 MB  00:00:01
(10/15): extras/7/x86_64/prestodelta                                                                                                             |  48 kB  00:00:02
(11/15): extras/7/x86_64/other_db                                                                                                                |  95 kB  00:00:02
(12/15): extras/7/x86_64/filelists_db                                                                                                            | 519 kB  00:00:02
(13/15): updates/7/x86_64/filelists_db                                                                                                           | 1.3 MB  00:00:02
(14/15): updates/7/x86_64/prestodelta                                                                                                            | 231 kB  00:00:00
(15/15): updates/7/x86_64/other_db                                                                                                               | 228 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirror.genesisadaptive.com
 * epel: s3-mirror-us-east-1.fedoraproject.org
 * extras: mirror.math.princeton.edu
 * updates: mirror.metrocast.net
Metadata Cache Created
+ sh -c 'yum install -y -q docker-ce'
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

If you observe the above output then you will get to know that script will detect your OS and will download, configure, and use supported repo to install Docker on your machine. It also notifies you to add non-root user to group docker so that he/she can run docker commands with root privileges.

You can download and run the script this in a single command as well like below –

root@kerneltalks # curl -fsSL get.docker.com -o - get-docker.sh | bash -s

If you are running the script on un-supported Linux version (which is not mentioned in SUPPORT_MAP list) then you will see below error.

root@kerneltalks # sh get-docker.sh
Executing docker install script, commit: 36b78b2

Either your platform is not easily detectable or is not supported by this
installer script.
Please visit the following URL for more detailed installation instructions:

https://docs.docker.com/engine/installation/

If you are on RHEL, SLES (basically Enterprise Linux editions) then only Docker EE i.e. Enterprise Edition (paid) is supported on them. You will need to purchase appropriate subscriptions to use them. You will see below message –

# sh get-docker.sh
# Executing docker install script, commit: 36b78b2


  WARNING: rhel is now only supported by Docker EE
           Check https://store.docker.com for information on Docker EE

Install with help from docker store

If both above methods are not suitable for you then you can always opt for the last method. Head to Docker online store. Goto Docker CE i.e. Community Edition (the free one) and choose your Linux distro. Currently, they have listed AWS, Azure, Fedora, CentOS, Ubuntu & Debian. Click on your choice, head to Resources tab, and click Detailed installation instructions. You will be redirected to appropriate documents on Docker documents which have detailed step by step commands to perform a clean install of Docker on Linux of your choice! Or you can always head to this home page of installation and choose your host.

Check if Docker is installed

Finally, you have to check if Docker is installed on the system. To check if docker is installed, simply run the command docker version

root@kerneltalks # docker version
Client:
 Version:      18.05.0-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   f150324
 Built:        Wed May  9 22:14:54 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

The last line in the above output shows that the Docker service is not yet running on the server. You can start the service and then the output will show your Docker server details as well.

root@kerneltalks # service docker start
root@kerneltalks # docker version
Client:
 Version:      18.05.0-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   f150324
 Built:        Wed May  9 22:14:54 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.05.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   f150324
  Built:        Wed May  9 22:18:36 2018
  OS/Arch:      linux/amd64
  Experimental: false

So, now you have successfully installed Docker on your machine and started the Docker server. You are yet to create containers in it!

Setting up docker for non-root user

For non-root user to use Docker, you need to add the user into a group called docker. This group is automatically gets created when you install Docker.

root@kerneltalks # usermod -aG <user> docker

Run above command to add non-root user in docker group and then that user will be able to run all docker commands without root privileges.

Also, you need to make sure that docker services start automatically when the server reboots. Since system control systemctl is becoming standard on all latest Linux versions, below command will suit on nearly major Linux distros

root@kerneltalks # systemctl enable docker

This command will enable docker to run with system boot and hence no root intervention needed when the system reboots. Non-root users will continue to use docker even after a reboot.

Try Docker without installing!

If you want to try Docker without installing it on your machine then just head to Play with Docker website and you will be able to spin up machines having Docker in it. You can try Docker commands in it from your web browser!

The only limitation they have is your session will be auto closed after 4 hours. You have a clock ticking in your browser window set to 4 hours once you log in.

Execute command at shutdown and boot in Suse Linux

Learn how to setup commands or scripts to execute at shutdown and boot in Suse Linux

Execute a command at shutdown and boot in Suse Linux

In this article, we will walk you through the procedure to schedule scripts at shutdown and boot in Suse Linux. Many times, we have a requirement to start certain applications or services or script after server boots. Sometimes you want to stop application or service or run the script before the server shuts down. This can be done automatically by defining commands or scripts in certain files in Suse Linux.

Application auto start-stop along with OS reboot

Let’s walk through steps to configure the custom applications to auto-start and stop along with Linux reboot. Create a file with a custom name (e.g autoapp) in /etc/init.d as below –

#!/bin/sh
### BEGIN INIT INFO
# Provides: auto_app
# Required-Start: $network $syslog $remote_fs $time
# X-UnitedLinux-Should-Start:
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Start and stop app with reboot
# Description: Start and stop custom application with reboot
### END INIT INFO#
case "$1" in
"start")

        su - appuser -c "/app/start/command -options"
        echo "Application started"
        ;;
"stop")
        su - appuser -c "/app/stop/command -options"
        ;;
*)
        echo "Usage: $0 { start|stop }"
        exit 1
        ;;
esac
exit 0

Make sure you copy all the above text including INIT block at the beginning of the file. Edit appuser and app commands under start and stop blocks.

Set executable permission on this file.

The next step is to identify this file as a service using chkconfig. Use filename as a service name in the below command.

root@kerneltalks # chkconfig --add autoapp

Now enable it to be handeled by systemctl

root@kerneltalks # systemctl enable autoapp

And you are done. Try to start and stop the application using systemctl command to make sure your configuration is working fine. To rule out any permission issues, script entries typo, etc.

root@kerneltalks # systemctl stop autoapp
root@kerneltalks # systemctl start autoapp

If systemctl is properly starting and stopping application as expected then you are all set. Final test you can do by rebooting your server and then verifying if the application was down while the server was shut and did it came up along with server boot.


Run script or command after server boot

In Suse Linux, you have to define commands or scripts in /etc/init.d/after.local to run them after server boots. I am running SLES 12 SP3 and my /etc/init.d/after.locallooks likes below –

root@kerneltalks # cat  /etc/init.d/after.local
#! /bin/sh
#
# Copyright (c) 2010 SuSE LINUX Products GmbH, Germany.  All rights reserved.
#
# Author: Werner Fink, 2010
#
# /etc/init.d/after.local
#
# script with local commands to be executed from init after all scripts
# of a runlevel have been executed.
#
# Here you should add things, that should happen directly after
# runlevel has been reached.
#

I added below command at end of this file.

echo "I love KernelTalks"

Then to test it, I rebooted the machine. After reboot, since command output is printed to console I need to check logs to confirm if the command executed successfully.

You can check logs of after local service as below :

# systemctl status after-local -l
● after-local.service - /etc/init.d/after.local Compatibility
   Loaded: loaded (/usr/lib/systemd/system/after-local.service; static; vendor preset: disabled)
   Active: active (exited) since Thu 2018-05-24 03:52:14 UTC; 7min ago
  Process: 2860 ExecStart=/etc/init.d/after.local (code=exited, status=0/SUCCESS)
 Main PID: 2860 (code=exited, status=0/SUCCESS)

May 24 03:52:14 kerneltalks systemd[1]: Started /etc/init.d/after.local Compatibility.
May 24 03:52:15 kerneltalks after.local[2860]: I love KernelTalks

If you observe the above output, the last line shows the output of our command which we configured in /etc/init.d/after.local! Alternatively, you can check syslog /var/log/messages file as well to check the same logs.

So it was a successful run.

Run script or command before server shutdown

To run a script or command before server initiate shutdown, you need to specify them in /etc/init.d/halt.local. Typical vanilla /etc/init.d/halt.local looks like below –

root@kerneltalks #  cat /etc/init.d/halt.local
#! /bin/sh
#
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany.  All rights reserved.
#
# Author: Werner Fink, 1998
#         Burchard Steinbild, 1998
#
# /etc/init.d/halt.local
#
# script with local commands to be executed from init on system shutdown
#
# Here you should add things, that should happen directly before shuting
# down.
#

I added below command at end of this file.

echo "I love KernelTalks"

To make sure, this file is picked up for execution before the shutdown halt.local service should be running. Check if service is running and if not then start it.

# systemctl enable halt.local
halt.local.service is not a native service, redirecting to systemd-sysv-install
Executing /usr/lib/systemd/systemd-sysv-install enable halt.local
# systemctl start halt.local
# systemctl status halt.local
● halt.local.service
   Loaded: loaded (/etc/init.d/halt.local; bad; vendor preset: disabled)
   Active: active (exited) since Thu 2018-05-24 04:20:18 UTC; 11s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3074 ExecStart=/etc/init.d/halt.local start (code=exited, status=0/SUCCESS)

May 24 04:20:18 kerneltalks systemd[1]: Starting halt.local.service...

Then to test it, I shut down the machine. After boot, check logs to confirm if a command was run when the system was shut down.

# cat /var/log/messages |grep halt
2018-05-24T04:21:12.657033+00:00 kerneltalks systemd[1]: Starting halt.local.service...
2018-05-24T04:21:12.657066+00:00 kerneltalks halt.local[832]: I Love KernelTalks
2018-05-24T04:21:12.657080+00:00 kerneltalks systemd[1]: Started halt.local.service.

# systemctl status halt.local -l
● halt.local.service
   Loaded: loaded (/etc/init.d/halt.local; bad; vendor preset: disabled)
   Active: active (exited) since Thu 2018-05-24 04:21:12 UTC; 1min 18s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 832 ExecStart=/etc/init.d/halt.local start (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 512)

May 24 04:21:12 kerneltalks systemd[1]: Starting halt.local.service...
May 24 04:21:12 kerneltalks halt.local[832]: I Love KernelTalks
May 24 04:21:12 kerneltalks systemd[1]: Started halt.local.service.




That’s it. You can see our echo message is printed in logs which indicates commands successfully ran before shutdown.

In this way, you can configure your application start-stop commands in Suse Linux to start and stop application after boot and before the shutdown of the server. Also, you can schedule scripts to execute before shutdown and after boot of the Suse Linux server.

How to resolve setenv: command not found

setenv is a built-in command for csh. You need to have C Shell to tackle with setenv: command not found error.

setenv: command not found resolution

Error :

Set environment command setenv is not available on the system. You see below error :

root@kerneltalks # setenv
-bash: setenv: command not found

So question is how to install setenv command.

Solution :

setenv is a shell built-in command comes with C shell csh. Above error could be due to two things –

  1. csh is not installed on server
  2. User havnt invoked csh shell

For point 1, go ahead and install csh package.

For point 2, Simply invoke csh shell by changing user login shell (usermod -s)  or use chsh command as below –

root@kerneltalks # chsh root
Changing shell for root.
New shell [/bin/bash]: /bin/csh
Shell changed.

And to change shell on the fly for your current logged-in session use below command –

root@kerneltalks # echo $0
bash
root@kerneltalks # csh
root@kerneltalks # echo $0
csh

Now, after csh shell availability if you run setenv, it runs smooth!

# setenv
REMOTEHOST=210.23.23.456
XDG_SESSION_ID=1
HOSTNAME=kerneltalks
HOST=kerneltalks
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
GROUP=root
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
HOSTTYPE=x86_64-linux
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
MAIL=/var/spool/mail/root
PWD=/root
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
HOME=/root
SHLVL=6
OSTYPE=linux
VENDOR=unknown
MACHTYPE=x86_64
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/bin/csh

Why ps output shows UID instead of username

Learn why ps output shows UID instead of username.

PS reads UID instead of username in output

One of our reader asked me:

I see userid in place of the username in ps -ef command output, please explain.

In this article, we will see why ps output shows UID instead of username sometimes. In some recent Linux distributions like RHEL 7, it shows cropped username ending with + sign. Let’s see the reason behind ps doesn’t show username.

Normal ps -ef command output looks like below –

root       541     1  0 17:48 ?        00:00:00 /usr/sbin/NetworkManager --no-da
root       559   541  0 17:48 ?        00:00:00 /sbin/dhclient -d -q -sf /usr/li
root       791     1  0 17:48 ?        00:00:00 /usr/bin/python -Es /usr/sbin/tu
root      1067     1  0 17:48 ?        00:00:00 /usr/libexec/postfix/master -w

where the first column is username who owns that particular process. Sometimes you see output like below –

kernelt+  1354  1335  0 17:50 pts/0    00:00:00 top
OR
1001  1354  1335  0 17:50 pts/0    00:00:00 top

where username in ps output is numeric or cropped username ending with +

This is because ps -ef output restricts username up to 8 characters. If your username is longer than 8 characters then it will display UID or cropped version of it. Here we have kerneltalks user on our server.

# cat /etc/passwd |grep kernel
kerneltalks:x:1001:1001::/home/kerneltalks:/bin/bash

If you observe, user kerneltalks has UID 1001 and hence we could see that UID in ps -ef output.

How to change UID or GID safely in Linux

Learn how to change UID or GID safely in Linux. Also, know how to switch UID between two users and GID between two groups without impacting files ownership they own.

How to change UID or GID safely in Linux

In this article, we will walk you through to change UID or GID of existing users or groups without affecting file ownership owned by them. Later, we also explained how to switch GID between two groups and how to switch UID between two users on the system without affecting file ownership owned by them.

Let’s start with changing UID or GID on the system.

Current scenario :

User shrikant with UID 1001
Group sysadmin with GID 2001

Expected scenario :

User shrikant with UID 3001
Group sysadmin with GID 4001

Changing GID and UID is simple using usermod or groupmod command, but you have to keep in mind that after changing UID or GID you need to change ownership of all files owned by them manually since file ownership is known to the kernel by GID and UID, not by username.

The procedure will be –

Change UID or GID as below :

root@kerneltalks # usermod -u 3001 shrikant
root@kerneltalks # groupmod -g 4001 sysadmin

Now, search and change all file’s ownership owned by this user or group with for loop

root@kerneltalks # for i in `find / -user 1001`; do chown 3001 $i; done
root@kerneltalks # for i in `find / -group 2001`; do chgrp 4001 $i; done
OR
root@kerneltalks # find / -user 1001 -exec chown -h shrikant {} \;
root@kerneltalks # find / -group 2001 -exec chgrp -h sysadmin {} \;

That’s it. You have safely changed UID and GID on your system without affecting any file ownership owned by them!

How to switch GID of two groups

Current scenario :

Group sysadmin with GID 1111
Group oracle with GID 2222

Expected scenario :

Group sysadmin with GID 2222
Group oracle with GID 1111

In the above situation, we need to use one intermediate GID which is currently not in use on your system. Check /etc/group file and select one GID XXXX which is not present in a file. In our example, we take 9999 as intermediate GID.

Now, the process is simple –

  1. Change sysadmin GID to 9999
  2. Find and change the group of all files owned by GID 1111 to sysadmin
  3. Change oracle GID to 1111
  4. Find and change the group of all files owned by GID 2222 to oracle
  5. Change sysadmin GID to 2222
  6. Find and change the group of all files owned by GID 9999 to sysadmin

List of commands for above steps are –

root@kerneltalks # groupmod -g 9999 sysadmin
root@kerneltalks # find / -group 1111 -exec chgrp -h sysadmin {} \;
root@kerneltalks # groupmod -g 1111 oracle
root@kerneltalks # find / -group 2222 -exec chgrp -h oracle {} \;
root@kerneltalks # groupmod -g 2222 sysadmin
root@kerneltalks # find / -group 9999 -exec chgrp -h sysadmin {} \;

How to switch UID of two users

It can be done in the same way we switched GID above by using intermediate UID.

How to safely remove disk from LVM

Learn how to safely remove the disk from LVM. It’s useful when you need to free up disks from the volume group and re-use somewhere else or replace a faulty disk.

How to safely remove disk from LVM

This article will serve solution for below questions :

  • How to safely remove the disk from LVM
  • How to remove the disk from VG online
  • How to copy data from one disk to other at the physical level
  • How to replace a faulty disk in LVM online
  • How to move physical extents from one disk to another
  • How to free up disk from VG to shrink VG size
  • How to safely reduce VG

We have volume group named vg01 which has 20M logical volume created in it and mounted it on /mydata mount point. Check lsblk output below –

root@kerneltalks # lsblk
NAME         MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda         202:0    0  10G  0 disk
├─xvda1      202:1    0   1M  0 part
└─xvda2      202:2    0  10G  0 part /
xvdf         202:80   0   1G  0 disk
└─vg01-lvol1 253:0    0  20M  0 lvm  /mydata

Now, attach new disk of the same or bigger size of the disk /dev/xvdf. Identify the new disk on the system by using lsblk command again and comparing the output to the previous one.

root@kerneltalks # lsblk
NAME         MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda         202:0    0  10G  0 disk
├─xvda1      202:1    0   1M  0 part
└─xvda2      202:2    0  10G  0 part /
xvdf         202:80   0   1G  0 disk
└─vg01-lvol1 253:0    0  20M  0 lvm  /mydata
xvdg         202:96   0   1G  0 disk

You can see the new disk has been identified as /dev/xvdg. Now, we will add this disk to current VG vg01. This can be done using vgextend command. Obviously, before using it in LVM you need to run pvcreate on it.

root@kerneltalks # pvcreate /dev/xvdg
  Physical volume "/dev/xvdg" successfully created.
root@kerneltalks # vgextend vg01 /dev/xvdg
  Volume group "vg01" successfully extended

Now we have disk to be removed /dev/xvdf and new disk to be added /dev/xvdg in the same volume group vg01. You can verify it using pvs command

root@kerneltalks # pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/xvdf  vg01 lvm2 a--  1020.00m 1000.00m
  /dev/xvdg  vg01 lvm2 a--  1020.00m 1020.00m

Observe the above output. Since we created a 20M mount point from disk /dev/xvdf it has 20M less free size. The new disk /dev/xvdg is completely free.

Now, we need to move physical extents from disk xvdf to xvdg. pvmove is the command used to achieve this. You just need to supply a disk name from where you need to move out PE. Command will move PE out of that disk and write them to all available disks in the same volume group. In our case, only one other disk is available to move PE.

root@kerneltalks # pvmove /dev/xvdf
  /dev/xvdf: Moved: 0.00%
  /dev/xvdf: Moved: 100.00%

Move progress is shown periodically. If due to any reason operation interrupted in between then moved PE will remain at destination disks and un-moved PEs will remain on the source disk. The operation can be resumed by issuing the same command again. It will then move the remaining PE out of the source disk.

You can even run it in background with nohup.

root@kerneltalks # pvmove /dev/xvdf 2>error.log >normal.log &
[1] 1639

In the above command, it will run pvmove in the background. It will redirect normal console outputs in normal.log file under the current working directory whereas errors will be redirected and saved in error.log file in the current working directory.

Now if you check pvs output again, you will find all space on disk xvdf is free which means its not been used to store any data in that VG. This ensures you can remove the disk without any issues.

root@kerneltalks # pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/xvdf  vg01 lvm2 a--  1020.00m 1020.00m
  /dev/xvdg  vg01 lvm2 a--  1020.00m 1000.00m

Before removing/detaching disk from the server, you need to remove it from LVM. You can do this by reducing VG and opting for that disk out.

root@kerneltalks # vgreduce vg01 /dev/xvdf
  Removed "/dev/xvdf" from volume group "vg01"

Now disk xvdf can be removed/detached from server safely.

Few useful switches of pvmove :

Verbose mode prints more detailed information on the operation. It can be invoked by using -v switch.

root@kerneltalks # pvmove -v /dev/xvdf
    Cluster mirror log daemon is not running.
    Wiping internal VG cache
    Wiping cache of LVM-capable devices
    Archiving volume group "vg01" metadata (seqno 17).
    Creating logical volume pvmove0
    activation/volume_list configuration setting not defined: Checking only host tags for vg01/lvol1.
    Moving 5 extents of logical volume vg01/lvol1.
    activation/volume_list configuration setting not defined: Checking only host tags for vg01/lvol1.
    Creating vg01-pvmove0
    Loading table for vg01-pvmove0 (253:1).
    Loading table for vg01-lvol1 (253:0).
    Suspending vg01-lvol1 (253:0) with device flush
    Resuming vg01-pvmove0 (253:1).
    Resuming vg01-lvol1 (253:0).
    Creating volume group backup "/etc/lvm/backup/vg01" (seqno 18).
    activation/volume_list configuration setting not defined: Checking only host tags for vg01/pvmove0.
    Checking progress before waiting every 15 seconds.
  /dev/xvdf: Moved: 0.00%
  /dev/xvdf: Moved: 100.00%
    Polling finished successfully.

The interval at which command updates the progress can be changed. -i switch followed by a number of seconds can be used to get updates from command on user-defined intervals on progress.

root@kerneltalks # pvmove -i 1 /dev/xvdf

Boot SUSE Linux from old kernel after kernel upgrade

How to guide to boot Suse Linux from old kernel after kernel upgrade. 

Boot Suse Linux from old kernel after kernel upgrade

This article is basically a how-to guide for booting SUSE Linux system from the previous kernel after the kernel upgrade process. Normally, Linux like Red Hat has the option to just change boot priority of kernel in /etc/grub.conf and reboot into the kernel of your choice. But in SUSE Linux, we do not have that option. Now the question is how to boot into old kernel once I upgrade the kernel.

You can boot into the older kernel by using the below method. I explained kernel upgrade first and then how to uninstall update to boot from the older kernel. This is a kind of rollback kernel upgrade in SUSE Linux.

1. Upgrade kernel in Suse Linux

The first thing you want to check and confirm that if your SUSE supports multiversion or not.  Go to /etc/zypp/zypp.conf and make sure the below-mentioned line is not commented on. If there is # at the beginning of it, remove it.

multiversion = provides:multiversion(kernel)

There are many ways to maintain how many old kernel versions can be maintained by the system. We won’t be going through it. You can find more details about it here.

Once you are confirmed, multiversion is active then go ahead with kernel upgrade. If it’s not activated, zypper will auto-delete old kernel and you won’t be able to use it.

Check current kernel version

root@kerneltalks # uname -a
Linux kerneltalks 4.4.114-94.11-default #1 SMP Thu Feb 1 19:28:26 UTC 2018 (4309ff9) x86_64 x86_64 x86_64 GNU/Linux

Install the new kernel version using zypper.  Make sure you are installing the new kernel and not updating your current one.

root@kerneltalks # zypper in kernel-default
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 5 NEW packages are going to be installed:
  crash-kmp-default crda kernel-default-4.4.120-94.17.1 kernel-firmware
  wireless-regdb

5 new packages to install.
Overall download size: 81.3 MiB. Already cached: 0 B. After the operation,
additional 358.3 MiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package kernel-default-4.4.120-94.17.1.x86_64
                                           (1/5),  38.6 MiB (167.2 MiB unpacked)
Retrieving: kernel-default-4.4.120-94.17.1.x86_64.rpm ........[done (7.1 MiB/s)]
Retrieving package kernel-firmware-20170530-21.19.1.noarch
                                           (2/5),  42.5 MiB (191.1 MiB unpacked)
Retrieving: kernel-firmware-20170530-21.19.1.noarch.rpm .....[done (18.2 MiB/s)]
Retrieving package wireless-regdb-2017.12.23-4.3.1.noarch
                                           (3/5),  14.1 KiB ( 13.0 KiB unpacked)
Retrieving: wireless-regdb-2017.12.23-4.3.1.noarch.rpm ...................[done]
Retrieving package crash-kmp-default-7.1.8_k4.4.92_6.30-4.6.2.x86_64
                                           (4/5), 116.8 KiB (  7.8 KiB unpacked)
Retrieving: crash-kmp-default-7.1.8_k4.4.92_6.30-4.6.2.x86_64.rpm ........[done]
Retrieving package crda-1.1.3-4.2.1.x86_64 (5/5),  14.4 KiB ( 34.5 KiB unpacked)
Retrieving: crda-1.1.3-4.2.1.x86_64.rpm ..................................[done]
Checking for file conflicts: .............................................[done]
(1/5) Installing: kernel-default-4.4.120-94.17.1.x86_64 ..................[done]
Additional rpm output:
Creating initrd: /boot/initrd-4.4.120-94.17-default
dracut: Executing: /usr/bin/dracut --logfile /var/log/YaST2/mkinitrd.log --force                                                                                         /boot/initrd-4.4.120-94.17-default 4.4.120-94.17-default
dracut: dracut module 'btrfs' will not be installed, because command 'btrfs' cou                                                                                        ld not be found!
dracut: dracut module 'dmraid' will not be installed, because command 'dmraid' c                                                                                        ould not be found!
dracut: dracut module 'mdraid' will not be installed, because command 'mdadm' co                                                                                        uld not be found!
dracut: dracut module 'btrfs' will not be installed, because command 'btrfs' cou                                                                                        ld not be found!
dracut: dracut module 'dmraid' will not be installed, because command 'dmraid' c                                                                                        ould not be found!
dracut: dracut module 'mdraid' will not be installed, because command 'mdadm' co                                                                                        uld not be found!
dracut: *** Including module: bash ***
dracut: *** Including module: systemd ***
dracut: *** Including module: systemd-initrd ***
dracut: *** Including module: i18n ***
dracut: No KEYMAP configured.
dracut: *** Including module: xen-tools-domU ***
dracut: *** Including module: kernel-modules ***
dracut: *** Including module: rootfs-block ***
dracut: *** Including module: suse-xfs ***
dracut: *** Including module: terminfo ***
dracut: *** Including module: udev-rules ***
dracut: Skipping udev rule: 40-redhat.rules
dracut: Skipping udev rule: 50-firmware.rules
dracut: Skipping udev rule: 50-udev.rules
dracut: Skipping udev rule: 91-permissions.rules
dracut: Skipping udev rule: 80-drivers-modprobe.rules
dracut: *** Including module: dracut-systemd ***
dracut: *** Including module: haveged ***
dracut: *** Including module: usrmount ***
dracut: *** Including module: base ***
dracut: *** Including module: fs-lib ***
dracut: *** Including module: shutdown ***
dracut: *** Including module: suse ***
dracut: *** Including modules done ***
dracut: *** Installing kernel module dependencies and firmware ***
dracut: *** Installing kernel module dependencies and firmware done ***
dracut: *** Resolving executable dependencies ***
dracut: *** Resolving executable dependencies done***
dracut: *** Hardlinking files ***
dracut: *** Hardlinking files done ***
dracut: *** Stripping files ***
dracut: *** Stripping files done ***
dracut: *** Generating early-microcode cpio image ***
dracut: *** Store current command line parameters ***
dracut: Stored kernel commandline:
dracut:  root=UUID=26fa33a2-ad40-4a85-a495-402aca6a2127 rootfstype=ext4 rootflag                                                                                        s=rw,relatime,data=ordered
dracut: *** Creating image file '/boot/initrd-4.4.120-94.17-default' ***
dracut: *** Creating initramfs image file '/boot/initrd-4.4.120-94.17-default' d                                                                                        one ***


(2/5) Installing: kernel-firmware-20170530-21.19.1.noarch ................[done]
(3/5) Installing: wireless-regdb-2017.12.23-4.3.1.noarch .................[done]
(4/5) Installing: crash-kmp-default-7.1.8_k4.4.92_6.30-4.6.2.x86_64 ......[done]
(5/5) Installing: crda-1.1.3-4.2.1.x86_64 ................................[done]
Output of kernel-firmware-20170530-21.19.1.noarch.rpm %posttrans script:
    Creating initrd: /boot/initrd-4.4.114-94.11-default
    dracut: Executing: /usr/bin/dracut --logfile /var/log/YaST2/mkinitrd.log --f                                                                                        orce /boot/initrd-4.4.114-94.11-default 4.4.114-94.11-default
    dracut: dracut module 'btrfs' will not be installed, because command 'btrfs'                                                                                         could not be found!
    dracut: dracut module 'dmraid' will not be installed, because command 'dmrai                                                                                        d' could not be found!
    dracut: dracut module 'mdraid' will not be installed, because command 'mdadm                                                                                        ' could not be found!
    dracut: dracut module 'btrfs' will not be installed, because command 'btrfs'                                                                                         could not be found!
    dracut: dracut module 'dmraid' will not be installed, because command 'dmrai                                                                                        d' could not be found!
    dracut: dracut module 'mdraid' will not be installed, because command 'mdadm                                                                                        ' could not be found!
    dracut: *** Including module: bash ***
    dracut: *** Including module: systemd ***
    dracut: *** Including module: systemd-initrd ***
    dracut: *** Including module: i18n ***
    dracut: No KEYMAP configured.
    dracut: *** Including module: xen-tools-domU ***
    dracut: *** Including module: kernel-modules ***
    dracut: *** Including module: rootfs-block ***
    dracut: *** Including module: suse-xfs ***
    dracut: *** Including module: terminfo ***
    dracut: *** Including module: udev-rules ***
    dracut: Skipping udev rule: 40-redhat.rules
    dracut: Skipping udev rule: 50-firmware.rules
    dracut: Skipping udev rule: 50-udev.rules
    dracut: Skipping udev rule: 91-permissions.rules
    dracut: Skipping udev rule: 80-drivers-modprobe.rules
    dracut: *** Including module: dracut-systemd ***
    dracut: *** Including module: haveged ***
    dracut: *** Including module: usrmount ***
    dracut: *** Including module: base ***
    dracut: *** Including module: fs-lib ***
    dracut: *** Including module: shutdown ***
    dracut: *** Including module: suse ***
    dracut: *** Including modules done ***
    dracut: *** Installing kernel module dependencies and firmware ***
    dracut: *** Installing kernel module dependencies and firmware done ***
    dracut: *** Resolving executable dependencies ***
    dracut: *** Resolving executable dependencies done***
    dracut: *** Hardlinking files ***
    dracut: *** Hardlinking files done ***
    dracut: *** Stripping files ***
    dracut: *** Stripping files done ***
    dracut: *** Generating early-microcode cpio image ***
    dracut: *** Store current command line parameters ***
    dracut: Stored kernel commandline:
    dracut:  root=UUID=26fa33a2-ad40-4a85-a495-402aca6a2127 rootfstype=ext4 root                                                                                        flags=rw,relatime,data=ordered
    dracut: *** Creating image file '/boot/initrd-4.4.114-94.11-default' ***
    dracut: *** Creating initramfs image file '/boot/initrd-4.4.114-94.11-defaul                                                                                        t' done ***
    Creating initrd: /boot/initrd-4.4.120-94.17-default
    dracut: Executing: /usr/bin/dracut --logfile /var/log/YaST2/mkinitrd.log --f                                                                                        orce /boot/initrd-4.4.120-94.17-default 4.4.120-94.17-default
    dracut: dracut module 'btrfs' will not be installed, because command 'btrfs'                                                                                         could not be found!
    dracut: dracut module 'dmraid' will not be installed, because command 'dmrai                                                                                        d' could not be found!
    dracut: dracut module 'mdraid' will not be installed, because command 'mdadm                                                                                        ' could not be found!
    dracut: dracut module 'btrfs' will not be installed, because command 'btrfs'                                                                                         could not be found!
    dracut: dracut module 'dmraid' will not be installed, because command 'dmrai                                                                                        d' could not be found!
    dracut: dracut module 'mdraid' will not be installed, because command 'mdadm                                                                                        ' could not be found!
    dracut: *** Including module: bash ***
    dracut: *** Including module: systemd ***
    dracut: *** Including module: systemd-initrd ***
    dracut: *** Including module: i18n ***
    dracut: No KEYMAP configured.
    dracut: *** Including module: xen-tools-domU ***
    dracut: *** Including module: kernel-modules ***
    dracut: *** Including module: rootfs-block ***
    dracut: *** Including module: suse-xfs ***
    dracut: *** Including module: terminfo ***
    dracut: *** Including module: udev-rules ***
    dracut: Skipping udev rule: 40-redhat.rules
    dracut: Skipping udev rule: 50-firmware.rules
    dracut: Skipping udev rule: 50-udev.rules
    dracut: Skipping udev rule: 91-permissions.rules
    dracut: Skipping udev rule: 80-drivers-modprobe.rules
    dracut: *** Including module: dracut-systemd ***
    dracut: *** Including module: haveged ***
    dracut: *** Including module: usrmount ***
    dracut: *** Including module: base ***
    dracut: *** Including module: fs-lib ***
    dracut: *** Including module: shutdown ***
    dracut: *** Including module: suse ***
    dracut: *** Including modules done ***
    dracut: *** Installing kernel module dependencies and firmware ***
    dracut: *** Installing kernel module dependencies and firmware done ***
    dracut: *** Resolving executable dependencies ***
    dracut: *** Resolving executable dependencies done***
    dracut: *** Hardlinking files ***
    dracut: *** Hardlinking files done ***
    dracut: *** Stripping files ***
    dracut: *** Stripping files done ***
    dracut: *** Generating early-microcode cpio image ***
    dracut: *** Store current command line parameters ***
    dracut: Stored kernel commandline:
    dracut:  root=UUID=26fa33a2-ad40-4a85-a495-402aca6a2127 rootfstype=ext4 root                                                                                        flags=rw,relatime,data=ordered
    dracut: *** Creating image file '/boot/initrd-4.4.120-94.17-default' ***
    dracut: *** Creating initramfs image file '/boot/initrd-4.4.120-94.17-defaul                                                                                        t' done ***

Reboot system and you see your system is booted with the latest new kernel.

root@kerneltalks # uname -a
Linux kerneltalks 4.4.120-94.17-default #1 SMP Wed Mar 14 17:23:00 UTC 2018                                                                                         (cf3a7bb) x86_64 x86_64 x86_64 GNU/Linux

Now check all the installed kernel packages on your system using –

root@kerneltalks # zypper se -si 'kernel*'
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...

S  | Name            | Type    | Version          | Arch   | Repository
---+-----------------+---------+------------------+--------+-------------------
i+ | kernel-default  | package | 4.4.120-94.17.1  | x86_64 | SLES12-SP3-Updates
i+ | kernel-default  | package | 4.4.114-94.11.3  | x86_64 | SLES12-SP3-Updates
i  | kernel-firmware | package | 20170530-21.19.1 | noarch | SLES12-SP3-Updates

Here, you can see there are two kernels installed on the system. Old one is 4.4.114-94.11.3 and the new one is 4.4.120-94.17.1 from which the current system is booted.

2. Boot from the old kernel in SUSE Linux

For Suse with GRUB2

Now, if you want to boot the system from the old kernel 4.4.114-94.11.3 without un-installing new kernel then follow the below steps.

Make copy of /etc/default/grub file as a backup. and then edit it –

root@kerneltalks # cp /etc/default/grub /etc/default/grub.backup
root@kerneltalks # vi /etc/default/grub

Look for GRUB_DEFAULT=0and edit the number per old kernel menu number. Old kernel menu number can be found in /boot/grub2/grub.cfg

Open /boot/grub2/grub.cfg and look for entry menuentry You will be able to see different kernel entries in it. First being 0 and then counter goes on. Check and choose the menu number of your old kernel.

After editing /etc/default/grub file you need to re-create /boot/grub2/grub.cfg You can do it with below command –

root@kerneltalks # grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.120-94.17-default
Found initrd image: /boot/initrd-4.4.120-94.17-default
Found linux image: /boot/vmlinuz-4.4.114-94.11-default
Found initrd image: /boot/initrd-4.4.114-94.11-default
done

Once done, reboot the system. That’s it. You can see your system is booted with an old kernel while your new kernel is still installed on the server.

For Suse with GRUB

Edit /boot/grub/grub.conf which is also link to /boot/grub/menu.lst . Look for parameter default 0 and change the number 0 to your desired kernel menu number.

You can see the kernel list to be displayed later in the same file. Remember, the numbering starts at 0. So countdown to your old kernel version number and use it for the default parameter.

Save the file and reboot the system. You will be booted with old kernel.

3. Rollback to old kernel in SUSE Linux

Now if you want to rollback system to the old kernel 4.4.114-94.11.3, remove this latest installed kernel 4.4.120-94.17.1. You need to give kernel name as <package_name>-<package_version>. You can get the version from the above command output. In this way, we are downgrading kernel in SUSE Linux.

root@kerneltalks # zypper rm kernel-default-4.4.120-94.17.1
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following package is going to be REMOVED:
  kernel-default-4.4.120-94.17.1

1 package to remove.
After the operation, 167.2 MiB will be freed.
Continue? [y/n/...? shows all options] (y): y
(1/1) Removing kernel-default-4.4.120-94.17.1.x86_64 .............................................................................................................[done]
There are some running programs that might use files deleted by recent upgrade. You may wish to check and restart some of them. Run 'zypper ps -s' to list these programs.

Now as per warning lets check which all processes are using it.

root@kerneltalks # zypper ps -s
The following running processes use deleted files:

PID | PPID | UID | User | Command       | Service
----+------+-----+------+---------------+--------------
486 | 1    | 0   | root | systemd-udevd | systemd-udevd

You may wish to restart these processes.
See 'man zypper' for information about the meaning of values in the above table.

Lets reboot system and check kernel version.

root@kerneltalks # uname -a
Linux kerneltalks 4.4.114-94.11-default #1 SMP Thu Feb 1 19:28:26 UTC 2018 (4309ff9) x86_64 x86_64 x86_64 GNU/Linux

You can see the system is booted with your old kernel 4.4.114-94.11.3!

Now, Check installed kernel packages and you can see a newer kernel package is no more installed/active on the system.

root@kerneltalks # zypper se -si 'kernel*'
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...

S  | Name            | Type    | Version          | Arch   | Repository
---+-----------------+---------+------------------+--------+-------------------
i+ | kernel-default  | package | 4.4.114-94.11.3  | x86_64 | SLES12-SP3-Updates
i  | kernel-firmware | package | 20170530-21.19.1 | noarch | SLES12-SP3-Updates

If you have another method (command line) to boot into the older kernel then please share in the comments below.

VMware tools not running after Linux kernel upgrade

Solution for VMware tools not running after Linux kernel upgrade in guest VM

VMware tools not running after Linux kernel upgrade

In this article, we will discuss solutions when VMware tools are not running after the Linux kernel upgrade.

Cause :

After kernel upgrade in the Guest VM Linux machine, you may see VMware tools are not running. This is because there are VMware tools modules that runs using kernel library files. After a kernel upgrade, they point to different library files than the one currently used by the kernel and hence failed to start.

Solution :

The issue can be resolved by reconfiguring VMware tools after the kernel upgrade. This process is on the fly and does not require downtime.

Login to Guest Linux operating system using root account and run reconfiguration script /usr/bin/vmware-config-tools.pl

You will be asked a few choices to make. If you know about those modules you choose your answers according to your requirement and just hit enter to accept defaults.  See below sample output –

root@kerneltalks # /usr/bin/vmware-config-tools.pl
Initializing...
Making sure services for VMware Tools are stopped.
Found a compatible pre-built module for vmci.  Installing it...
Found a compatible pre-built module for vsock.  Installing it...
The module vmxnet3 has already been installed on this system by another
installer or package and will not be modified by this installer.

The module pvscsi has already been installed on this system by another
installer or package and will not be modified by this installer.

The module vmmemctl has already been installed on this system by another
installer or package and will not be modified by this installer.

The VMware Host-Guest Filesystem allows for shared folders between the host OS
and the guest OS in a Fusion or Workstation virtual environment.  Do you wish
to enable this feature? [no]

Found a compatible pre-built module for vmxnet.  Installing it...


The vmblock enables dragging or copying files between host and guest in a
Fusion or Workstation virtual environment.  Do you wish to enable this feature?
[no]

VMware automatic kernel modules enables automatic building and installation of
VMware kernel modules at boot that are not already present. This feature can
be enabled/disabled by re-running vmware-config-tools.pl.

Would you like to enable VMware automatic kernel modules?
[no]

Do you want to enable Guest Authentication (vgauth)? Enabling vgauth is needed
if you want to enable Common Agent (caf). [yes]

Do you want to enable Common Agent (caf)? [yes]

No X install found.

Creating a new initrd boot image for the kernel.

NOTE: both /etc/vmware-tools/GuestProxyData/server/key.pem and
      /etc/vmware-tools/GuestProxyData/server/cert.pem already exist.
      They are not generated again. To regenerate them by force,
      use the "vmware-guestproxycerttool -g -f" command.

vmware-tools start/running
The configuration of VMware Tools 10.0.6 build-3560309 for Linux for this
running kernel completed successfully.

You must restart your X session before any mouse or graphics changes take
effect.

You can now run VMware Tools by invoking "/usr/bin/vmware-toolbox-cmd" from the
command line.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and
file and text copy/paste), you will need to do one (or more) of the following:
1. Manually start /usr/bin/vmware-user
2. Log out and log back into your desktop session; and,
3. Restart your X session.

Enjoy,

--the VMware team

If you are ok to accept the default and want the script to run non-interactive, run it with -d default switch.

root@kerneltalks # /usr/bin/vmware-config-tools.pl -d default

Once, the script finishes execution you can see in VMware console that it shows VMware tools are running on guest VM!

Failed to mount cd error in Zypper

Troubleshooting to get rid of failed to mount CD error due to CD repo in zypper.

Failed to mount cd error in Zypper

Error :

While trying to install the package in zypper I came across below error :

Failed to mount cd:///?devices=/dev/disk/by-id/ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001 on /var/adm/mount/AP_0xFre2nn: Mounting media failed (mount: no medium found on /dev/sr0)

Detailed error snippet below :

# zypper in salt-minion
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 16 NEW packages are going to be installed:
  libzmq3 python-Jinja2 python-MarkupSafe python-PyYAML python-backports.ssl_match_hostname python-futures python-msgpack-python python-netaddr python-psutil
  python-pycrypto python-pyzmq python-requests python-simplejson python-tornado salt salt-minion

The following 2 recommended packages were automatically selected:
  python-futures python-netaddr

The following 15 packages are not supported by their vendor:
  libzmq3 python-Jinja2 python-MarkupSafe python-PyYAML python-backports.ssl_match_hostname python-futures python-msgpack-python python-psutil python-pycrypto
  python-pyzmq python-requests python-simplejson python-tornado salt salt-minion

16 new packages to install.
Overall download size: 9.0 MiB. Already cached: 0 B. After the operation, additional 48.0 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package python-netaddr-0.7.10-8.5.noarch                                                                       (1/16), 896.9 KiB (  4.2 MiB unpacked)
Failed to mount cd:///?devices=/dev/disk/by-id/ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001 on /var/adm/mount/AP_0xFre2nn: Mounting media failed (mount: no medium found on /dev/sr0)

Please insert medium [SLES12-SP1-12.1-0] #1 and type 'y' to continue or 'n' to cancel the operation. [yes/no] (no): n
Problem occured during or after installation or removal of packages:
Installation aborted by user

Please see the above error message for a hint.

Cause :

This error is nothing but zypper trying to read repo information from CD/DVD. Since one of the zypper repo is configured to look for mountable media, it’s doing its job. But, currently, that media is not connected to the system, and hence zypper is failing to read details from it.

Solution :

List your zypper repo using the command :

# zypper lr --details
# | Alias                | Name                 | Enabled | GPG Check | Refresh | Priority | Type   | URI                                                                                    | Service
--+----------------------+----------------------+---------+-----------+---------+----------+--------+----------------------------------------------------------------------------------------+--------
1 | SLES12-SP1-12.1-0    | SLES12-SP1-12.1-0    | Yes     | (r ) Yes  | No      |   99     | yast2  | cd:///?devices=/dev/disk/by-id/ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001 |
2 | sles12-sp1-bootstrap | sles12-sp1-bootstrap | Yes     | ( p) Yes  | No      |   99     | rpm-md | http://repo.kerneltalks.com/pub/repositories/sle/12/1/bootstrap                 |

Here you can see first repo’s URI is pointing to a CD. Now you can mount the CD or you can disable that repo for time being and move ahead with the installation.

Use the below command to disable CD repo. Make sure you enter correct repo number in command (here it’s 1)

# zypper mr --disable 1
Repository 'SLES12-SP1-12.1-0' has been successfully disabled.

Once CD/DVD repo is disabled successfully, re-run zypper installation command and you will be able to execute it without any errors!

# zypper in salt-minion
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 15 NEW packages are going to be installed:
  libzmq3 python-Jinja2 python-MarkupSafe python-PyYAML python-backports.ssl_match_hostname python-futures python-msgpack-python python-psutil python-pycrypto
  python-pyzmq python-requests python-simplejson python-tornado salt salt-minion

The following recommended package was automatically selected:
  python-futures

The following 15 packages are not supported by their vendor:
  libzmq3 python-Jinja2 python-MarkupSafe python-PyYAML python-backports.ssl_match_hostname python-futures python-msgpack-python python-psutil python-pycrypto
  python-pyzmq python-requests python-simplejson python-tornado salt salt-minion

15 new packages to install.
Overall download size: 8.1 MiB. Already cached: 0 B. After the operation, additional 43.8 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package python-backports.ssl_match_hostname-3.4.0.2-17.1.noarch                                                (1/15),  10.4 KiB ( 14.3 KiB unpacked)
Retrieving: python-backports.ssl_match_hostname-3.4.0.2-17.1.noarch.rpm ..................................................................................[done]
Retrieving package python-futures-3.0.2-7.1.noarch                                                                        (2/15),  23.5 KiB ( 85.6 KiB unpacked)
Retrieving: python-futures-3.0.2-7.1.noarch.rpm ..........................................................................................................[done]
Retrieving package python-requests-2.11.1-6.20.1.noarch                                                                   (3/15), 396.8 KiB (  1.9 MiB unpacked)
Retrieving: python-requests-2.11.1-6.20.1.noarch.rpm .....................................................................................................[done]
Retrieving package libzmq3-4.0.4-6.1.x86_64                                                                               (4/15), 278.6 KiB (676.6 KiB unpacked)
Retrieving: libzmq3-4.0.4-6.1.x86_64.rpm .................................................................................................................[done]
Retrieving package python-MarkupSafe-0.18-7.1.x86_64                                                                      (5/15),  24.6 KiB ( 66.0 KiB unpacked)
Retrieving: python-MarkupSafe-0.18-7.1.x86_64.rpm ........................................................................................................[done]
Retrieving package python-PyYAML-3.12-25.1.x86_64                                                                         (6/15), 154.6 KiB (625.5 KiB unpacked)
Retrieving: python-PyYAML-3.12-25.1.x86_64.rpm ...........................................................................................................[done]
Retrieving package python-msgpack-python-0.4.6-2.1.x86_64                                                                 (7/15),  67.0 KiB (221.0 KiB unpacked)
Retrieving: python-msgpack-python-0.4.6-2.1.x86_64.rpm ...................................................................................................[done]
Retrieving package python-psutil-1.2.1-9.1.x86_64                                                                         (8/15), 100.3 KiB (444.6 KiB unpacked)
Retrieving: python-psutil-1.2.1-9.1.x86_64.rpm ...........................................................................................................[done]
Retrieving package python-pycrypto-2.6.1-4.1.x86_64                                                                       (9/15), 371.5 KiB (  2.0 MiB unpacked)
Retrieving: python-pycrypto-2.6.1-4.1.x86_64.rpm .........................................................................................................[done]
Retrieving package python-simplejson-3.8.2-4.1.x86_64                                                                    (10/15), 105.0 KiB (384.5 KiB unpacked)
Retrieving: python-simplejson-3.8.2-4.1.x86_64.rpm .......................................................................................................[done]
Retrieving package python-pyzmq-14.0.0-3.1.x86_64                                                                        (11/15), 510.3 KiB (  1.5 MiB unpacked)
Retrieving: python-pyzmq-14.0.0-3.1.x86_64.rpm ...........................................................................................................[done]
Retrieving package python-Jinja2-2.7.3-17.1.noarch                                                                       (12/15), 278.5 KiB (  1.7 MiB unpacked)
Retrieving: python-Jinja2-2.7.3-17.1.noarch.rpm ..........................................................................................................[done]
Retrieving package python-tornado-4.2.1-9.1.x86_64                                                                       (13/15), 547.1 KiB (  2.8 MiB unpacked)
Retrieving: python-tornado-4.2.1-9.1.x86_64.rpm ..........................................................................................................[done]
Retrieving package salt-2016.11.4-45.2.x86_64                                                                            (14/15),   5.2 MiB ( 31.4 MiB unpacked)
Retrieving: salt-2016.11.4-45.2.x86_64.rpm ...............................................................................................................[done]
Retrieving package salt-minion-2016.11.4-45.2.x86_64                                                                     (15/15), 107.8 KiB ( 36.9 KiB unpacked)
Retrieving: salt-minion-2016.11.4-45.2.x86_64.rpm ........................................................................................................[done]
Checking for file conflicts: .............................................................................................................................[done]
( 1/15) Installing: python-backports.ssl_match_hostname-3.4.0.2-17.1 .....................................................................................[done]
( 2/15) Installing: python-futures-3.0.2-7.1 .............................................................................................................[done]
( 3/15) Installing: python-requests-2.11.1-6.20.1 ........................................................................................................[done]
( 4/15) Installing: libzmq3-4.0.4-6.1 ....................................................................................................................[done]
( 5/15) Installing: python-MarkupSafe-0.18-7.1 ...........................................................................................................[done]
( 6/15) Installing: python-PyYAML-3.12-25.1 ..............................................................................................................[done]
( 7/15) Installing: python-msgpack-python-0.4.6-2.1 ......................................................................................................[done]
( 8/15) Installing: python-psutil-1.2.1-9.1 ..............................................................................................................[done]
( 9/15) Installing: python-pycrypto-2.6.1-4.1 ............................................................................................................[done]
(10/15) Installing: python-simplejson-3.8.2-4.1 ..........................................................................................................[done]
(11/15) Installing: python-pyzmq-14.0.0-3.1 ..............................................................................................................[done]
(12/15) Installing: python-Jinja2-2.7.3-17.1 .............................................................................................................[done]
(13/15) Installing: python-tornado-4.2.1-9.1 .............................................................................................................[done]
(14/15) Installing: salt-2016.11.4-45.2 ..................................................................................................................[done]
(15/15) Installing: salt-minion-2016.11.4-45.2 ...........................................................................................................[done]

You can re-enable CD/DVD repo when you have the related device mounted on the server.

How to upgrade kernel in RHEL, Suse, Ubuntu Linux

Step by step procedure to upgrade kernel in RHEL, Suse, and Ubuntu Linux along with sample outputs of all the commands.

Upgrade kernel in RHEL, Suse, and Ubuntu Linux

How to check current kernel & patch level in Linux

You can confirm current kernel version & patch level using uname -r and uname -v command.

root@kerneltlks # uname -v
#1 SMP Sun Jul 27 15:55:46 EDT 2014
root@kerneltalks # uname -r
2.6.32-431.29.2.el6.x86_64

-r switch gives you your current kernel version. -v gives you your current patch level. You can see in the above output our RHEL6 system has 2014 (almost 4 years old) patched kernel. We will patch it to the latest one in this article.

How to upgrade the kernel in RHEL

Patching kernel is Linux is the same as upgrading to the latest kernel. Make sure you have yum configured properly to receive the latest packages from trusted repositories. If you do not have/want yum configurations, you can download the latest kernel and its dependencies from the Red Hat portal and keep it ready on the server for installation.

Never replace the existing kernel by updating the package. Always install a new kernel package so that your old kernel still resides on the server and you can boot it if your server/application is not behaving well with the new kernel.

To install the latest kernel, use rpm -ivh <rpm names> or yum install kernel command.

root@kerneltalks # yum install kernel
Loaded plugins: amazon-id, rhui-lb, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:2.6.32-696.20.1.el6 will be installed
--> Processing Dependency: dracut-kernel >= 004-408.el6 for package: kernel-2.6.32-696.20.1.el6.x86_64
--> Processing Dependency: kernel-firmware >= 2.6.32-696.20.1.el6 for package: kernel-2.6.32-696.20.1.el6.x86_64
--> Running transaction check
---> Package dracut-kernel.noarch 0:004-336.el6_5.2 will be updated
---> Package dracut-kernel.noarch 0:004-409.el6_8.2 will be an update
--> Processing Dependency: dracut = 004-409.el6_8.2 for package: dracut-kernel-004-409.el6_8.2.noarch
---> Package kernel-firmware.noarch 0:2.6.32-431.29.2.el6 will be updated
---> Package kernel-firmware.noarch 0:2.6.32-696.20.1.el6 will be an update
--> Running transaction check
---> Package dracut.noarch 0:004-336.el6_5.2 will be updated
---> Package dracut.noarch 0:004-409.el6_8.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                        Version                                   Repository                                             Size
========================================================================================================================================================================
Installing:
 kernel                               x86_64                      2.6.32-696.20.1.el6                       rhui-REGION-rhel-server-releases                       32 M
Updating for dependencies:
 dracut                               noarch                      004-409.el6_8.2                           rhui-REGION-rhel-server-releases                      127 k
 dracut-kernel                        noarch                      004-409.el6_8.2                           rhui-REGION-rhel-server-releases                       28 k
 kernel-firmware                      noarch                      2.6.32-696.20.1.el6                       rhui-REGION-rhel-server-releases                       29 M

Transaction Summary
========================================================================================================================================================================
Install       1 Package(s)
Upgrade       3 Package(s)

Total download size: 61 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): dracut-004-409.el6_8.2.noarch.rpm                                                                                                         | 127 kB     00:00
(2/4): dracut-kernel-004-409.el6_8.2.noarch.rpm                                                                                                  |  28 kB     00:00
(3/4): kernel-2.6.32-696.20.1.el6.x86_64.rpm                                                                                                     |  32 MB     00:00
(4/4): kernel-firmware-2.6.32-696.20.1.el6.noarch.rpm                                                                                            |  29 MB     00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    45 MB/s |  61 MB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : dracut-004-409.el6_8.2.noarch                                                                                                                        1/7
  Updating   : dracut-kernel-004-409.el6_8.2.noarch                                                                                                                 2/7
  Updating   : kernel-firmware-2.6.32-696.20.1.el6.noarch                                                                                                           3/7
  Installing : kernel-2.6.32-696.20.1.el6.x86_64                                                                                                                    4/7
  Cleanup    : dracut-kernel-004-336.el6_5.2.noarch                                                                                                                 5/7
  Cleanup    : dracut-004-336.el6_5.2.noarch                                                                                                                        6/7
  Cleanup    : kernel-firmware-2.6.32-431.29.2.el6.noarch                                                                                                           7/7
  Verifying  : kernel-firmware-2.6.32-696.20.1.el6.noarch                                                                                                           1/7
  Verifying  : kernel-2.6.32-696.20.1.el6.x86_64                                                                                                                    2/7
  Verifying  : dracut-kernel-004-409.el6_8.2.noarch                                                                                                                 3/7
  Verifying  : dracut-004-409.el6_8.2.noarch                                                                                                                        4/7
  Verifying  : dracut-004-336.el6_5.2.noarch                                                                                                                        5/7
  Verifying  : kernel-firmware-2.6.32-431.29.2.el6.noarch                                                                                                           6/7
  Verifying  : dracut-kernel-004-336.el6_5.2.noarch                                                                                                                 7/7

Installed:
  kernel.x86_64 0:2.6.32-696.20.1.el6

Dependency Updated:
  dracut.noarch 0:004-409.el6_8.2                  dracut-kernel.noarch 0:004-409.el6_8.2                  kernel-firmware.noarch 0:2.6.32-696.20.1.el6

Complete!

If you are on a test system and don’t mind wiping out old kernel then you can directly use yum update kernel or rpm -Uvh <rpms> command and update kernel.

If you observe, yum resolved dependencies too. If you are opting to install from rpm you need to download all dependencies as well. Here is the list of dependencies depending on your RHEL version :

RHEL4 kernel package upgrade dependencies:kernel-smp, kernel-largesmp, kernel-hugemem
RHEL5 kernel package upgrade dependencies:kernel-PAE, kernel-xen
RHEL6 kernel package upgrade dependencies: kernel-firmware
RHEL7 kernel package upgrade dependencies:dracut, dracut-network, dracut-config-rescue

Now, if you observe,/boot/grub/grub.conf your newly installed kernel entry is added before your old kernel entry. This gives new kernel priority to boot when you reboot the system. parameter default=0 says the system needs to be booted from the very first kernel defined below. Kernel entries numbering starts from 0. Make sure this parameter value points to your newly installed kernel and reboot the system.

# cat /boot/grub/grub.conf
default=0
timeout=1
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.32-696.20.1.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-696.20.1.el6.x86_64 console=ttyS0 ro root=UUID=9996863e-b964-47d3-a33b-3920974fdbd9 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 xen_blkfront.sda_is_xvda=1 console=ttyS0,115200n8 console=tty0 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM
        initrd /boot/initramfs-2.6.32-696.20.1.el6.x86_64.img
title Red Hat Enterprise Linux (2.6.32-431.29.2.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-431.29.2.el6.x86_64 console=ttyS0 ro root=UUID=9996863e-b964-47d3-a33b-3920974fdbd9 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 xen_blkfront.sda_is_xvda=1 console=ttyS0,115200n8 console=tty0 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM
        initrd /boot/initramfs-2.6.32-431.29.2.el6.x86_64.img

After rebooting, you can see your system is running with a new updated kernel!

root@kerneltalks # reboot

Broadcast message from root@kerneltalks
        (/dev/pts/0) at 2:14 ...

The system is going down for reboot NOW!

root@kerneltalks # uname -r
2.6.32-696.20.1.el6.x86_64
root@kerneltalks # uname -v
#1 SMP Fri Jan 12 15:07:59 EST 2018

You can see kernel is upgraded from 2.6.32-431.29.2.el6.x86_64 to 2.6.32-696.20.1.el6.x86_64. And patch level from July 2014 to Jan 2018.

How to upgrade the kernel in Suse Linux

Let’s start with checking current kernel version and patch info.

root@kerneltalks # uname -r
3.0.101-108.21-default
root@kerneltalks # uname -v
#1 SMP Fri Dec 29 10:25:37 UTC 2017 (5f5299b)

Perform kernel upgrade with zypper or if you have kernel rpm package with you, you can use rpm -ivh <kernel_rpm_path> to perform the multi-kernel install (not update)

You have an option to perform distribution upgrade using zypper dup as well which includes updating all packages to available updates. But most of the cases it’s not recommended.

# zypper up kernel-default
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following packages are going to be upgraded:
  kernel-default kernel-default-base

2 packages to upgrade.
Overall download size: 40.2 MiB. After the operation, additional 1.2 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package kernel-default-base-3.0.101-108.35.1.x86_64 (1/2), 15.7 MiB (23.2 MiB unpacked)
Retrieving: kernel-default-base-3.0.101-108.35.1.x86_64.rpm [done]
Retrieving package kernel-default-3.0.101-108.35.1.x86_64 (2/2), 24.5 MiB (86.1 MiB unpacked)
Retrieving: kernel-default-3.0.101-108.35.1.x86_64.rpm [done]
Installing: kernel-default-base-3.0.101-108.35.1 [done]
Additional rpm output:

Kernel image:   /boot/vmlinuz-3.0.101-108.35-default
Initrd image:   /boot/initrd-3.0.101-108.35-default
Root device:    /dev/hda1 (mounted on / as ext3)
Kernel Modules: xen-platform-pci xen-vbd-upstream xen-vbd xen-balloon xen-vnif scsi_mod libata ata_piix jbd mbcache ext3 edd usb-common usbcore ehci-hcd ohci-hcd uhci-hcd xhci-hcd crc-t10dif sd_mod
Features:       acpi fv_guest block resume.userspace resume.kernel
32723 blocks


Installing: kernel-default-3.0.101-108.35.1 [done]
Additional rpm output:

Kernel image:   /boot/vmlinuz-3.0.101-108.35-default
Initrd image:   /boot/initrd-3.0.101-108.35-default
Root device:    /dev/hda1 (mounted on / as ext3)
Kernel Modules: hwmon thermal_sys thermal processor fan xen-platform-pci xen-vbd-upstream xen-vbd xen-balloon xen-vnif scsi_mod libata ata_piix ata_generic jbd mbcache ext3 edd usb-common usbcore ehci-hcd ohci-hcd uhci-hcd xhci-hcd hid usbhid crc-t10dif sd_mod
Features:       acpi fv_guest block usb resume.userspace resume.kernel
33630 blocks

# reboot
Broadcast message from root (pts/0) (Sat Mar  3 04:47:12 2018):

The system is going down for reboot NOW!

Reboot the system and then check new kernel version.

# uname -r
3.0.101-108.35-default
# uname -v
#1 SMP Mon Feb 19 21:13:08 UTC 2018 (251ec24)

You can see the kernel is upgraded from 3.0.101-108.21-default to 3.0.101-108.35-default. And patch date from Dec 2017 to Feb 2018!

How to upgrade the kernel in Ubuntu Linux

Start with checking your current kernel version and patching date

# uname -v
#16-Ubuntu SMP Fri Jan 20 15:31:12 UTC 2017
# uname -r
4.9.0-15-generic

Now visit the Ubuntu Kernel page and download the kernel of your choice which is matching with your server arch using wget. We chose to upgrade to 4.10 kernel. Since we have generic kernel we downloaded generic kernel files from 4.10 directory.

root@kerneltalks # wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
--2018-03-03 05:03:15--  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
Resolving kernel.ubuntu.com (kernel.ubuntu.com)... 91.189.94.216
Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 659514 (644K) [application/x-debian-package]
Saving to: ‘linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’

linux-headers-4.10.1-041001-generic_4.10. 100%[=====================================================================================>] 644.06K  1.32MB/s    in 0.5s

2018-03-03 05:03:16 (1.32 MB/s) - ‘linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’ saved [659514/659514]

root@kerneltalks # wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
--2018-03-03 05:03:24--  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
Resolving kernel.ubuntu.com (kernel.ubuntu.com)... 91.189.94.216
Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 59573112 (57M) [application/x-debian-package]
Saving to: ‘linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’

linux-image-4.10.1-041001-generic_4.10.1- 100%[=====================================================================================>]  56.81M   744KB/s    in 2m 40s

2018-03-03 05:06:05 (363 KB/s) - ‘linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’ saved [59573112/59573112]

root@kerneltalks # wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb
--2018-03-03 05:06:10--  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb
Resolving kernel.ubuntu.com (kernel.ubuntu.com)... 91.189.94.216
Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10345532 (9.9M) [application/x-debian-package]
Saving to: ‘linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb’

linux-headers-4.10.1-041001_4.10.1-041001 100%[=====================================================================================>]   9.87M   932KB/s    in 14s

2018-03-03 05:06:24 (739 KB/s) - ‘linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb’ saved [10345532/10345532]

Now install these kernel packages using dpkg command with -i switch.

root@kerneltalks # dpkg -i *.deb
Selecting previously unselected package linux-headers-4.10.1-041001.
(Reading database ... 56103 files and directories currently installed.)
Preparing to unpack linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb ...
Unpacking linux-headers-4.10.1-041001 (4.10.1-041001.201702260735) ...
Selecting previously unselected package linux-headers-4.10.1-041001-generic.
Preparing to unpack linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb ...
Unpacking linux-headers-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Selecting previously unselected package linux-image-4.10.1-041001-generic.
Preparing to unpack linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb ...
Done.
Unpacking linux-image-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Setting up linux-headers-4.10.1-041001 (4.10.1-041001.201702260735) ...
Setting up linux-headers-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Setting up linux-image-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
update-initramfs: Generating /boot/initrd.img-4.10.1-041001-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
run-parts: executing /etc/kernel/postinst.d/x-grub-legacy-ec2 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-4.9.0-15-generic
Found kernel: /boot/vmlinuz-4.10.1-041001-generic
Found kernel: /boot/vmlinuz-4.9.0-15-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done

run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.10.1-041001-generic
Found initrd image: /boot/initrd.img-4.10.1-041001-generic
Found linux image: /boot/vmlinuz-4.9.0-15-generic
Found initrd image: /boot/initrd.img-4.9.0-15-generic
done

After a successful install, reboot the system and check new kernel version.

root@kerneltalks # reboot

root@kerneltalks # uname -v
#201702260735 SMP Sun Feb 26 12:36:48 UTC 2017
root@kerneltalks # uname -r
4.10.1-041001-generic

You can see kernel is upgraded to 4.10.1-041001-generic from 4.9.0-15-generic. And patch date from Jan 2017 to Feb 2017.