> For the complete documentation index, see [llms.txt](https://richardweiyang-2.gitbook.io/understanding_qemu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://richardweiyang-2.gitbook.io/understanding_qemu/00-lm/01-migrate_command_line.md).

# 从用法说起

我们通过例子来看一下，要做一次热迁移需要如何操作。

## tcp传输

**源端**

```
sudo qemu-system-x86_64 -m 4G,slots=4,maxmem=128G -smp 4,maxcpus=16 --enable-kvm \
    -drive file=fedora29.img,format=raw -nographic
```

源端的qemu命令和平时的没有什么两样。

**目的端**

```
sudo qemu-system-x86_64 -m 4G,slots=4,maxmem=128G -smp 4,maxcpus=16 --enable-kvm \
    -drive file=fedora29.img,format=raw -nographic \
  -incoming tcp:0:4444
```

目的端要保证和源端的命令行是一样的，且要加&#x4E0A;**"-incoming tcp:0:4444"**

**开始迁移**

此时可以在源端的monitor中执行下面的命令开始迁移

```
migrate -d tcp:0:4444
```

## exec传输

这种严格来说不能叫热迁移，因为虚拟机有停顿。不过因为从命令行的形式上看类似，就放在这里。

**源端**

```
sudo qemu-system-x86_64 -m 4G,slots=4,maxmem=128G -smp 4,maxcpus=16 --enable-kvm \
    -drive file=fedora29.img,format=raw -nographic
```

虚拟机的启动是一样的，但是源端启动后就需要在monitor中执行

```
stop
migrate "exec cat > /backup_file"
quit
```

可以看到，源端的虚拟机不仅停止了，还退出了。

**目的端**

```
sudo qemu-system-x86_64 -m 4G,slots=4,maxmem=128G -smp 4,maxcpus=16 --enable-kvm \
    -drive file=fedora29.img,format=raw -nographic \
  -incoming "exec:cat < /backup_file"
```

运行之后在monitor中执行

```
cont
```

更多用法可以参考[Migration](https://www.linux-kvm.org/page/Migration)
