system: Provide a new VM image configuration.

* gnu/system/examples/vm-image.tmpl: Rewrite.
* doc/guix.texi (Running Guix in a VM): Adjust accordingly.
This commit is contained in:
Ludovic Courtès 2019-04-26 11:39:53 +02:00
parent 504a0fc636
commit 538b99f31f
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 79 additions and 42 deletions

View file

@ -24576,13 +24576,23 @@ example graph.
@section Running Guix in a Virtual Machine @section Running Guix in a Virtual Machine
@cindex virtual machine @cindex virtual machine
To run Guix in a virtual machine (VM), one can either use the To run Guix in a virtual machine (VM), one can use the pre-built Guix VM image
pre-built Guix VM image distributed at distributed at
@indicateurl{https://alpha.gnu.org/gnu/guix/guix-system-vm-image-@value{VERSION}.@var{system}.xz} @indicateurl{https://alpha.gnu.org/gnu/guix/guix-system-vm-image-@value{VERSION}.@var{system}.xz}
, or build their own virtual machine image using @command{guix system This image is a compressed image in QCOW format. You will first need to
vm-image} (@pxref{Invoking guix system}). The returned image is in decompress with @command{xz -d}, and then you can pass it to an emulator such
qcow2 format, which the @uref{http://qemu.org/, QEMU emulator} can as QEMU (see below for details).
efficiently use.
This image boots the Xfce graphical environment and it contains some
commonly-used tools. You can install more software in the image by running
@command{guix package} in a terminal (@pxref{Invoking guix package}). You can
also reconfigure the system based on its initial configuration file available
as @file{/etc/config.scm} (@pxref{Using the Configuration System}).
Instead of using this pre-built image, one can also build their own virtual
machine image using @command{guix system vm-image} (@pxref{Invoking guix
system}). The returned image is in qcow2 format, which the
@uref{http://qemu.org/, QEMU emulator} can efficiently use.
@cindex QEMU @cindex QEMU
If you built your own image, you must copy it out of the store If you built your own image, you must copy it out of the store
@ -24595,7 +24605,7 @@ vm-image} on x86_64 hardware:
@example @example
$ qemu-system-x86_64 \ $ qemu-system-x86_64 \
-net user -net nic,model=virtio \ -net user -net nic,model=virtio \
-enable-kvm -m 256 /tmp/qemu-image -enable-kvm -m 512 /tmp/qemu-image
@end example @end example
Here is what each of these options means: Here is what each of these options means:
@ -24621,7 +24631,7 @@ If your system has hardware virtualization extensions, enabling the
virtual machine support (KVM) of the Linux kernel will make things run virtual machine support (KVM) of the Linux kernel will make things run
faster. faster.
@item -m 256 @item -m 512
RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB, RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
which may be insufficient for some operations. which may be insufficient for some operations.

View file

@ -1,58 +1,85 @@
;;; This is an operating system configuration template for a "bare-bones" setup, ;; This is an operating system configuration for a VM image.
;;; suitable for booting in a virtualized environment, including virtual private ;; Modify it as you see fit and instantiate the changes by running:
;;; servers (VPS). ;;
;; guix system reconfigure /etc/config.scm
;;
(use-modules (gnu)) (use-modules (gnu) (srfi srfi-1))
(use-package-modules bootloaders disk nvi) (use-service-modules xorg desktop)
(use-package-modules bootloaders nvi wget xorg)
(define vm-image-motd (plain-file "motd" " (define vm-image-motd (plain-file "motd" "
This is the GNU system. Welcome! \x1b[1;37mThis is the GNU system. Welcome!\x1b[0m
This instance of Guix System is a bare-bones template for virtualized environments. This instance of Guix is a template for virtualized environments.
You can reconfigure the whole system by adjusting /etc/config.scm
and running:
You will probably want to do these things first if you booted in a virtual guix system reconfigure /etc/config.scm
private server (VPS):
\x1b[1;33mConsider setting a password for the 'root' and 'guest' \
accounts.\x1b[0m
"))
(define this-file
(local-file "./vm-image.tmpl" "config.scm"))
* Set a password for 'root'.
* Set up networking.
* Expand the root partition to fill the space available by 0) deleting and
recreating the partition with fdisk, 1) reloading the partition table with
partprobe, and then 2) resizing the filesystem with resize2fs.\n"))
(operating-system (operating-system
(host-name "gnu") (host-name "gnu")
(timezone "Etc/UTC") (timezone "Etc/UTC")
(locale "en_US.utf8") (locale "en_US.utf8")
(keyboard-layout (keyboard-layout "us" "altgr-intl"))
(firmware '()) (firmware '())
;; Assuming /dev/sdX is the target hard disk, and "my-root" is ;; Below we assume /dev/vda is the VM's hard disk.
;; the label of the target root file system. ;; Adjust as needed.
(bootloader (bootloader-configuration (bootloader (bootloader-configuration
(bootloader grub-bootloader) (bootloader grub-bootloader)
(target "/dev/sda") (target "/dev/vda")
(terminal-outputs '(console)))) (terminal-outputs '(console))))
(file-systems (cons (file-system (file-systems (cons (file-system
(device (file-system-label "my-root"))
(mount-point "/") (mount-point "/")
(device "/dev/vda1")
(type "ext4")) (type "ext4"))
%base-file-systems)) %base-file-systems))
;; This is where user accounts are specified. The "root" (users (cons (user-account
;; account is implicit, and is initially created with the (name "guest")
;; empty password. (comment "GNU Guix Live")
(users %base-user-accounts) (password "") ;no password
(group "users")
(supplementary-groups '("wheel" "netdev"
"audio" "video")))
%base-user-accounts))
;; Globally-installed packages. (packages (append (list nvi wget) %base-packages))
(packages (append (list nvi fdisk
;; mostly so xrefs to its manual work
grub
;; partprobe
parted)
%base-packages))
(services (modify-services %base-services (services
(login-service-type config => (append (list (service xfce-desktop-service-type)
(login-configuration
(inherit config) ;; Copy this file to /etc/config.scm in the OS.
(motd vm-image-motd)))))) (simple-service 'config-file etc-service-type
`(("config.scm" ,this-file)))
;; Choose SLiM, which is lighter than the default GDM.
(service slim-service-type
(slim-configuration
(auto-login? #t)
(default-user "guest")
(xorg-configuration
(xorg-configuration
(keyboard-layout keyboard-layout))))))
;; Remove GDM.
(remove (lambda (service)
(eq? gdm-service-type (service-kind service)))
(modify-services %desktop-services
(login-service-type config =>
(login-configuration
(inherit config)
(motd vm-image-motd)))))))
;; Allow resolution of '.local' host names with mDNS.
(name-service-switch %mdns-host-lookup-nss))