From 7aa8c84ce2251393ea88cb235f19e4da3a513ec3 Mon Sep 17 00:00:00 2001 From: Peter Ajamian Date: Sat, 29 May 2021 14:17:06 +1200 Subject: [PATCH 1/4] Add dnf version check EL 8.0 had a dnf that was not compatible with this script (output changed causing parsing errors). Make sure that e ahve a recent enough dnf for this script to run properly and recommend updating otherwise. --- migrate2rocky.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/migrate2rocky.sh b/migrate2rocky.sh index 10a6191..90dc914 100644 --- a/migrate2rocky.sh +++ b/migrate2rocky.sh @@ -57,6 +57,19 @@ os-release () ( printf '%s\n' "${!1}" ) +# Check the version of a package against a supplied version number. Note that +# this uses sort -V to compare the versions which isn't perfect for rpm package +# versions, but to do a proper comparison we would need to use rpmdev-vercmp in +# the rpmdevtools package which we don't want to force-install. sort -V should +# be adequate for our needs here. +pkg_ver() ( + ver=$(rpm -q --qf '%{VERSION}\n' "$1") || return 2 + if [[ $(sort -V <<<"$ver"$'\n'"$2" | head -1) != $2 ]]; then + return 1 + fi + return 0 +) + # All of the binaries used by this script are available in a EL8 minimal install # and are in /bin, so we should not encounter a system where the script doesn't # work unless it's severly broken. This is just a simple check that will cause @@ -79,12 +92,17 @@ bin_check() { fi local -a missing - for bin in rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir rm; do + for bin in rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir rm \ + head; do if ! type "$bin" >/dev/null 2>&1; then missing+=("$bin") fi done + if ! pkg_ver dnf 4.2; then + exit_message 'dnf >= 4.2 is required for this script. Please run "dnf update" first.' + fi + if (( ${#missing[@]} )); then exit_message "Commands not found: ${missing[@]}. Possible bad PATH setting or corrupt installation." fi From 800cf77a386275d6ade316857ac445228d0112b5 Mon Sep 17 00:00:00 2001 From: Peter Ajamian Date: Sat, 29 May 2021 18:33:57 +1200 Subject: [PATCH 2/4] Add support for EFI You can now pass the -e switch to update EFI boot settings at the end of the migration. --- migrate2rocky.sh | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/migrate2rocky.sh b/migrate2rocky.sh index 90dc914..7ae6116 100644 --- a/migrate2rocky.sh +++ b/migrate2rocky.sh @@ -91,9 +91,15 @@ bin_check() { exit_message "bash >= 4.0 is required for this script." fi - local -a missing - for bin in rpm dnf awk column tee tput mkdir cat arch sort uniq rmdir rm \ - head; do + local -a missing bins + bins=( + rpm dnf awk column tee tput mkdir + cat arch sort uniq rmdir rm head + ) + if [[ $update_efi ]]; then + bins+=(findmnt grub2-mkconfig efibootmgr) + fi + for bin in "${bins[@]}"; do if ! type "$bin" >/dev/null 2>&1; then missing+=("$bin") fi @@ -193,6 +199,15 @@ provides_pkg () ( ) collect_system_info () { + # Check the efi mount first, so we can bail before wasting time on all these + # other checks if it's not there. + if [[ $update_efi ]]; then + declare -g efi_mount + efi_mount=$(findmnt --mountpoint /boot/efi --output SOURCE \ + --noheadings) || + exit_message "Can't find EFI mount. No EFI boot detected." + fi + # Don't enable these module streams, even if they are enabled in the source # distro. declare -g -a module_excludes @@ -359,16 +374,17 @@ collect_system_info () { } convert_info_dir=/root/convert -unset convert_to_rocky reinstall_all_rpms verify_all_rpms +unset convert_to_rocky reinstall_all_rpms verify_all_rpms update_efi usage() { printf '%s\n' \ "Usage: ${0##*/} [OPTIONS]" \ '' \ 'Options:' \ - '-h displays this help' \ - '-r Converts to rocky' \ - '-V Verifies switch' \ + '-e Update EFI boot sector when done' \ + '-h Display this help' \ + '-r Convert to rocky' \ + '-V Verify switch' \ ' !! USE WITH CAUTION !!' exit 1 } >&2 @@ -500,6 +516,14 @@ EOF dnf -y distro-sync || exit_message "Error during distro-sync." } +# Called to update the EFI boot. +fix_efi () ( + grub2-mkconfig -o /boot/efi/EFI/rocky/grub.cfg || + exit_message "Error updating the grub config." + efibootmgr -c -d "$efi_mount" -L "Rocky Linux" -I /EFI/rocky/grubx64.efi || + exit_message "Error updating uEFI firmware." +) + ## End actual work noopts=0 @@ -515,6 +539,9 @@ while getopts "hrVR" option; do V) verify_all_rpms=true ;; + e) + update_efi=true + ;; *) printf '%s\n' "${errcolor}Invalid switch.$nocolor" usage @@ -542,6 +569,10 @@ if [[ $verify_all_rpms && $convert_to_rocky ]]; then find /root/convert -type f -name "$HOSTNAME-rpms-*.log" fi +if [[ $update_efi && $convert_to_rocky ]]; then + fix_efi +fi + printf '\n\n\n' if [[ $convert_to_rocky ]]; then cat /etc/issue | awk 'NR<=15' From b2d0c000d455bbeef1254efa15c943c499dfad99 Mon Sep 17 00:00:00 2001 From: Peter Ajamian Date: Sat, 29 May 2021 21:17:10 +1200 Subject: [PATCH 3/4] Turn off colors This is for two reaons: 1. There have been a number of complaints about the color blue. For now I can't get reasonable agreement on which color to make informative messages and it will differ depending on what the background color is of a person's terminal. 2. Currently the log is generated simply by splitting stdout and stderr. That means that color codes go to the log, which is less than ideal. We need separate logging routines that don't send the color codes but for now turning off color will suffice. This has been accomplished simply by commenting out the tput assignments at the beginning of the script. It is likely that osme form of color support will go back in at some point so we'll keep the old code around for now. --- migrate2rocky.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/migrate2rocky.sh b/migrate2rocky.sh index 7ae6116..4547a8e 100644 --- a/migrate2rocky.sh +++ b/migrate2rocky.sh @@ -16,9 +16,10 @@ truncate -s0 "$logfile" exec > >(tee -a "$logfile") 2> >(tee -a "$logfile" >&2) # List nocolor last here so that -x doesn't bork the display. -errcolor=$(tput setaf 1) -blue=$(tput setaf 4) -nocolor=$(tput op) +#errcolor=$(tput setaf 1) +#blue=$(tput setaf 4) +#nocolor=$(tput op) +unset errcolor blue nocolor export LANG=en_US.UTF-8 shopt -s nullglob From 40dc4b53b1bf84e080c75c5a20a2586e591cdb93 Mon Sep 17 00:00:00 2001 From: Peter Ajamian Date: Sat, 29 May 2021 21:22:01 +1200 Subject: [PATCH 4/4] Change log file name to migrate2rocky.log It was left as centos2rocky.log from the old script. --- migrate2rocky.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrate2rocky.sh b/migrate2rocky.sh index 4547a8e..d4a0e52 100644 --- a/migrate2rocky.sh +++ b/migrate2rocky.sh @@ -9,7 +9,7 @@ ## instability. # Path to logfile -logfile=/var/log/centos2rocky.log +logfile=/var/log/migrate2rocky.log # Send all output to the logfile as well as stdout. truncate -s0 "$logfile"