How can I check from the command line if a reboot is required on RHEL or CentOS?
Solution 1
https://access.redhat.com/discussions/3106621#comment-1196821
Don't forget that you might need to reboot because of core library updates, at least if it is glibc. (And also, services may need to be restarted after updates).
If you install the
yum-utils
package, you can use a command calledneeds-restarting
.You can use it both for checking if a full reboot is required because of kernel or core libraries updates (using the
-r
option), or what services need to be restarted (using the-s
option).
needs-restarting -r
returns0
if reboot is not needed, and1
if it is, so it is perfect to use in a script.An example:
root@server1:~> needs-restarting -r ; echo $?
Core libraries or services have been updated:
openssl-libs -> 1:1.0.1e-60.el7_3.1
systemd -> 219-30.el7_3.9
Reboot is required to ensure that your system benefits from these updates.
More information:
https://access.redhat.com/solutions/27943
1
Solution 2
About comparing installed kernels with running one:
#!/bin/bash
LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1)
CURRENT_KERNEL=$(uname -r)
test $LAST_KERNEL = $CURRENT_KERNEL || echo REBOOT
Hope that helps!
Solution 3
One thing that can be helpful to look at in terms of "is a reboot required" is whether or not there are any files that have been removed/replaced by the update but for which the old files are still loaded/used by active processes.
Basically, when YUM updates a file that is in use by a process, the file itself may have been marked for deletion, but the process keeps using the old file since it has an open file-descriptor to the old file's inode.
A command to get a count of the number of old files still in use:
#lsof | grep "(path inode=.*)" | wc -l
That command will give you a count of the files.
Use this instead to see which files are actually in use:
#lsof | grep "(path inode=.*)"
That command will produce output similar to the following on a YUM-updated box:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 3782 root mem REG 8,17 153427 /lib64/libcrypto.so.0.9.8e (path inode=153253)
mysqld 3883 mysql mem REG 8,17 153259 /lib64/libcrypt-2.5.so (path inode=153402)
mingetty 4107 root mem REG 8,17 153243 /lib64/libc-2.5.so (path inode=153222)
...
etc
Solution 4
You could compare the ouput of uname -a with the list of installed kernel packages
Solution 5
uname -a
vs. rpm -q kernel
and needs-restarting
from yum-utils
Related videos on Youtube
Jim Hunziker
Updated on September 18, 2022Comments
-
Jim Hunziker almost 2 years
I'm using CentOS and Red Hat Enterprise Linux on a few machines without the GUI. How can I check if recently installed updates require a reboot? In Ubuntu, I'm used to checking if
/var/run/reboot-required
is present. -
Chris_K over 14 yearsIs a different kernel the only reason a linux server would need a reboot?
-
Dominik over 14 yearsNormally, when staying within the 'normal' package upgrade processes (up2date, yum etc.), there shouldn't be really many other reasons to reboot the system besides the kernel upgrade
-
nhed almost 11 yearsI suspect that certain other packages may require a reboot eben iof the kernel does not change (when I installed kexec-tools-2.0.0-258 on centos6.0 there was no memory reserved for the dump)
-
Yanick Girouard almost 11 yearsThis doesn't work if you have a PAE enabled kernel version. The uname -r comamnd returns the PAE suffix after the .elX part but not the rpm names.
-
Programster almost 10 yearsAt first I thought this wasn't working as it continued to tell me to reboot after I had, but then found out that if you are using a DigitalOcean instance, you need to manually change the kernel from their control panel first before rebooting.
-
bshacklett over 9 yearsBeyondTrust's pbis-open package requests the user to reboot after installation via stdout.
-
Zlemini over 7 yearsIs there a reason why the
kernel-
string is being removed from the output ofrpm -q
? -
Paul Gear about 5 yearsIt's worth mentioning that at least the
-s
option requires root access. -
Franklin Yu about 5 years
-
msanford almost 4 yearsIs this a reliable way to detect kernel updates (obviating the need for me also to check that)?
-
reinierpost over 3 yearsCentOS 6 doesn't support
-r
, either, and theneeds-restarting
it has is not good enough (doesn't notice when a newer kernel is available). -
papanito over 2 years
$?
still is1
, even soneeds-restarting -r
saysNo core libraries or services have been updated.