将 Data Science Virtual Machine 升级到 Ubuntu 18.04Upgrade your Data Science Virtual Machine to Ubuntu 18.04

如果你的 Data Science Virtual Machine 运行的是早期版本,例如 Ubuntu 16.04 或 CentOS,则应将 DSVM 迁移到 Ubuntu 18.04。If you have a Data Science Virtual Machine running an older release such as Ubuntu 16.04 or CentOS, you should migrate your DSVM to Ubuntu 18.04. 迁移会确保你获取最新的操作系统补丁、驱动程序、预安装软件和库版本。Migrating will ensure that you get the latest operating system patches, drivers, preinstalled software, and library versions. 本文档说明了如何从 Ubuntu 的早期版本或从 CentOS 进行迁移。This document tells you how to migrate from either older versions of Ubuntu or from CentOS.

先决条件Prerequisites

  • 熟悉 SSH 和 Linux 命令行Familiarity with SSH and the Linux command line

概述Overview

可通过两种可能的方式进行迁移:There are two possible ways to migrate:

  • 就地迁移,也称为“同服务器”迁移。In-place migration, also called "same server" migration. 此迁移会升级现有 VM,而不是创建新的虚拟机。This migration upgrades the existing VM without creating a new virtual machine. 就地迁移是从 Ubuntu 16.04 迁移到 Ubuntu 18.04 的较简单方法。In-place migration is the easier way to migrate from Ubuntu 16.04 to Ubuntu 18.04.
  • 并行迁移,也称为“服务器间”迁移。Side-by-side migration, also called "inter-server" migration. 此迁移将数据从现有虚拟机传输到新创建的虚拟机。This migration transfers data from the existing virtual machine to a newly created VM. 并行迁移是从 Centos 迁移到 Ubuntu 18.04 的方式。Side-by-side migration is the way to migrate from Centos to Ubuntu 18.04. 如果你认为旧安装已变得混乱,你可能更倾向于进行并行迁移以在 Ubuntu 版本之间进行升级。You may prefer side-by-side migration for upgrading between Ubuntu versions if you feel your old install has become needlessly cluttered.

如果需要回滚,请为你的 VM 创建快照Snapshot your VM in case you need to roll back

在 Azure 门户中,使用搜索栏查找 快照 功能。In the Azure portal, use the search bar to find the Snapshots functionality.

显示了 Azure 门户和搜索栏的屏幕截图,其中突出显示了**快照**

  1. 选择“添加”,这会转到“创建快照”页面。Select Add , which will take you to the Create snapshot page. 选择你的虚拟机的订阅和资源组。Select the subscription and resource group of your virtual machine. 对于“区域”,请选择目标存储所在的区域。For Region , select the same region in which the target storage exists. 选择 DSVM 存储磁盘和其他备份选项。Select the DSVM storage disk and additional backup options. 标准 HDD 是适用于此备份方案的存储类型。Standard HDD is an appropriate storage type for this backup scenario.

显示了“创建快照”选项的屏幕截图

  1. 填写所有详细信息并通过验证后,选择“查看 + 创建”来验证并创建快照。Once all the details are filled and validations pass, select Review + create to validate and create the snapshot. 当快照成功完成后,你会看到一条消息,告知你部署已完成。When the snapshot successfully completes, you'll see a message telling you the deployment is complete.

就地迁移In-place migration

如果迁移的是较旧的 Ubuntu 版本,可以选择进行就地迁移。If you're migrating an older Ubuntu release, you may choose to do an in-place migration. 此迁移不会创建新的虚拟机,并且执行的步骤少于并行迁移的步骤。This migration doesn't create a new virtual machine and has fewer steps than a side-by-side migration. 如果因为需要更多控制或要从另一发行版(例如 CentOS)进行迁移而希望进行并行迁移,请跳到并行迁移部分。If you wish to do a side-by-side migration because you want more control or because you're migrating from a different distribution, such as CentOS, skip to the Side-by-side migration section.

  1. 在 Azure 门户中,启动你的 DSVM 并使用 SSH 登录。From the Azure portal, start your DSVM and sign in using SSH. 为此,请选择“连接”和“SSH”并按照连接说明进行操作。To do so, select Connect and SSH and follow the connection instructions.

  2. 连接到 DSVM 上的终端会话后,运行以下升级命令:Once connected to a terminal session on your DSVM, run the following upgrade command:

    sudo do-release-upgrade
    

升级过程需要一段时间才能完成。The upgrade process will take a while to complete. 结束时,程序会要求获得重启虚拟机的权限。When it's over, the program will ask for permission to restart the virtual machine. 回答“是”。Answer Yes. 系统重启时,会断开与 SSH 会话的连接。You will be disconnected from the SSH session as the system reboots.

如有必要,请重新生成 SSH 密钥If necessary, regenerate SSH keys

重要

升级并重启后,可能需要重新生成 SSH 密钥。After upgrading and rebooting, you may need to regenerate your SSH keys.

在你的 VM 升级并重启后,尝试通过 SSH 再次访问它。After your VM has upgraded and rebooted, attempt to access it again via SSH. IP 地址可能在重启过程中发生了更改,因此请在尝试连接之前进行确认。The IP address may have changed during the reboot, so confirm it before attempting to connect.

如果收到“远程主机标识已更改”错误,则需要重新生成 SSH 凭据。If you receive the error REMOTE HOST IDENTIFICATION HAS CHANGED , you'll need to regenerate your SSH credentials.

显示了“远程主机标识已更改”警告的 PowerShell 屏幕截图

为此,请在本地计算机上运行以下命令:To do so, on your local machine, run the command:

ssh-keygen -R "your server hostname or ip"

你现在应能通过 SSH 进行连接。You should now be able to connect with SSH. 如果仍然遇到问题,请在“连接”页上单击“排查 SSH 连接性问题”链接。If you're still having trouble, in the Connect page follow the link to Troubleshoot SSH connectivity issues.

并行迁移Side-by-side migration

如果要从 CentOS 迁移或要进行干净的 OS 安装,可以进行并行迁移。If you're migrating from CentOS or want a clean OS install, you can do a side-by-side migration. 此类型的迁移包含更多步骤,但允许你精确控制要迁移的文件。This type of migration has more steps, but gives you control over exactly which files are carried over.

从基于同一组上游源包的其他系统进行迁移应该相对简单,例如常见问题解答/CentOS3Migrations from other systems based on the same set of upstream source packages should be relatively straightforward, for example FAQ/CentOS3.

你可以选择升级文件系统的操作系统部分,并保留用户目录,例如 /homeYou may choose to upgrade the operating system parts of the filesystem and leave user directories, such as /home in place. 如果你将旧的用户主目录保留在原来的位置,那么 GNOME/KDE 菜单和其他桌面项可能会出现一些问题。If you do leave the old user home directories in place expect some problems with the GNOME/KDE menus and other desktop items. 最简单的方法是在文件系统中创建新的用户帐户,并将旧目录装载到文件系统中的其他某个位置,以便在迁移后引用、复制或链接用户的资料。It may be easiest to create new user accounts and mount the old directories somewhere else in the filesystem for reference, copying, or linking users' material after the migration.

迁移概览Migration at a glance

  1. 创建现有 VM 的快照,如前文所述Create a snapshot of your existing VM as described previously

  2. 基于该快照创建磁盘Create a disk from that snapshot

  3. 创建新的 Ubuntu Data Science Virtual MachineCreate a new Ubuntu Data Science Virtual Machine

  4. 在新虚拟机上重新创建用户帐户Recreate user account(s) on the new virtual machine

  5. 在新的 Data Science Virtual Machine 上装载快照 VM 的磁盘作为数据磁盘Mount the disk of the snapshotted VM as a data disk on your new Data Science Virtual Machine

  6. 手动复制所需的数据Manually copy the wanted data

基于 VM 快照创建磁盘Create a disk from your VM snapshot

如果尚未按前文所述创建 VM 快照,请执行该操作。If you haven't already created a VM snapshot as described previously, do so.

  1. 在 Azure 门户中,搜索“磁盘”并选择“添加”,这将打开“磁盘”页面。In the Azure portal, search for Disks and select Add , which will open the Disk page.

Azure 门户的屏幕截图,其中显示了搜索“磁盘”时的页面和“添加”按钮

  1. 将“订阅”、“资源组”和“区域”设置为你的 VM 快照的值。Set the Subscription , Resource group , and Region to the values of your VM snapshot. 为要创建的磁盘选择一个 名称Choose a Name for the disk to be created.

  2. 选择“快照”作为“源类型”,并选择 VM 快照作为“源快照”。Select Source type as Snapshot and select the VM snapshot as the Source snapshot. 查看并创建磁盘。Review and create the disk.

磁盘创建对话框的屏幕截图,其中显示了选项

创建新的 Ubuntu Data Science Virtual MachineCreate a new Ubuntu Data Science Virtual Machine

使用 Azure 门户ARM 模板创建新的 Ubuntu Data Science Virtual Machine。Create a new Ubuntu Data Science Virtual Machine using the Azure portal or an ARM template.

在新的 Data Science Virtual Machine 上重新创建用户帐户Recreate user account(s) on your new Data Science Virtual Machine

由于你只需从旧计算机复制数据,因此需要重新创建要在新计算机上使用的任何用户帐户和软件环境。Since you'll just be copying data from your old computer, you'll need to recreate whichever user accounts and software environments that you want to use on the new machine.

Linux 足够灵活,允许你在新安装中自定义目录和路径,以遵循你的旧计算机的要求。Linux is flexible enough to allow you to customize directories and paths on your new installation to follow your old machine. 但一般情况下,在使用新式 Ubuntu 的首选布局的基础上根据情况修改用户环境和脚本更为容易。In general, though, it's easier to use the modern Ubuntu's preferred layout and modify your user environment and scripts to adapt.

有关详细信息,请参阅快速入门:设置适用于 Linux (Ubuntu) 的 Data Science Virtual MachineFor more information, see Quickstart: Set up the Data Science Virtual Machine for Linux (Ubuntu).

在新的 Data Science Virtual Machine 上装载快照 VM 的磁盘作为数据磁盘Mount the disk of the snapshotted VM as a data disk on your new Data Science Virtual Machine

  1. 在 Azure 门户中,确保你的 Data Science Virtual Machine 正在运行。In the Azure portal, make sure that your Data Science Virtual Machine is running.

  2. 在 Azure 门户中,转到你的 Data Science Virtual Machine 的页面。In the Azure portal, go to the page of your Data Science Virtual Machine. 选择左侧导轨上的“磁盘”边栏选项卡。Choose the Disks blade on the left rail. 选择“附加现有磁盘”。Choose Attach existing disks.

  3. 在“磁盘名称”下拉列表中,选择基于旧 VM 的快照创建的磁盘。In the Disk name dropdown, select the disk that you created from your old VM's snapshot.

DSVM 选项页的屏幕截图,其中显示了磁盘附加选项

  1. 选择“保存”以更新你的虚拟机。Select Save to update your virtual machine.

重要

在你附加数据磁盘时,你的 VM 应当正在运行。Your VM should be running at the time you attach the data disk. 如果 VM 未运行,则可能会按不正确的顺序添加磁盘,从而导致令人费解且可能无法启动的系统。If the VM isn't running, the disks may be added in an incorrect order, leading to a confusing and potentially non-bootable system. 如果在 VM 关闭的情况下添加数据磁盘,请选择数据磁盘旁边的 X ,启动 VM,然后重新附加它。If you add the data disk with the VM off, choose the X beside the data disk, start the VM, and re-attach it.

手动复制所需的数据Manually copy the wanted data

  1. 使用 SSH 登录到正在运行的虚拟机。Sign on to your running virtual machine using SSH.

  2. 通过运行以下命令,确认已附加了基于旧 VM 的快照创建的磁盘:Confirm that you've attached the disk created from your old VM's snapshot by running the following command:

    lsblk -o NAME,HCTL,SIZE,MOUNTPOINT | grep -i 'sd'
    

    结果应当类似于下图。The results should look something like the following image. 在图中,磁盘 sda1 装载到根目录上,sdb2/mnt 暂存磁盘。In the image, disk sda1 is mounted at the root and sdb2 is the /mnt scratch disk. 基于旧 VM 的快照创建的数据磁盘会被标识为 sdc1 但尚不可用,表现为缺少装载位置。The data disk created from the snapshot of your old VM is identified as sdc1 but isn't yet available, as evidenced by the lack of a mount location. 你的结果可能具有不同的标识符,但你应当会看到类似的模式。Your results might have different identifiers, but you should see a similar pattern.

    lsblk 输出的屏幕截图,其中显示了未装载的数据驱动器

  3. 若要访问数据驱动器,请为其创建一个位置并装载它。To access the data drive, create a location for it and mount it. /dev/sdc1 替换为 lsblk 返回的相应值:Replace /dev/sdc1 with the appropriate value returned by lsblk:

    sudo mkdir /datadrive && sudo mount /dev/sdc1 /datadrive
    
  4. 现在,/datadrive 包含旧 Data Science Virtual Machine 的目录和文件。Now, /datadrive contains the directories and files of your old Data Science Virtual Machine. 根据需要将所需的目录或文件从数据驱动器移动或复制到新 VM。Move or copy the directories or files you want from the data drive to the new VM as you wish.

有关详细信息,请参阅使用门户将数据磁盘附加到 Linux VMFor more information, see Use the portal to attach a data disk to a Linux VM.

连接并确认版本升级Connect and confirm version upgrade

无论是就地迁移还是并行迁移,都请确认是否已成功升级。Whether you did an in-place or side-by-side migration, confirm that you've successfully upgraded. 从终端会话中,运行:From a terminal session, run:

cat /etc/os-release

你应该会看到你正在运行 Ubuntu 18.04。And you should see that you're running Ubuntu 18.04.

Ubuntu 终端的屏幕截图,其中显示了 OS 版本数据

版本的更改也会显示在 Azure 门户中。The change of version is also shown in the Azure portal.

门户屏幕截图,其中显示了 DSVM 属性,包括 OS 版本

后续步骤Next steps