Notes about using virtualization technologies on Guix.
Read more about qemu.
Let’s say you wanted to run PantherX Desktop in a virtual machine.
Create a system config px-desktop-config_vm.scm
:
;; PantherX OS Desktop Configuration v2
;; for Virtual machine
(use-modules (gnu)
(gnu system)
(px system config))
(px-desktop-os
(operating-system
(host-name "px-base")
(timezone "Europe/Berlin")
(locale "en_US.utf8")
(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(target "/dev/vda")
(terminal-outputs '(console))))
(file-systems (cons (file-system
(mount-point "/")
(device "/dev/vda1")
(type "ext4"))
%base-file-systems))
(users (cons (user-account
(name "panther")
(comment "panther's account")
(group "users")
;; Set the default password to 'pantherx'
;; Important: Change with 'passwd panther' after first login
(password (crypt "pantherx" "$6$abc"))
(supplementary-groups '("wheel"
"audio" "video"))
(home-directory "/home/panther"))
%base-user-accounts))
;; Globally-installed packages.
(packages (cons*
%px-desktop-packages))
;; Globally-activated services.
(services (cons*
%px-desktop-services))))
Build a VM from px-desktop-config_vm.scm
:
guix system vm guix-desktop-vm_image.scm --substitute-urls='https://bordeaux.guix.gnu.org https://packages.pantherx.org'
Once that’s done, you should get a bash script:
building /gnu/store/v6s7975lv0z95ss2k7bjc5y5j9myh4ap-copy-image.drv...
building /gnu/store/z73xm20ipfdbqwid5mvlpfysp83lf8m9-run-vm.sh.drv...
/gnu/store/7d6mi0wpfyxsxy25rd8gcnj1x5szdgcr-run-vm.sh
Run like this:
/gnu/store/7d6mi0wpfyxsxy25rd8gcnj1x5szdgcr-run-vm.sh -m 2048 -smp 2 -nic user,model=virtio-net-pci -enable-kvm
Notes:
m
is memorysmp
is the processor countenable-kvm
will enable hardware acceleration (you should! enable this)Important: To actually use the -enable-kvm
flag, you need to enable it for your user, in the system configuration at /etc/system.scm
. Learn more: More performance using KVM
Login with password pantherx
.
alternatively we can generate a disk image in QCOW2 format, containing Guix instance installed on match with our provided configuration file.
$ guix system vm-image /path/to/config.scm
...
/gnu/store/...-qemu-image
later we can run this image using qemu
.
$ qemu-system-x86_64 \
-nic user,model=virtio-net-pci \
-enable-kvm -m 1024 \
-device virtio-blk,drive=myhd \
-drive if=none,file=/path/to/...-qemu-image,id=myhd
running the disk image there are a series of items that we need to consider:
(1) generated disk image will be saved in store
, and since store is a read-only location, we need to copy that to some other place and assign write permission before we can use generated image.
(2) default image generated using guix system vm-image
usually doesn’t have enough space for additional files and packages to store/install. so if we need more space, we should pass our desired size using --image-size
parameter.
$ guix system vm-image /path/to/config.scm --image-size=10G
(3) in order to have ssh access to the virtual machine, we need to forward default ssh port of the guest machine to some other port in host using hostfwt
parameter of QEMU:
$ qemu-system-x86_64 -nic user,model=virtio-net-pci,hostfwd=tcp::10022-:22 ...
(4) later we can connect to guest machine using ssh client:
$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 root@127.0.0.1
in order to switch to other virtual TTY in guest os, we need to switch to monitoring console of QEMU using ctrl+alt+2
and send our key combination using sendkey
command:
sendkey ctrl-alt-f2
later we can switch back to default console using ctrl+alt+1
command.
PantherX & (unofficial) GNU Guix Wiki.
Last update: 2024-04-21 10:28:03 +0000 | Apache-2.0
Inspired by the excellent Arch Linux Wiki