如何保留 QEMU VM 镜像中的更改?

How to retain the changes in the QEMU VM image?

我想使用 QEMU 来模拟 Linux OS 并为 Tiny Core Linux (TCL) 创建一个虚拟机 (VM)。我通过 QEMU 在 运行 TCL VM 中使用了以下命令。

首先,我创建了一个qcow2格式的虚拟机镜像(我也试过创建.img镜像,但好像效果一样):

qemu-img create -f qcow2 TCLcoredisk.qcow2 1G

然后,我用QEMU模拟器启动了TCL。效果很好,我可以在虚拟机中做一些操作(比如新建目录和文件,挂载文件系统)。

qemu-system-x86_64 -boot d \
    -cdrom Core-current.iso \
    -m 500 \
    -hda TCLcoredisk.qcow2 \
    -nographic \
    -enable-kvm \
    -curses

问题是在我关闭 QEMU(pkill QEMU 进程)后,我无法保留通过启动之前的映像文件所做的更改。更糟糕的是,我什至无法启动映像。我只能通过 -cdrom.iso 映像文件启动,但更改将会丢失。但是,由于我在第一次启动时将文件系统挂载到新建的目录中,所以再次启动TCLcoredisk.qcow2镜像文件时,所有第一次启动的信息都丢失了。我使用以下命令来启动这个现有的映像文件:

qemu-system-x86_64 -drive "file=TCLcoredisk.qcow2,format=qcow2" \
    -m 500 \
    -nographic \ 
    -enable-kvm \
    -curses

我收到错误 Nothing to boot: No such file or directory (http://ipxe.org/2d03e13b)。我的主机只支持命令行,不使用图形界面,这就是我使用-nographic-curses的原因。我也想只通过命令行使用 TCL。我想在第一次启动后我不需要再使用 .iso 图像文件了。有没有办法可以正确启动现有的映像文件并保留以前启动时的更改?谢谢!

有人指出,在 FAQ 上,Tiny Core Linux 仅基于 RAM。因此你不能使用持久文件系统

What is the boot architecture?

Tinycore always boots to ram. This unique way has several advantages, like 100% functioning usb boot, awesome speed, and being able to boot without having the ability to access the boot device after booting. You're free to snag out the usb drive right after initrd is loaded, for example. https://distro.ibiblio.org/tinycorelinux/faq.html#arch

您将需要使用另一个发行版