没有不值得去解决的问题,也没有不值得去学习的技术!

Migrate CentOS 7 to Alibaba Cloud Linux 3 on Alibaba Cloud ECS

Select image: Alibaba Cloud Linux, 3.2104 LTS 64-bit

1. Configure the CentOS 7 yum source, refer to: “CentOS, Ubuntu, Debian Dependency Source Configuration”. An error occurs when updating the cache: File contains no section headers. Loaded plugins: fastestmirror. The reason is that CentOS has stopped maintenance.

Plaintext

[root@iZ23wv7v5ggZ ~]# cd /etc/yum.repos.d/
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 8
-rw-r--r-- 1 root root 2523 Jan 28  2022 CentOS-Base.repo
-rw-r--r-- 1 root root  664 Jan 28  2022 epel.repo
[root@iZ23wv7v5ggZ yum.repos.d]# rm -rf /etc/yum.repos.d/*.repo
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 0
[root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7221  100  7221    0     0   3763      0  0:00:01  0:00:01 --:--:--  3762
[root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7215  100  7215    0     0  11531      0 --:--:-- --:--:-- --:--:-- 11525
[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache
Loaded plugins: fastestmirror


File contains no section headers.
file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 1
'\n'
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 16
-rw-r--r-- 1 root root 7221 Jun  6 14:32 CentOS-Base.repo
-rw-r--r-- 1 root root 7215 Jun  6 14:32 epel.repo
[root@iZ23wv7v5ggZ yum.repos.d]#


2. Reference: Alibaba Cloud CentOS EOL Migration Solution. Prepare to migrate the currently used CentOS to the Alibaba Cloud Linux operating system.

3. Before migration, create a snapshot for the ECS instance to back up data to avoid data loss during the operation. See Figure 1

Create a snapshot for the ECS instance before migration to back up data, avoiding data loss during the operation
Figure 1

4. For detailed steps on migrating CentOS 7 to Alibaba Cloud Linux 2, please refer to CentOS 7 migration to Alibaba Cloud Linux 2

5. Stop the ECS instance. See Figure 2

Stop the ECS instance
Figure 2

6. Log in to the ECS management console. Find the target instance, and in the Actions column, select More > Disks and Images > Replace Operating System. See Figure 3

Log in to the ECS management console. Find the target instance, and in the Actions column, select More > Disks and Images > Replace Operating System
Figure 3

7. There is no operating system migration option, so you need to switch to the new version of the console. See Figure 4

There is no operating system migration option, so you need to switch to the new version of the console
Figure 4

8. In the Actions column, select More > Disks and Images > Replace Operating System. See Figure 5

In the Actions column, select More > Disks and Images > Replace Operating System
Figure 5

9. In the Replace Operating System dialog box, select Operating System Migration. See Figure 6

In the Replace Operating System dialog box, select Operating System Migration
Figure 6

10. For the target operating system, select Alibaba Cloud Linux 3. End of support date: April 30, 2031. See Figure 7

For the target operating system, select Alibaba Cloud Linux 3. End of support date: April 30, 2031
Figure 7

11. The status shows that the system replacement is in progress. Replacement failed, stopped. Normal downtime mode. See Figure 8

The status shows that the system replacement is in progress. Replacement failed, stopped. Normal downtime mode
Figure 8

12. Server Migration Center (SMC), import migration source. See Figure 9

Server Migration Center (SMC), import migration source
Figure 9

13. Cannot import. Reason: The selected instance cannot execute Cloud Assistant commands. Please check the Cloud Assistant status of the current instance. See Figure 10

Cannot import. Reason: The selected instance cannot execute Cloud Assistant commands. Please check the Cloud Assistant status of the current instance
Figure 10

14. After starting the instance, import the migration source again. Migration source status: Importing. See Figure 11

After starting the instance, import the migration source again. Migration source status: Importing
Figure 11

15. Import exception. After deleting, re-import. Still reports an error: Error code: SourceServer.ImportError Error message: Import timed out. See Figure 12

Import exception. After deleting, re-import. Still reports an error: Error code: SourceServer.ImportError Error message: Import timed out
Figure 12

16. After deleting, stop the instance. For the target operating system, select Anolis OS 7. End of support date: June 30, 2024. See Figure 13

After deleting, stop the instance. For the target operating system, select Anolis OS 7. End of support date: June 30, 2024
Figure 13

17. Finally, it was found that all 4 target systems under Operating System Migration failed to migrate.

18. At this stage, the only remaining option is to replace the system disk, and then redeploy the relevant environment. See Figure 14

At this stage, the only remaining option is to replace the system disk, and then redeploy the relevant environment
Figure 14

19. Select image: Alibaba Cloud Linux, 3.2104 LTS 64-bit. See Figure 15

Select image: Alibaba Cloud Linux, 3.2104 LTS 64-bit
Figure 15

20. If the operating system is Linux both before and after the replacement, and the data disk is set to automatically mount partitions at startup, the data disk partition mount information will be lost after switching the operating system, and the /etc/fstab configuration needs to be updated. For specific operations, please refer to Configure UUID-based automatic mounting of data disks in the fstab file. Run the following command to check the mount result

Plaintext

[root@iZ23wv7v5ggZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        464M     0  464M   0% /dev
tmpfs           482M     0  482M   0% /dev/shm
tmpfs           482M  440K  481M   1% /run
tmpfs           482M     0  482M   0% /sys/fs/cgroup
/dev/vda1        20G  2.9G   16G  16% /
tmpfs           482M     0  482M   0% /tmp
tmpfs            97M     0   97M   0% /run/user/0


21. Run the following command to view the cloud disk information of the instance

Plaintext

[root@iZ23wv7v5ggZ ~]#  fdisk -lu
Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x51cf5d51

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 41943039 41940992  20G 83 Linux


Disk /dev/vdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc0ac4089

Device     Boot Start      End  Sectors Size Id Type
/dev/vdb1        2048 83886079 83884032  40G 83 Linux
[root@iZ23wv7v5ggZ ~]#


22. Run the following command to query the UUID information of the cloud disk.

Plaintext

[root@iZ23wv7v5ggZ ~]# blkid
/dev/vda1: UUID="3bda0135-1a08-4c3e-8216-e07c05dd073a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="51cf5d51-01"
/dev/vdb1: UUID="0feecc5e-62d8-4282-98b3-cdc8ecf51952" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="c0ac4089-01"
[root@iZ23wv7v5ggZ ~]#


23. Run the following command to create the mount point for the data disk. Create the mount point /data for /dev/vdb1

Plaintext

[root@iZ23wv7v5ggZ /]# mkdir /data


24. Add mount information in the fstab file. Run the following command to edit fstab. Add the following mount information. The result is shown below. See Figure 16

Plaintext


[root@iZ23wv7v5ggZ /]# vi /etc/fstab
[root@iZ23wv7v5ggZ /]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu May 25 04:02:20 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=3bda0135-1a08-4c3e-8216-e07c05dd073a /                       ext4    defaults        1 1
UUID=0feecc5e-62d8-4282-98b3-cdc8ecf51952   /data     ext4    defaults     0   0
[root@iZ23wv7v5ggZ /]#



25. Run the following command to mount the file system of the data disk partition. Mount /dev/vdb1

Plaintext

[root@iZ23wv7v5ggZ /]# mount /dev/vdb1 /data

26. Run the following command to check the mount result.

Plaintext


[root@iZ23wv7v5ggZ /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        464M     0  464M   0% /dev
tmpfs           482M     0  482M   0% /dev/shm
tmpfs           482M  440K  481M   1% /run
tmpfs           482M     0  482M   0% /sys/fs/cgroup
/dev/vda1        20G  2.9G   16G  16% /
tmpfs           482M     0  482M   0% /tmp
tmpfs            97M     0   97M   0% /run/user/0
/dev/vdb1        40G   24G   14G  65% /data
[root@iZ23wv7v5ggZ /]#


27. After configuration is complete, restart the ECS instance and check the mount result again. The system will automatically mount the data disk.

Plaintext

[root@iZ23wv7v5ggZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        464M     0  464M   0% /dev
tmpfs           482M     0  482M   0% /dev/shm
tmpfs           482M  436K  481M   1% /run
tmpfs           482M     0  482M   0% /sys/fs/cgroup
/dev/vda1        20G  2.9G   16G  16% /
tmpfs           482M     0  482M   0% /tmp
/dev/vdb1        40G   24G   14G  65% /data
tmpfs            97M     0   97M   0% /run/user/0
[root@iZ23wv7v5ggZ ~]#


28. Enter the /etc/yum.repos.d/ directory and check the yum source, which meets expectations

Plaintext


[root@iZ23wv7v5ggZ ~]# cd /etc/yum.repos.d/
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 20
-rw-r--r-- 1 root root 1475 May 25 12:15 AliYun.repo
-rw-r--r-- 1 root root  703 Jun 10  2022 epel-modular.repo
-rw-r--r-- 1 root root  664 Jun 10  2022 epel.repo
-rw-r--r-- 1 root root  781 Jun 10  2022 epel-testing-modular.repo
-rw-r--r-- 1 root root  742 Jun 10  2022 epel-testing.repo
[root@iZ23wv7v5ggZ yum.repos.d]#


关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系