Docs
文档
Getting started
快速上手
Install AnyVM, boot a guest, and run something inside it. Five minutes, most of which is the image download.
装上 AnyVM,开一台虚拟机,在里面跑点东西。五分钟,其中大部分时间是在下载镜像。
Install AnyVM
安装 AnyVM
AnyVM is one Python file. Any of these gets you the anyvm
command; they differ only in how the file lands on your machine.
AnyVM 就是一个 Python 文件。下面几种装法结果都一样,最后都给你
anyvm 命令,区别只在于这个文件怎么到你机器上。
pip
$ pip install anyvm.py
This installs both an anyvm and an anyvm.py
command.
这会同时装上 anyvm 和 anyvm.py 两条命令。
pip install with an
externally-managed-environment error (PEP 668). Use pipx:
Debian 和 Ubuntu:系统自带的 Python 会拒绝
pip install,报 externally-managed-environment
错误(PEP 668)。改用 pipx:
$ sudo apt-get install -y pipx $ pipx install anyvm.py $ pipx ensurepath # first time only, then reopen the shell
python3 -m venv ~/.venvs/anyvm && ~/.venvs/anyvm/bin/pip install anyvm.py
Homebrew (macOS)
Homebrew(macOS)
$ brew install anyvm-org/tap/anyvm
The tap installs qemu and zstd as dependencies,
so you can skip the next section entirely.
这个 tap 会把 qemu 和 zstd 一起装上,所以
下一节可以整个跳过。
winget (Windows)
winget(Windows)
$ winget install anyvm-org.anyvm
This one is a self-contained build with Python bundled in, so the machine needs nothing else except QEMU.
这个版本打包了 Python,机器上除了 QEMU 什么都不用另装。
Docker
Docker
$ docker run --rm -it ghcr.io/anyvm-org/anyvm:latest --os freebsd
A container with QEMU already set up. More tags and examples in anyvm-org/docker.
QEMU 都配好了的容器。更多标签和用法见 anyvm-org/docker。
The single file
直接下那个文件
$ curl -O https://raw.githubusercontent.com/anyvm-org/anyvm/main/anyvm.py $ python3 anyvm.py --os freebsd
anyvm.py imports nothing outside the Python standard library,
so this one file is the entire program. Commit it to a repo, bake it into
a CI image, or scp it to a jump host -- it runs the same everywhere.
anyvm.py 不 import 标准库以外的任何东西,所以这一个文件就是全部。
提交进仓库、打进 CI 镜像、scp 到跳板机都行,到哪跑起来都一样。
Install QEMU
安装 QEMU
AnyVM drives QEMU; it does not bundle it. Install it once for your host.
AnyVM 是去驱动 QEMU,本身不带 QEMU。按你的宿主装一次就行。
Linux (apt-based)
Linux(apt 系)
$ sudo apt-get --no-install-recommends -y install \
zstd ovmf xz-utils qemu-utils ca-certificates \
qemu-system-x86 qemu-system-arm qemu-efi-aarch64 \
qemu-efi-riscv64 qemu-system-riscv64 qemu-system-misc u-boot-qemu \
qemu-system-ppc qemu-system-s390x qemu-system-sparc \
openssh-client
That list covers every guest architecture. If you only care about x86_64
guests, qemu-system-x86, qemu-utils,
ovmf and zstd are enough.
这一串覆盖了所有客户机架构。如果你只跑 x86_64,装
qemu-system-x86、qemu-utils、ovmf
和 zstd 就够了。
macOS
macOS
$ brew install qemu
Windows
Windows
Download an installer from qemu.org, or use a package manager:
从 qemu.org 下安装包,或者用包管理器:
# winget $ winget install SoftwareFreedomConservancy.QEMU # MSYS2 $ pacman.exe -S --noconfirm mingw-w64-ucrt-x86_64-qemu # Chocolatey $ choco install qemu
Your first VM
开第一台虚拟机
$ anyvm --os freebsd
AnyVM picks the newest FreeBSD release it publishes, downloads the image,
boots it under QEMU with settings known to work for that guest, waits for
SSH, and drops you into a shell inside the VM. Type exit to
leave.
AnyVM 会挑它发布过的最新 FreeBSD 版本,下载镜像,用这个系统已知能跑通的参数
在 QEMU 里启动,等 SSH 起来,然后把你送进虚拟机的 shell。敲
exit 退出。
Images are cached, so the second boot of the same guest skips the
download. Everything lives under ./output by default; change
it with --data-dir.
镜像会缓存,所以同一个系统第二次启动就不用再下了。东西默认都放在
./output 下,用 --data-dir 可以改。
Run a command instead of a shell
不进 shell,直接跑命令
Everything after -- runs inside the guest, and AnyVM exits
with that command's status. This is the shape you want in scripts and CI.
-- 后面的东西都在虚拟机里执行,AnyVM 用那条命令的退出码退出。
写脚本和 CI 的时候就该用这种形式。
$ anyvm --os freebsd -- uname -a $ anyvm --os openbsd -- sh -lc "id; sysctl hw.model" $ anyvm --os ubuntu -- ./run-tests.sh
Combine it with -v below and you have a portable way to build
and test your working tree on an operating system you do not run.
再配上下面的 -v,你就有了一个便携的办法:把手头的代码拿到一个
自己根本没装的系统上去编译和测试。
Releases and architectures
版本和架构
$ anyvm --os freebsd --release 14.4 $ anyvm --os freebsd --release 15.1 --arch riscv64 $ anyvm --os netbsd --release 11.0 --arch sparc64 $ anyvm --os ubuntu --release 24.04 --arch s390x
Omit --release and AnyVM picks an available one for you.
Release names are matched case-insensitively, so
--release 24.03-lts-sp4 finds OpenEuler's
24.03-LTS-SP4.
不写 --release 的话,AnyVM 会自己挑一个可用版本。版本名不区分
大小写,所以 --release 24.03-lts-sp4 能匹配到 OpenEuler 的
24.03-LTS-SP4。
Each builder repository owns the authoritative release list for its guest -- guest notes links to all of them.
每个系统支持哪些版本,以它自己的 builder 仓库为准 —— 系统说明里有全部链接。
Share a directory
共享目录
# Linux and macOS $ anyvm --os freebsd -v "$PWD:/data" # Windows $ anyvm --os freebsd -v D:\data:/data
-v is repeatable. The mechanism behind it is selectable with
--sync:
-v 可以写多次。底下用什么机制,由 --sync 决定:
| Mode模式 | What it does做什么 |
|---|---|
rsync | The default. A one-shot copy in, and back out when the command finishes.默认。进去时拷一次,命令跑完再拷回来。 |
sshfs | A live mount inside the guest over SSH.通过 SSH 在虚拟机里做实时挂载。 |
nfs | The bundled user-space NFS server (nfsd). No kernel nfsd, no root, works on Linux, macOS and Windows hosts.自带的用户态 NFS 服务器(nfsd)。不用内核 nfsd,不用 root,Linux、macOS、Windows 宿主都能用。 |
sys-nfs | The host's kernel NFS server. Linux host with root only.宿主的内核 NFS 服务器。只能在有 root 的 Linux 宿主上用。 |
scp | A one-shot copy, for guests where a live mount is a bad idea.一次性拷贝,给那些不适合做实时挂载的系统用。 |
9p | Plan 9 only, and its default there. Mounts the guest's 9P share on the host, so it needs a Linux host.只用于 Plan 9,也是它的默认值。把虚拟机的 9P 共享挂到宿主上,所以需要 Linux 宿主。 |
nfs and sys-nfs:
OpenBSD, NetBSD and DragonFly BSD guests are NFSv3-only and reach the
bundled server through its portmapper on port 111. That port is free on
Windows and macOS hosts, but usually owned by the system
rpcbind on Linux -- so use sys-nfs for those
three guests on a Linux host. There is no automatic fallback between the
two.
nfs 和 sys-nfs 怎么选:
OpenBSD、NetBSD、DragonFlyBSD 只支持 NFSv3,要通过 111 端口上的 portmapper
才能连到自带的服务器。这个端口在 Windows 和 macOS 上是空的,但在 Linux 上通常
被系统的 rpcbind 占着 —— 所以这三个系统在 Linux 宿主上要用
sys-nfs。两者之间不会自动切换。
Forward a port
端口转发
$ anyvm --os ubuntu -p 8080:80 $ anyvm --os ubuntu -p tcp:8443:443 -p udp:5353:5353
Forwards bind to 127.0.0.1. Add --public to bind
0.0.0.0 instead. Guest SSH is forwarded automatically to a
free port; pin it with --ssh-port.
转发默认绑在 127.0.0.1 上,加 --public 改成绑
0.0.0.0。虚拟机的 SSH 会自动转发到一个空闲端口,想固定就用
--ssh-port。
Desktops and the VNC web UI
桌面和 VNC 网页控制台
Several guests publish desktop images. Ask for one by release name:
好几个系统都发布了桌面镜像,用版本名指定就行:
$ anyvm --os freebsd --release 15.1-kde6 $ anyvm --os openbsd --release 7.9-xfce $ anyvm --os ghostbsd --release 26.1-gershwin
The VNC web UI starts by default at http://localhost:6080
(the next free port if 6080 is taken -- the actual URL is printed at
startup), so a desktop guest is one browser tab away. It supports
clipboard paste, fullscreen and a Ctrl+Alt+Del button.
VNC 网页控制台默认开在 http://localhost:6080(6080 被占就往后顺延,
实际地址启动时会打印出来),所以桌面系统开个浏览器标签页就能用。支持粘贴剪贴板、
全屏,还有一个 Ctrl+Alt+Del 按钮。
# Password-protect it (any username, the password is what matters) $ anyvm --os openbsd --release 7.9-xfce --vnc-password mysecret # Put it on a public URL via a tunnel $ anyvm --os openbsd --release 7.9-xfce --remote-vnc # Turn it off $ anyvm --os freebsd --vnc off
Host support
宿主支持
Which guest architectures you can run depends on the host you are on. A Linux x86_64 host -- including WSL -- covers everything.
你能跑哪些客户机架构,取决于你用的宿主。一台 Linux x86_64(WSL 也算)全都能跑。
| Host宿主 | x86_64 | aarch64 | riscv64 | s390x | powerpc64 | sparc64 | loongarch64 |
|---|---|---|---|---|---|---|---|
| Linux x86_64 | |||||||
| Linux aarch64 | |||||||
| Linux s390x (IBM Z) | |||||||
| macOS Apple siliconmacOS Apple 芯片 | |||||||
| Windows x86_64, nativeWindows x86_64 原生 | |||||||
| Windows x86_64, WSLWindows x86_64 WSL |
Hardware acceleration -- KVM, HVF or WHPX -- is detected and enabled automatically for same-architecture guests. Everything else runs under TCG.
同架构的客户机会自动检测并启用硬件加速 —— KVM、HVF 或 WHPX。其余的都走 TCG。
Try it without installing anything
什么都不装也能试
Both of these give you a machine with nested virtualization and drop you straight into the repository:
下面两个都会给你一台支持嵌套虚拟化的机器,并直接把仓库打开:
In Codespaces, enable KVM first:
在 Codespaces 里要先打开 KVM:
$ sudo chmod o+rw /dev/kvm $ sudo apt-get update $ sudo apt-get --no-install-recommends -y install \ zstd ovmf xz-utils qemu-utils ca-certificates \ qemu-system-x86 qemu-system-arm qemu-efi-aarch64 \ qemu-efi-riscv64 qemu-system-riscv64 qemu-system-misc u-boot-qemu \ qemu-system-ppc qemu-system-s390x qemu-system-sparc \ openssh-client