如何使用CLI将OpenSUSE 15.1升级到15.2

时间:2020-01-09 10:39:49  来源:igfitidea点击:

OpenSUSE的最新版本是15.2,在以前的15.1版本中,台式机和服务器用户都可以借此机会更新OpenSUSE Linux,以获取最新的软件堆栈。
可以很容易地遵循将OpenSUSE 15.1升级到15.2的过程。
在本教程中,我们将说明如何将OpenSUSE 15.1升级到15.2。

步骤1.准备备份所有内容

在执行以下任何命令之前,必须备份所有数据和配置文件。
确保系统备份是最新的并且在紧急情况下可以恢复。
作者或theitroad对损失不承担任何责任。
因此,请检查系统备份。
就我而言,我每天都有异地备份,并且创建了我的Linode和AWS VM的快照。

第2步。更新OpenSUSE 15.1软件包

请注意,openSUSE Leap版本15.2仅作为64位发行版提供。
接下来,执行以下zypper命令以更新所有现有软件包。
要刷新存储库,请运行:

$ sudo zypper ref
Repository 'openSUSE-Leap-15.1-1' is up to date.
Retrieving repository 'openSUSE-Leap-15.1-Update' metadata ..........................................[done]
Building repository 'openSUSE-Leap-15.1-Update' cache ...............................................[done]
Retrieving repository 'openSUSE-Leap-15.1-Update-Non-Oss' metadata ..................................[done]
Building repository 'openSUSE-Leap-15.1-Update-Non-Oss' cache .......................................[done]
All repositories have been refreshed.

使用更新的版本更新安装的软件包

运行:

$ sudo zypper up
Loading repository data...
Reading installed packages...

The following 16 package updates will NOT be installed:
  aws-cli cloud-init cloud-init-config-suse cloud-netconfig-ec2 growpart
  libsodium23 python3-bcrypt python3-boto3 python3-botocore python3-cffi
  python3-cryptography python3-ec2imgutils python3-ec2metadata python3-jmespath
  python3-s3transfer python-rpm-macros

The following 332 NEW packages are going to be installed:
  adjtimex adwaita-icon-theme apparmor-parser-lang atk-lang at-spi2-atk-common
  at-spi2-atk-gtk2 bash-completion bash-doc bash-lang branding-openSUSE
The following product is going to be reinstalled:
  "openSUSE Leap 15.1"

The following 7 packages require a system reboot:
  dbus-1 glibc kernel-default-4.12.14-lp151.28.52.1 kernel-firmware
  libopenssl1_1 systemd udev

280 packages to upgrade, 332 new, 1 to remove.
Overall download size: 455.0 MiB. Already cached: 0 B. After the operation,
additional 1.3 GiB will be used.

    Note: System reboot required.
Continue? [y/n/v/...? shows all options] (y): y

步骤3.重新启动服务器

记下您的Linux内核版本,执行:

$ uptime
$ uname -mrs

您必须重新引导Linux系统,然后运行:

$ sudo reboot
## 或者
$ sudo shutdown -r now

使用ssh命令登录:

$ ssh ec2-user@your-aws-ec2-ip-here
## 或者
$ ssh root@your-Linode-ip-here

系统重启后再次验证版本:

$ uname -mrs

步骤4.将OpenSUSE 15.1升级到15.2

现在,我们的系统是最新的,并已针对OpenSUSE Leap 15.1版进行了修补。
现在该将服务器更新到OpenSUSE版本15.2了。

列出存储库

在升级到15.2之前,更新存储库必须存在并且已启用并已更新。
验证一下:

$ sudo zypper repos --uri
## 或者
$ sudo zypper lr -u
Repository priorities are without effect. All enabled repositories share the same priority.
 
# | Alias                             | Name                              | Enabled | GPG Check | Refresh | URI
--+-----------------------------------+-----------------------------------+---------+-----------+---------+-------------------------------------------------------------
1 | openSUSE-Leap-15.1-1              | openSUSE-Leap-15.1-1              | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/distribution/leap/15.1/repo/oss/
2 | openSUSE-Leap-15.1-Update         | openSUSE-Leap-15.1-Update         | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/update/leap/15.1/oss/
3 | openSUSE-Leap-15.1-Update-Non-Oss | openSUSE-Leap-15.1-Update-Non-Oss | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/update/leap/15.1/non-oss/

项目编号2和3表示已启用版本15.1更新存储库。
如果"已启用"列显示"否",请发出以下命令启用它:

$ sudo zypper modifyrepo --enable openSUSE-Leap-15.1-Update
$ sudo zypper ref
$ sudo zypper up
## if a new kernel and libs installed ##
$ sudo reboot

找出版本号是否经过硬编码

找出/etc/zypp/repos.d/中定义的LeapRepo是否正在使用$releasever变量。
最好验证一下。
否则,更新将不会进行。
要使用以下awk命令/grep命令获取所有已启用的存储库的列表:

zypper lr -u | \
awk -F'|' ' ~ /Yes/ { gsub (" ", "", ); 
                        r="/etc/zypp/repos.d/"".repo"; 
                        print "\nFile: " r; system("cat " r) 
                      }'

输出示例表明``$releasever`已定义并且不需要使用sed命令:

File: /etc/zypp/repos.d/repo-non-oss.repo
[repo-non-oss]
name=Non-OSS Repository
enabled=1
autorefresh=0
baseurl=http://download.opensuse.org/distribution/leap/$releasever/repo/non-oss/
type=rpm-md

File: /etc/zypp/repos.d/repo-oss.repo
[repo-oss]
name=Main Repository
enabled=1
autorefresh=0
baseurl=http://download.opensuse.org/distribution/leap/$releasever/repo/oss/
type=rpm-md

File: /etc/zypp/repos.d/repo-update.repo
[repo-update]
name=Main Update Repository
enabled=1
autorefresh=0
baseurl=http://download.opensuse.org/update/leap/$releasever/oss/
type=rpm-md

File: /etc/zypp/repos.d/repo-update-non-oss.repo
[repo-update-non-oss]
name=Update Repository (Non-Oss)
enabled=1
autorefresh=0
baseurl=http://download.opensuse.org/update/leap/$releasever/non-oss/
type=rpm-md

这是另一个输出,指示版本号是硬编码的,您需要执行sed命令:

File: /etc/zypp/repos.d/openSUSE-Leap-15.1-1.repo
[openSUSE-Leap-15.1-1]
name=openSUSE-Leap-15.1-1
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/distribution/leap/15.1/repo/oss/
path=/
type=rpm-md
keeppackages=0

File: /etc/zypp/repos.d/openSUSE-Leap-15.1-Update.repo
[openSUSE-Leap-15.1-Update]
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/update/leap/15.1/oss/
type=rpm-md

File: /etc/zypp/repos.d/openSUSE-Leap-15.1-Update-Non-Oss.repo
[openSUSE-Leap-15.1-Update-Non-Oss]
enabled=1
autorefresh=1
baseurl=http://download.opensuse.org/update/leap/15.1/non-oss/
type=rpm-md

Linux sed命令更新硬编码版本

警告:仅当您具有硬编码的版本值时,才执行以下命令。

让我们尝试bash for loop和sed的组合。
首先,使用sudo命令切换到root用户帐户:

$ sudo -i

现在我们可以轻松地以root用户身份执行以下命令:

files="$(zypper lr -u | awk -F'|' ' ~ /Yes/ { gsub (" ", "", ); r="/etc/zypp/repos.d/"".repo"; print r }')"
for f in $files
do
  echo "Backup of $f saved to /root/ before patching it up ..."
  cp -f "$f" /root/
  sed -i 's+/leap/15.1+/leap/$releasever+' "$f"
  sed -i 's+15.1.1+15.2+' "$f"
  sed -i 's+15.1+15.2+' "$f"
done

运行15.2的升级

到目前为止,我们已验证并更新了硬编码版本。
现在该使用以下语法将所有存储库切换并刷新到15.2:

$ sudo zypper --releasever=15.2 ref
Warning: Enforced setting: $releasever=15.2
Retrieving repository 'openSUSE-Leap-15.2' metadata ......................................[done]
Building repository 'openSUSE-Leap-15.2' cache ...........................................[done]
Retrieving repository 'openSUSE-Leap-15.2-Update' metadata ...............................[done]
Building repository 'openSUSE-Leap-15.2-Update' cache ....................................[done]
Retrieving repository 'openSUSE-Leap-15.2-Update-Non-Oss' metadata .......................[done]
Building repository 'openSUSE-Leap-15.2-Update-Non-Oss' cache ............................[done]
All repositories have been refreshed.

确保存储库正确以获取OpenSUSE 15.2的更新:

$ sudo zypper lr -u
Repository priorities are without effect. All enabled repositories share the same priority.
 
# | Alias                             | Name                              | Enabled | GPG Check | Refresh | URI
--+-----------------------------------+-----------------------------------+---------+-----------+---------+-------------------------------------------------------------
1 | openSUSE-Leap-15.2                | openSUSE-Leap-15.2                | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/distribution/leap/15.2/repo/oss/
2 | openSUSE-Leap-15.2-Update         | openSUSE-Leap-15.2-Update         | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/update/leap/15.2/oss/
3 | openSUSE-Leap-15.2-Update-Non-Oss | openSUSE-Leap-15.2-Update-Non-Oss | Yes     | (r ) Yes  | Yes     | http://download.opensuse.org/update/leap/15.2/non-oss/

最后,执行以下命令以将完整发行版从15.1升级到15.2。
请注意,必须从非GUI(KDE/GNOME)模式执行命令。
因此,建议您从运行级别3(文本+网络)或虚拟控制台运行命令。
您可以按Ctrl-Alt-F2(同时全部)以切换到虚拟终端2。
也可以发出sudo init 3。
请参阅此页面以获取更多信息。

$ sudo zypper --releasever=15.2 dup

下载和安装软件包的过程可能需要一些时间。
这完全取决于您的Internet和云服务器/VM速度。
最后,您应该看到如下输出,指示您必须重新引导系统:

Executing %posttrans scripts ............................................................[done]
There are running programs which still use files and libraries deleted or updated by recent upgrades. They should be restarted to benefit from the latest updates. Run 'zypper ps -s' to list these programs.

Core libraries or services have been updated.
Reboot is required to ensure that your system benefits from these updates.

因此,重新启动服务器:

$ sudo reboot

步骤5:验证

确保一切正常。
首先,找到OpenSuse Linux版本和其他信息:

$ uname -mrs
$ lsb_release -a
$ hostnamectl

检查您的服务器日志。
例如,使用journalctl命令/tail命令/dmesg命令以及更多命令:

$ sudo tail -f /var/log/nginx/access_log
$ dmesg
$ journalctl -xe