m (Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux")
m
 
Line 2: Line 2:
  
 
The following script was pulled from one of my setup scripts.
 
The following script was pulled from one of my setup scripts.
<syntaxhighlight lang="bash">
+
{{highlight|lang=bash|code=
 
function install_new_kernel() {
 
function install_new_kernel() {
  
if ! yum repolist | grep elrepo > /dev/null ; then
+
if ! yum repolist {{!}} grep elrepo > /dev/null ; then
 
echo "This will now install the ELRepo repository from ELRepo.org."
 
echo "This will now install the ELRepo repository from ELRepo.org."
 
if ! prompt "Do you wish to install ELRepo on the system?" Y ; then
 
if ! prompt "Do you wish to install ELRepo on the system?" Y ; then
Line 24: Line 24:
 
# Install the mainline kernel
 
# Install the mainline kernel
 
yum install kernel-ml kernel-ml-devel kernel-ml-headers \
 
yum install kernel-ml kernel-ml-devel kernel-ml-headers \
|| die "Could not install kernel."
+
{{!}}{{!}} die "Could not install kernel."
  
Option=`awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg | /bin/grep -n 3.17 | head -n 1 | cut -f1 -d:`
+
Option=`awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg {{!}} /bin/grep -n 3.17 {{!}} head -n 1 {{!}} cut -f1 -d:`
  
 
echo "Current kernels installed:"
 
echo "Current kernels installed:"
 
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
 
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
 
echo "-- End of List --"
 
echo "-- End of List --"
echo "Kernel made to boot will be: " $(awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg | sed -n "$Option{p;q}")
+
echo "Kernel made to boot will be: " $(awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg {{!}} sed -n "$Option{p;q}")
 
 
 
if prompt "Is this okay?" Y ; then
 
if prompt "Is this okay?" Y ; then
Line 46: Line 46:
  
 
install_new_kernel
 
install_new_kernel
</syntaxhighlight>
+
}}
  
 
{{Navbox Linux}}[[Category:Linux]]
 
{{Navbox Linux}}[[Category:Linux]]

Latest revision as of 16:21, 30 November 2019

The following script will install the mainline kernel from ElRepo. The mainline kernel will be the most recent stable kernel rather than the more conservative kernel used in CentOS.

The following script was pulled from one of my setup scripts.

function install_new_kernel() {

	if ! yum repolist | grep elrepo > /dev/null ; then
		echo "This will now install the ELRepo repository from ELRepo.org."
		if ! prompt "Do you wish to install ELRepo on the system?" Y ; then
			return
		fi

		rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
		rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
		yum clean all
	fi

	# Need to enable the repo.
	sed -i '/\[elrepo-kernel\]/,/^\[/ s/enabled=0/enabled=1/' /etc/yum.repos.d/elrepo.repo

	# Should do a full update first.
	yum update

	# Install the mainline kernel
	yum install kernel-ml kernel-ml-devel kernel-ml-headers \
		|| die "Could not install kernel."

	Option=`awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg | /bin/grep -n 3.17 | head -n 1 | cut -f1 -d:`

	echo "Current kernels installed:"
	awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
	echo "-- End of List --"
	echo "Kernel made to boot will be: " $(awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg | sed -n "$Option{p;q}")
	
	if prompt "Is this okay?" Y ; then
		grub2-set-default $[$Option - 1]
		grub2-mkconfig -o /boot/grub2/grub.cfg
		echo "Default now set to: " $(grub2-editenv list)
		warning "You should now reboot the server to apply the new kernel."
	else
		echo "Please select the grub option and run:"
		echo " grub2-set-default X     - where X is the option"
		echo " grub2-mkconfig -o /boot/grub2/grub.cfg"
	fi
}

install_new_kernel