> 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)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://richardweiyang-2.gitbook.io/understanding_qemu/00-lm/01-migrate_command_line.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
