Next: , Previous: , Up: System Configuration   [Contents][Index]


10.16 Running Guix in a Virtual Machine

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-1.3.0.8543-039c3-dirty.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 Invoking guix package). You can also reconfigure the system based on its initial configuration file available as /run/current-system/configuration.scm (see Using the Configuration System).

Instead of using this pre-built image, one can also build their own image using guix system image (see Invoking guix system).

If you built your own image, you must copy it out of the store (see The Store) 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:

qemu-system-x86_64

This specifies the hardware platform to emulate. This should match the host.

-nic user,model=virtio-net-pci

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 online. 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.

-enable-kvm

If your system has hardware virtualization extensions, enabling the virtual machine support (KVM) of the Linux kernel will make things run faster.

-m 1024

RAM available to the guest OS, in mebibytes. Defaults to 128 MiB, which may be insufficient for some operations.

-device virtio-blk,drive=myhd

Create a 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.

-drive if=none,file=/tmp/qemu-image,id=myhd

Use our QCOW image, the /tmp/qemu-image file, as the backing store of the “myhd” drive.

The default 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 using $(guix system vm config.scm) -nic user. An important caveat of using -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 guix download.

10.16.1 Connecting Through SSH

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

The -p tells ssh the port you want to connect to. -o UserKnownHostsFile=/dev/null prevents ssh from 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.

Note: 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 dhcp-client-service-type service type.

10.16.2 Using virt-viewer with Spice

As an alternative to the default qemu graphical client you can use the 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 this.

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 qemu:

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


Next: , Previous: , Up: System Configuration   [Contents][Index]