Assuming that reinstalling from zero is not practical, how do I perform an update from CentOS 7 to CentOS 8?

I tried to do a yum install http://mirror.bytemark.co.uk/centos/8/BaseOS/x86_64/os/Packages/centos-release-8.0-0.1905.0.9.el8.x86_64.rpm but apparently that does not work as one would expect. Running yum update after this puts yum into an endless recursive attempt to resolve dependencies.

  • 2
    That's never been a supported upgrade method, but you also installed an i686 package... – Michael Hampton Sep 24 '19 at 16:15
  • @MichaelHampton I fixed the url, it was only on the post, real life test was done using correct arch. – sorin Sep 24 '19 at 16:17
  • Aha. Well, I did some looking around. It appears that C8 is still being pushed out to mirrors. It has not been officially announced. Try again tomorrow, maybe? – Michael Hampton Sep 24 '19 at 16:22

Red Hat provide the tool leapp to upgrade from EL 7.6+ to 8, however according to this CentOS bug, there are no plans to support it on CentOS. Trying to point an existing 7.x machine to the 8.x repos and running yum update will likely not work; it's never been a supported method. Your only choice is a reinstall.

| improve this answer | |
  • is a reinstall truly necessary? see a bunch of upvotes, but there seem to be guilds showing how to upgrade... do they work? – warath-coder Dec 20 '19 at 14:18
  • @warath-coder The guides I've seen aren't necessarily an official upgrade path/procedure endorsed by CentOS. Because of the core changes, the risk of something going south during the process is very high. From a production point of view, it is likely that a migration is the safest possible "upgrade path". Install CentOS 8 fresh and migrate configs and software packages. – James White Jan 4 at 17:46
  • @JamesWhite yes, that is always the "safest" path from a breaking code change. However, lots can go wrong doing that as well :( any new guides on best way to do that, or are the "tried/true" methods still the best? – warath-coder Jan 16 at 12:33

There are manuals around with bugs, so try this (see comments). If something fails, you need to resolve the issue or it won't work. Some steps are hard to reverse and you may end up with unbootable system so be prepared to rescue/reinstall the system from scratch and have backups. Some commands (distro-sync) takes long time and must not be interrupted so if you know how to use screen you will be fine (even you'll not be able to reconnect after update, update process finishes in screen, check log by tail -f /var/log/dnf.log). If don't, upgrade from terminal (no network connection) or over super-stable network connection. You have been warned. It is suggested to update the whole system first by yum -y update, reboot and check if everything works, so you will know what was broken by upgrade and what has been broken before upgrade.

# relax SELinux temporally (permissive mode)
setenforce 0
# switch to dnf
yum -y install dnf
# remove yum and its files
dnf -y remove yum yum-metadata-parser
rm -Rf /etc/yum /var/cache/yum
# switch to CentOS 8 repo
dnf -y upgrade http://vault.centos.org/8.0.1905/BaseOS/x86_64/os/Packages/centos-release-8.0-0.1905.0.9.el8.x86_64.rpm

Switch all your active yum/dnf repositories to version 8 or you get strange errors (conflicting packages etc) at distro-sync later. List your repos by rpm -qf /etc/yum.repos.d/* | sort -u and IF you get something like epel-release-7-1.el7.noarch update repos by command below (URL parametr is copied from EPEL page). Repeat this paragraph until you have all repos on v8 (Chrome repo doesn't have to be updated).

dnf -y upgrade https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Let's continue:

# clean repos metadata
dnf clean all
# update repos packages to their latest version (centos-release, epel-release, ...)
dnf -y update \*release*
# remove all kernel packages (system is unbootable until new kernel is installed later), modify if using kernel-plus
rpm -e --nodeps $(rpm -q kernel)
# remove conflicting package
rpm -e --nodeps sysvinit-tools
# lets upgrade the system to version 8
dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
# install kernel modules (you may need kernel-plus and kernel-plus-modules instead if you have obsolete hardware)
dnf -y install kernel-modules
# kernel package has been renamed so set DEFAULTKERNEL=kernel-core in /etc/sysconfig/kernel
sed -i -e s@DEFAULTKERNEL=kernel@DEFAULTKERNEL=kernel-core@ /etc/sysconfig/kernel
# refresh initramfs after additional kernel modules were installed
dnf -y reinstall kernel-core
# make sure all base packages are in place (change install to update if these groups are already installed)
dnf -y group install Core "Minimal Install"
# fix SELinux labels during shutdown (it will take a time)
touch /.autorelabel

Take a copy/photo of the file /etc/sysconfig/grub. You may need content of the GRUB_CMDLINE_LINUX if GRUB loader fall to shell prompt at bootup (root filesystem info). Check list and number of modules in iniramfs image by lsinitrd /boot/initramfs-4*.img | grep -c ko.xz

CentOS 8 uses new BLS configuration through directory /boot/loader/entries/ where every kernel has own config file for every GRUB menu entry (they are sorted alphabeticaly, not by date/time) so /etc/grub2.cfg has no menuentry and does not need to be updated with kernel. CentOS 8 obsoletes network scripts and moves to NetworkManager. If your network interfaces are handled by network scripts, make sure you have network-scripts package installed and this service is enabled (systemctl enable network.service).

Cross your fingers and keep handy bootable CentOS 8 DVD (or USB stick) to rescue your system and type reboot to boot new system (SELinux autorelabel will take a time, press ESC key to see what's going on on boot screen, it reboots once when finished).

After successful reboot, you may want to check what config files were left behind by rpmconf -a from package rpmconf (this package is in EPEL repo, so you need to enable this repo first by dnf -y install epel-release).

There will be some packages that are no longer part of CentOS 8 repo (orphans), you may list them by dnf repoquery --extras. Remove by dnf remove <package>, remove all by dnf remove $(dnf repoquery --extras). List leaves by dnf repoquery --unneeded (remove some or all of them).

Check SELinux denial messages after reboot by ausearch -m avc --start recent (fix them if you have own rules or non-standard setup). Check /var/log/messages, /var/log/boot.log and journalctl -xe for errors and warnings. Set AutoUpdates (if you had yum-cron). Delete rescue kernel by rm /boot/vmlinuz-0-rescue* /boot/initramfs-0-rescue* and reinstall kernel to get new GRUB rescue menuentry for CentOS 8 by command dnf -y reinstall kernel-core (the rescue kernel has all possible drivers/modules included). Set proper alternative for Python by alternatives --config python (pick version 3 or old 2).

| improve this answer | |

I was able to update one machine running CentOS 7 using this guide as reference: https://www.tecmint.com/upgrade-centos-7-to-centos-8/

Thought I had to search for the correct mirror package to upgrade to v8.0 since I had gpg key issues updating directly to v8.1 as suggested in this guide.

So for step 4, this is the command I used:

# dnf install http://mirror.bytemark.co.uk/centos/8.0.1905/BaseOS/x86_64/os/Packages/centos-release-8.0-0.1905.0.9.el8.x86_64.rpm

(Notice the version number change in the URL 8 -> 8.0.1905)

I did not need to install centos-repos and centos-gpg-keys as mentioned in the guide and was able to carry on with the next steps of the guide.

NB: Though I wouldn't really use this on a production server. I'd rather go for a migration. If you can't, make sure you have backuped up everything thouroughly (data AND configurations).

I hope this helps!

Cheers, D

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.