To run Guix in a virtual machine (VM), one can use the pre-built Guix VM image distributed at https://ftp.gnu.org/gnu/guix/guix-system-vm-image-8a35479.x86_64-linux.qcow2. This image is a compressed image in QCOW format. You can pass it to an emulator such as QEMU (see below for details).
This image boots the Xfce graphical environment and it contains some
commonly used tools. You can install more software in the image by running
guix package in a terminal (see 调用guix package). You
can also reconfigure the system based on its initial configuration file
available as /run/current-system/configuration.scm (see 使用配置系统).
Instead of using this pre-built image, one can also build their own image
guix system image (see 调用guix system).
If you built your own image, you must copy it out of the store (see 仓库) and give yourself permission to write to the copy before you can use
it. When invoking QEMU, you must choose a system emulator that is suitable
for your hardware platform. Here is a minimal QEMU invocation that will
boot the result of
guix system image -t qcow2 on x86_64 hardware:
$ qemu-system-x86_64 \ -nic user,model=virtio-net-pci \ -enable-kvm -m 1024 \ -device virtio-blk,drive=myhd \ -drive if=none,file=/tmp/qemu-image,id=myhd
Here is what each of these options means:
This specifies the hardware platform to emulate. This should match the host.
Enable the unprivileged user-mode network stack. The guest OS can access
the host but not vice versa. This is the simplest way to get the guest OS
model specifies which network device to emulate:
virtio-net-pci is a special device made for virtualized operating
systems and recommended for most uses. Assuming your hardware platform is
x86_64, you can get a list of available NIC models by running
qemu-system-x86_64 -nic model=help.
If your system has hardware virtualization extensions, enabling the virtual machine support (KVM) of the Linux kernel will make things run faster.
RAM available to the guest OS, in mebibytes. Defaults to 128 MiB, which may be insufficient for some operations.
virtio-blk drive called “myhd”.
virtio-blk is a
“paravirtualization” mechanism for block devices that allows QEMU to
achieve better performance than if it were emulating a complete disk drive.
See the QEMU and KVM documentation for more info.
Use our QCOW image, the /tmp/qemu-image file, as the backing store of the “myhd” drive.
run-vm.sh script that is returned by an invocation of
guix system vm does not add a
-nic user flag by
default. To get network access from within the vm add the
(dhcp-client-service) to your system definition and start the VM
$(guix system vm config.scm) -nic user. An important caveat
-nic user for networking is that
ping will not
work, because it uses the ICMP protocol. You’ll have to use a different
command to check for network connectivity, for example
To enable SSH inside a VM you need to add an SSH server like
openssh-service-type to your VM (see
openssh-service-type). In addition you need to forward the SSH
port, 22 by default, to the host. You can do this with
$(guix system vm config.scm) -nic user,model=virtio-net-pci,hostfwd=tcp::10022-:22
To connect to the VM you can run
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 localhost
ssh the port you want to connect to.
-o UserKnownHostsFile=/dev/null prevents
complaining every time you modify your
config.scm file and the
-o StrictHostKeyChecking=no prevents you from having to allow a
connection to an unknown host every time you connect.
注: If you find the above ‘hostfwd’ example not to be working (e.g., your SSH client hangs attempting to connect to the mapped port of your VM), make sure that your Guix System VM has networking support, such as by using the
As an alternative to the default
qemu graphical client you can use
remote-viewer from the
virt-viewer package. To
connect pass the
-spice port=5930,disable-ticketing flag to
qemu. See previous section for further information on how to do
Spice also allows you to do some nice stuff like share your clipboard with
your VM. To enable that you’ll also have to pass the following flags to
-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5 -chardev spicevmc,name=vdagent,id=vdagent -device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,\ name=com.redhat.spice.0
You’ll also need to add the
(spice-vdagent-service) to your system
definition (see Spice service).