2021-06-08 22:46:18 +00:00
|
|
|
# Live Migration
|
|
|
|
|
|
|
|
This document gives two examples of how to use the live migration
|
|
|
|
support in Cloud Hypervisor:
|
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
1. local migration - migrating a VM from one Cloud Hypervisor instance to another on the same machine;
|
|
|
|
1. remote migration - migrating a VM between two machines;
|
|
|
|
|
|
|
|
> :warning: These examples place sockets /tmp. This is done for
|
|
|
|
> simplicity and should not be done in production.
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2022-01-17 16:41:44 +00:00
|
|
|
## Local Migration (Suitable for Live Upgrade of VMM)
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2021-06-08 22:46:18 +00:00
|
|
|
Launch the source VM (on the host machine):
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2021-06-08 22:46:18 +00:00
|
|
|
$ target/release/cloud-hypervisor
|
|
|
|
--kernel ~/workloads/vmlinux \
|
|
|
|
--disk path=~/workloads/focal.raw \
|
2022-01-17 16:41:44 +00:00
|
|
|
--cpus boot=1 --memory size=1G,shared=on \
|
2021-06-08 22:46:18 +00:00
|
|
|
--cmdline "root=/dev/vda1 console=ttyS0" \
|
2023-09-11 15:32:41 +00:00
|
|
|
--serial tty --console off --api-socket=/tmp/api1
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Launch the destination VM from the same directory (on the host machine):
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2023-09-11 15:32:41 +00:00
|
|
|
$ target/release/cloud-hypervisor --api-socket=/tmp/api2
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Get ready for receiving migration for the destination VM (on the host machine):
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2023-09-11 15:32:41 +00:00
|
|
|
$ target/release/ch-remote --api-socket=/tmp/api2 receive-migration unix:/tmp/sock
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Start to send migration for the source VM (on the host machine):
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2023-09-11 15:32:41 +00:00
|
|
|
$ target/release/ch-remote --api-socket=/tmp/api1 send-migration --local unix:/tmp/sock
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
When the above commands completed, the source VM should be successfully
|
|
|
|
migrated to the destination VM. Now the destination VM is running while
|
2021-08-25 17:48:52 +00:00
|
|
|
the source VM is terminated gracefully.
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
## Remote Migration
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
In this example, we will migrate a VM from one machine (`src`) to
|
|
|
|
another (`dst`) across the network. To keep it simple, we will use a
|
|
|
|
minimal VM setup without storage.
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
Because Cloud Hypervisor does not natively support migrating via TCP
|
|
|
|
connections, we will tunnel traffic through `socat`.
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
### Preparation
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
Make sure that `src` and `dst` can reach each other via the
|
|
|
|
network. You should be able to ping each machine. Also each machine
|
|
|
|
should have an open TCP port. For this example we assume port 6000.
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
You will need a kernel and initramfs for a minimal Linux system. For
|
|
|
|
this example, we will use the Debian netboot image.
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
Place the kernel and initramfs into the _same directory_ on both
|
|
|
|
machines. This is important for the migration to succeed. We will use
|
|
|
|
`/var/images`:
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2024-11-29 10:41:31 +00:00
|
|
|
src $ export DEBIAN=https://ftp.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/debian-installer/amd64
|
|
|
|
src $ mkdir -p /var/images
|
|
|
|
src $ curl $DEBIAN/linux > /var/images/linux
|
|
|
|
src $ curl $DEBIAN/initrd.gz > /var/images/initrd
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
Repeat the above steps on the destination host.
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
### Starting the Receiver VM
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
On the receiver side, we prepare an empty VM:
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
```console
|
|
|
|
dst $ cloud-hypervisor --api-socket /tmp/api
|
|
|
|
```
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
In a different terminal, configure the VM as a migration target:
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
```console
|
|
|
|
dst $ ch-remote --api-socket=/tmp/api receive-migration unix:/tmp/sock
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
In yet another terminal, forward TCP connections to the Unix domain socket:
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2024-11-29 10:41:31 +00:00
|
|
|
dst $ socat TCP-LISTEN:6000,reuseaddr UNIX-CLIENT:/tmp/sock
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
2024-11-28 15:51:32 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
### Starting the Sender VM
|
2021-06-08 22:46:18 +00:00
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
Let's start the VM on the source machine:
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2024-11-29 10:41:31 +00:00
|
|
|
src $ cloud-hypervisor \
|
|
|
|
--serial tty --console off \
|
|
|
|
--cpus boot=2 --memory size=4G \
|
|
|
|
--kernel /var/images/linux \
|
|
|
|
--initramfs /var/images/initrd \
|
|
|
|
--cmdline "console=ttyS0" \
|
|
|
|
--api-socket /tmp/api
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
After a few seconds the VM should be up and you can interact with it.
|
|
|
|
|
|
|
|
### Performing the Migration
|
|
|
|
|
|
|
|
First, we start `socat`:
|
2024-11-28 15:51:32 +00:00
|
|
|
|
|
|
|
```console
|
2024-11-29 10:41:31 +00:00
|
|
|
src $ socat UNIX-LISTEN:/tmp/sock,reuseaddr TCP:dst:6000
|
2021-06-08 22:46:18 +00:00
|
|
|
```
|
|
|
|
|
2024-11-29 10:41:31 +00:00
|
|
|
Then we kick-off the migration itself:
|
|
|
|
|
|
|
|
```console
|
|
|
|
src $ ch-remote --api-socket=/tmp/api send-migration unix:/tmp/sock
|
|
|
|
```
|
|
|
|
|
|
|
|
When the above commands completed, the VM should be successfully
|
|
|
|
migrated to the destination machine without interrupting the workload.
|