如何将物理机或虚拟机导入 Incus 实例¶
Incus 提供了一个工具 (incus-migrate
) 用于基于现有磁盘或镜像创建 Incus 实例。
您可以在任何 Linux 机器上运行该工具。它连接到 Incus 服务器并创建一个空白实例,您可以在迁移期间或之后配置该实例。然后,该工具将您提供的磁盘或镜像中的数据复制到实例中。
incus-migrate
可以导入 raw
、qcow2
和 vmdk
文件格式的镜像。
注意
如果您想在迁移过程中配置新实例,请在开始迁移过程之前设置您希望实例使用的实体。
默认情况下,新实例将使用 default
配置文件中指定的实体。您可以指定不同的配置文件(或配置文件列表)来自定义配置。有关更多信息,请参见 如何使用配置文件。您还可以覆盖 实例选项、要使用的 存储池 以及 存储卷 的大小,以及要使用的 网络。
或者,您可以在迁移完成后更新实例配置。
该工具可以创建容器和虚拟机
创建容器时,您必须提供一个包含容器根文件系统的磁盘或分区。例如,这可能是您运行该工具的机器或容器的
/
根磁盘。创建虚拟机时,您必须提供一个可启动的磁盘、分区或镜像。这意味着仅提供文件系统是不够的,您无法从正在运行的容器中创建虚拟机。也不可能从用于进行迁移的物理机中创建虚拟机,因为迁移工具将使用它正在复制的磁盘。相反,您可以提供一个可启动的镜像,或者当前未使用的可启动分区或磁盘。
提示
如果您想将 Windows 虚拟机从其他虚拟化程序(而不是使用 Q35/
virtio-scsi
的 QEMU/KVM)转换,您必须将virtio-win
驱动程序安装到 Windows。否则,您的虚拟机将无法启动。展开以查看如何将所需的驱动程序集成到您的 Windows 虚拟机中
在主机上安装所需的工具安装
virt-v2v
版本 >= 2.3.4(这是支持--block-driver
选项的最低版本)。安装
virtio-win
软件包,或下载virtio-win.iso
镜像并将其放入/usr/share/virtio-win
文件夹中。您可能还需要安装
rhsrvany
。
现在,您可以使用
virt-v2v
将其他虚拟化程序的镜像转换为 Incus 的raw
镜像,并包含所需的驱动程序# Example 1. Convert a vmdk disk image to a raw image suitable for incus-migrate sudo virt-v2v --block-driver virtio-scsi -o local -of raw -os ./os -i vmx ./test-vm.vmx # Example 2. Convert a QEMU/KVM qcow2 image and integrate virtio-scsi driver sudo virt-v2v --block-driver virtio-scsi -o local -of raw -os ./os -if qcow2 -i disk test-vm-disk.qcow2
您可以在
os
目录中找到生成的镜像,并在下一步中将其与incus-migrate
一起使用。
完成以下步骤将现有机器迁移到 Incus 实例
从最新 Incus 版本 的 Assets 部分下载
bin.linux.incus-migrate
工具 (bin.linux.incus-migrate.aarch64
或bin.linux.incus-migrate.x86_64
)。将该工具放置在您要用于创建实例的机器上。使其可执行(通常通过运行
chmod u+x bin.linux.incus-migrate
)。确保机器上安装了
rsync
。 如果缺少,请安装它(例如,使用sudo apt install rsync
)。运行工具
sudo ./bin.linux.incus-migrate
然后,工具会提示您提供迁移所需的信息。
提示
作为交互式运行工具的替代方法,您可以将配置作为参数提供给命令。 有关更多信息,请参见
./bin.linux.incus-migrate --help
。指定 Incus 服务器 URL,可以是 IP 地址或 DNS 名称。
注意
Incus 服务器必须 暴露给网络。 如果您想导入到本地 Incus 服务器,您仍然必须将其暴露给网络。 然后,您可以指定
127.0.0.1
作为访问本地服务器的 IP 地址。检查并确认证书指纹。
选择一种身份验证方法(参见 远程 API 身份验证)。
例如,如果您选择使用证书令牌,请登录 Incus 服务器,并使用
incus config trust add
为您运行迁移工具的机器创建令牌。 然后,使用生成的令牌对工具进行身份验证。选择是创建容器还是虚拟机。 参见 关于容器和虚拟机。
为要创建的实例指定一个名称。
提供根文件系统路径(对于容器)或可启动磁盘、分区或镜像文件路径(对于虚拟机)。
对于容器,可以选择添加其他文件系统挂载点。
对于虚拟机,指定是否支持安全启动。
可以选择配置新实例。 您可以通过指定 配置文件、直接设置 配置选项 或更改 存储 或 网络 设置来完成此操作。
或者,您可以在迁移后配置新实例。
完成配置后,启动迁移过程。
展开以查看导入到容器的示例输出
user@host:~$
sudo ./bin.linux.incus-migrate
Please provide Incus server URL: https://192.0.2.7:8443
Certificate fingerprint: xxxxxxxxxxxxxxxxx
ok (y/n)? y
1) Use a certificate token
2) Use an existing TLS authentication certificate
3) Generate a temporary TLS authentication certificate
Please pick an authentication mechanism above: 1
Please provide the certificate token: xxxxxxxxxxxxxxxx
Remote Incus server:
Hostname: bar
Version: 5.4
Would you like to create a container (1) or virtual-machine (2)?: 1
Name of the new instance: foo
Please provide the path to a root filesystem: /
Do you want to add additional filesystem mounts? [default=no]:
Instance to be created:
Name: foo
Project: default
Type: container
Source: /
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 3
Please specify config keys and values (key=value ...): limits.cpu=2
Instance to be created:
Name: foo
Project: default
Type: container
Source: /
Config:
limits.cpu: "2"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 4
Please provide the storage pool to use: default
Do you want to change the storage size? [default=no]: yes
Please specify the storage size: 20GiB
Instance to be created:
Name: foo
Project: default
Type: container
Source: /
Storage pool: default
Storage pool size: 20GiB
Config:
limits.cpu: "2"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 5
Please specify the network to use for the instance: incusbr0
Instance to be created:
Name: foo
Project: default
Type: container
Source: /
Storage pool: default
Storage pool size: 20GiB
Network name: incusbr0
Config:
limits.cpu: "2"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 1
Instance foo successfully created
展开以查看导入到虚拟机的示例输出
user@host:~$
sudo ./bin.linux.incus-migrate
Please provide Incus server URL: https://192.0.2.7:8443
Certificate fingerprint: xxxxxxxxxxxxxxxxx
ok (y/n)? y
1) Use a certificate token
2) Use an existing TLS authentication certificate
3) Generate a temporary TLS authentication certificate
Please pick an authentication mechanism above: 1
Please provide the certificate token: xxxxxxxxxxxxxxxx
Remote Incus server:
Hostname: bar
Version: 5.4
Would you like to create a container (1) or virtual-machine (2)?: 2
Name of the new instance: foo
Please provide the path to a root filesystem: ./virtual-machine.img
Does the VM support UEFI Secure Boot? [default=no]: no
Instance to be created:
Name: foo
Project: default
Type: virtual-machine
Source: ./virtual-machine.img
Config:
security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 3
Please specify config keys and values (key=value ...): limits.cpu=2
Instance to be created:
Name: foo
Project: default
Type: virtual-machine
Source: ./virtual-machine.img
Config:
limits.cpu: "2"
security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 4
Please provide the storage pool to use: default
Do you want to change the storage size? [default=no]: yes
Please specify the storage size: 20GiB
Instance to be created:
Name: foo
Project: default
Type: virtual-machine
Source: ./virtual-machine.img
Storage pool: default
Storage pool size: 20GiB
Config:
limits.cpu: "2"
security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 5
Please specify the network to use for the instance: incusbr0
Instance to be created:
Name: foo
Project: default
Type: virtual-machine
Source: ./virtual-machine.img
Storage pool: default
Storage pool size: 20GiB
Network name: incusbr0
Config:
limits.cpu: "2"
security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 1
Instance foo successfully created
迁移完成后,检查新实例,并将其配置更新到新环境。 通常,您至少必须更新存储配置(
/etc/fstab
)和网络配置。