当前位置: 首页 > ops >正文

01-centos离线升级至almalinux

  • 官网链接
  • 官方代码调整:
1. vi repositories/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
with mounting.BindMount(source=userspace_dir, target=os.path.join(context.base_dir, install_root_dir.lstrip('/'))):_restore_persistent_package_cache(userspace_dir)if not is_nogpgcheck_set():_import_gpg_keys(context, install_root_dir, target_major_version)repos_opt = [['--enablerepo', repo] for repo in enabled_repos]repos_opt = list(itertools.chain(*repos_opt))cmd = ['dnf', 'install', '-y']if is_nogpgcheck_set():cmd.append('--nogpgcheck')cmd += ['--setopt=module_platform_id=platform:el{}'.format(target_major_version),'--setopt=keepcache=1','--releasever', api.current_actor().configuration.version.target,'--installroot', install_root_dir,'--disablerepo', '*','--enablerepo', UPGRADE_REPO_NAME] + repos_opt + packages2. repositories/system_upgrade/common/libraries/dnfplugin.py
def _prepare_transaction(used_repos, target_userspace_info, binds=()):""" Creates the transaction environment needed for the target userspace DNF execution  """target_repoids = set([UPGRADE_REPO_NAME])try:dest = '/var/lib/leapp/el8userspace' + UPGRADE_DIRshutil.copytree(UPGRADE_DIR, dest)except Exception as e:print(e)with mounting.NspawnActions(base_dir=target_userspace_info.path, binds=binds) as context:yield context, list(target_repoids), target_userspace_info
  • 离线升级脚本
#!/bin/bashalma8_upgraded_option() {rpm -qa | grep el7 | xargs rpm -e --nodeps &>/dev/nullrpm -qa | grep elevate | xargs rpm -e --nodeps &>/dev/nullrpm -qa | grep leapp | xargs rpm -e --nodeps &>/dev/nullrm -fr /root/tmp_leapp_py3dnf clean allrpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n' | awk '{print $1}' | xargs rpm -esed -i '/^exclude=python2-leapp/ s/^/#/' /etc/yum.confsed -i '/^exclude=python2-leapp/ s/^/#/' /etc/dnf/dnf.conf
}install_leapp() {# leapp软件下载leapp_install=`cat ${LOGS_FILE_PATH} | grep "${VERSION_TO_UPGRADE}_leapp_install=true"`if [ -z "$leapp_install" ];thenyum localinstall -y ${PACKAGES_DIR}/elevate-release-latest-${ELEVATE_VERSION}.noarch.rpmfind /etc/yum.repos.d/ ! -name "local.repo" -type f | xargs rm -fyum localinstall -y ${PACKAGES_DIR}/leapp/*.rpmif [ $? -eq 0 ]; thenecho "${VERSION_TO_UPGRADE}_leapp_install=true" >> ${LOGS_FILE_PATH}fifi
}reboot_confirm() {reboot_option=`cat ${LOGS_FILE_PATH} | grep "${VERSION_TO_UPGRADE}_${1}_reboot=true"`if [ -z "$reboot_option" ];thenread -p "Please confirm whether to restart the machine[y/n]:" optioncase $option iny)echo "Start reboot"echo "${VERSION_TO_UPGRADE}_${1}_reboot=true" >> ${LOGS_FILE_PATH}reboot;;n)echo "Cancel reboot";;*)echo "Please input [y/n]";;esacfi
}generate_local_repo (){case ${VERSION_TO_UPGRADE} incentos7_to_alma8)cat <<EOF > /etc/yum.repos.d/local.repo
[${PREPARE_REPO_NAME}]
name=${PREPARE_REPO_NAME} Repository
baseurl=file://${PREPARE_DIR}
enabled=1
gpgcheck=0[${UPGRADE_REPO_NAME}]
name=${UPGRADE_REPO_NAME} Repository
baseurl=file://${UPGRADE_DIR}
enabled=1
gpgcheck=0
EOF;;alma8_to_alma9)
cat <<EOF > /etc/yum.repos.d/local.repo
[${UPGRADE_REPO_NAME}]
name=${UPGRADE_REPO_NAME} Repository
baseurl=file://${UPGRADE_DIR}
enabled=1
gpgcheck=0
EOF;;*)exit 0;;esac
}# 当前机器的版本
CURRENT_OS_VERSION=`cat /etc/os-release | grep PRETTY_NAME= | tr '[:upper:]' '[:lower:]'` if [[ "$CURRENT_OS_VERSION" == *"centos"* ]];thenVERSION_TO_UPGRADE=centos7_to_alma8ELEVATE_VERSION=el7
elif [[ "$CURRENT_OS_VERSION" == *"almalinux 8"* ]];thenVERSION_TO_UPGRADE=alma8_to_alma9ELEVATE_VERSION=el8
fiBASE_DIR=$(cd "$(dirname "$0")";pwd)
LOGS_DIR=${BASE_DIR}/logs
LOGS_FILE_PATH=${LOGS_DIR}/history
PACKAGES_DIR=${BASE_DIR}/${VERSION_TO_UPGRADE}
PREPARE_REPO_NAME=prepare
UPGRADE_REPO_NAME=upgrade
PREPARE_DIR=${PACKAGES_DIR}/${PREPARE_REPO_NAME}
UPGRADE_DIR=${PACKAGES_DIR}/${UPGRADE_REPO_NAME}# 配置本地仓库
if [ ! -d "${PACKAGES_DIR}/yum.repos.d" ]; thenmv /etc/yum.repos.d ${PACKAGES_DIR}/mkdir -p /etc/yum.repos.d
figenerate_local_repo# 解压rpm包
mkdir -p ${PACKAGES_DIR}
if [ -f "${VERSION_TO_UPGRADE}.tar.gz" ];thenecho "Start tar xf ${BASE_DIR}/${VERSION_TO_UPGRADE}.tar.gz"rm -rf ${PACKAGES_DIR}/*tar xf ${BASE_DIR}/${VERSION_TO_UPGRADE}.tar.gz -C ${PACKAGES_DIR}
elseecho "please check ${VERSION_TO_UPGRADE}.tar.gz exists?"exit 0
fimkdir -p ${LOGS_DIR}
touch ${LOGS_FILE_PATH}# 升级前处理
case ${VERSION_TO_UPGRADE} in
centos7_to_alma8)# 软件升级yum_upgrade=`cat ${LOGS_FILE_PATH} | grep "${VERSION_TO_UPGRADE}_yum_upgrade=true"`if [ -z "$yum_upgrade" ];thenyum upgrade -y --disablerepo=* --enablerepo=${PREPARE_REPO_NAME}if [ $? -eq 0 ]; thenecho "${VERSION_TO_UPGRADE}_yum_upgrade=true" >> ${LOGS_FILE_PATH}fifi# 重启reboot_confirm yum_upgrade# 安装leappinstall_leapp# 生成 answerfilecat <<EOF > /var/log/leapp/answerfile
[remove_pam_pkcs11_module_check]
confirm = True
EOF# 卸载内核模块pata_acpirmmod pata_acpi# 修改sshd_config,允许root密码登录if ! grep -q "^PermitRootLogin yes" /etc/ssh/sshd_config; thensed -i '/^PermitRootLogin/ s/^/#/' /etc/ssh/sshd_configecho PermitRootLogin yes | tee -a /etc/ssh/sshd_configfi;;alma8_to_alma9)# 升级前处理alma8_upgraded_option# 安装leappinstall_leapp# 生成 answerfilecat <<EOF > /var/log/leapp/answerfile
[check_vdo]
confirm = True
EOF# 修改sshd_config,禁止root密码登录if grep -q "^PermitRootLogin yes" /etc/ssh/sshd_config; thensed -i '/^PermitRootLogin/ s/^/#/' /etc/ssh/sshd_configecho PermitRootLogin no | tee -a /etc/ssh/sshd_configfi# 防火墙设置sed -i "s/^AllowZoneDrifting=.*/AllowZoneDrifting=no/" /etc/firewalld/firewalld.conf;;
*)exit 0;;
esac# 拷贝执行目录到目标路径
echo UPGRADE_REPO_NAME=${UPGRADE_REPO_NAME} > ${PACKAGES_DIR}/${VERSION_TO_UPGRADE//_/-}-leapp-repository/leapp_upgrade.env
echo UPGRADE_DIR=${UPGRADE_DIR} >> ${PACKAGES_DIR}/${VERSION_TO_UPGRADE//_/-}-leapp-repository/leapp_upgrade.env
rm -rf /usr/share/leapp-repository
cp -r ${PACKAGES_DIR}/${VERSION_TO_UPGRADE//_/-}-leapp-repository /usr/share/leapp-repository# 执行升级
leapp upgrade

http://www.xdnf.cn/news/5496.html

相关文章:

  • Meilisearch 安装
  • 【番外】02:Windows 编译带 DNN_CUDA 功能的 OpenCV 动态链接库
  • Node.js中那些常用的进程通信方式
  • bazel迁移cmake要点及具体迁移工程示例(apollo radar)
  • SDK does not contain ‘libarclite‘ at the path
  • 【前端】骨架屏
  • 深度解析LLM参数:Top-K、Top-p和温度如何影响输出随机性?
  • 循环语句:for、range -《Go语言实战指南》
  • 矩阵键盘模块
  • Spark(25)在shell中运行Spark程序
  • mapbox进阶,使用mapbox-plugins插件加载饼状图
  • 《AI大模型应知应会100篇》第60篇:Pinecone 与 Milvus,向量数据库在大模型应用中的作用
  • iOS safari和android chrome开启网页调试与检查器的方法
  • 我开源了一个免费在线工具!UIED Tools
  • 【Python 变量类型】
  • 【技巧】离线安装docker镜像的方法
  • MIT XV6 - 1.6 Lab: Xv6 and Unix utilities -uptime
  • AI 时代 UI 设计的未来范式
  • 设计模式之中介者模式
  • 华为行业认证是什么?如何考取华为行业认证?
  • Wpf学习片段
  • Python3(31) CGI 编程
  • 自动驾驶技术栈——DoIP通信协议
  • 鸿蒙 UIAbility组件与UI的数据同步和窗口关闭
  • 【数据结构】——队列
  • 学习threejs,使用Physijs物理引擎,加载各种几何体网格对象
  • 2025 盘古石杯初赛 wp
  • Lambda表达式能用在哪些场景?
  • 学习黑客5 分钟深入浅出理解Windows Editions
  • MyBatis源码解读1(MyBatis回顾)