X-Git-Url: https://git.hcoop.net/jackhill/guix/guix.git/blobdiff_plain/f7f292d359e0eb77617f4ecf6b3164f868ec1784..19008a22d18e772062952034c58a15ed341df3b5:/gnu/tests/install.scm diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm index ecf1ac1923..277908cc49 100644 --- a/gnu/tests/install.scm +++ b/gnu/tests/install.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2016 Ludovic Courtès +;;; Copyright © 2016, 2017, 2018, 2019 Ludovic Courtès +;;; Copyright © 2017 Tobias Geerinckx-Rice ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,15 +19,17 @@ (define-module (gnu tests install) #:use-module (gnu) + #:use-module (gnu bootloader extlinux) #:use-module (gnu tests) #:use-module (gnu tests base) #:use-module (gnu system) #:use-module (gnu system install) #:use-module (gnu system vm) #:use-module ((gnu build vm) #:select (qemu-command)) + #:use-module (gnu packages bootloaders) #:use-module (gnu packages ocr) - #:use-module (gnu packages qemu) #:use-module (gnu packages package-management) + #:use-module (gnu packages virtualization) #:use-module (guix store) #:use-module (guix monads) #:use-module (guix packages) @@ -34,13 +37,17 @@ #:use-module (guix gexp) #:use-module (guix utils) #:export (%test-installed-os + %test-installed-extlinux-os + %test-iso-image-installer %test-separate-store-os + %test-separate-home-os %test-raid-root-os - %test-encrypted-os)) + %test-encrypted-root-os + %test-btrfs-root-os)) ;;; Commentary: ;;; -;;; Test the installation of GuixSD using the documented approach at the +;;; Test the installation of Guix using the documented approach at the ;;; command line. ;;; ;;; Code: @@ -54,11 +61,12 @@ (timezone "Europe/Paris") (locale "en_US.UTF-8") - (bootloader (grub-configuration (device "/dev/vdb"))) + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) (kernel-arguments '("console=ttyS0")) (file-systems (cons (file-system - (device "my-root") - (title 'label) + (device (file-system-label "my-root")) (mount-point "/") (type "ext4")) %base-file-systems)) @@ -75,6 +83,37 @@ (guix combinators))))) %base-services)))) +(define (operating-system-add-packages os packages) + "Append PACKAGES to OS packages list." + (operating-system + (inherit os) + (packages (append packages (operating-system-packages os))))) + +(define-os-with-source (%minimal-extlinux-os + %minimal-extlinux-os-source) + (use-modules (gnu) (gnu tests) (gnu bootloader extlinux) + (srfi srfi-1)) + + (operating-system + (host-name "liberigilo") + (timezone "Europe/Paris") + (locale "en_US.UTF-8") + + (bootloader (bootloader-configuration + (bootloader extlinux-bootloader-gpt) + (target "/dev/vdb"))) + (kernel-arguments '("console=ttyS0")) + (file-systems (cons (file-system + (device (file-system-label "my-root")) + (mount-point "/") + (type "ext4")) + %base-file-systems)) + (services (cons (service marionette-service-type + (marionette-configuration + (imported-modules '((gnu services herd) + (guix combinators))))) + %base-services)))) + (define (operating-system-with-current-guix os) "Return a variant of OS that uses the current Guix." (operating-system @@ -89,7 +128,11 @@ "Return a variant of OS where ROOTS are registered as GC roots." (operating-system (inherit os) - (services (cons (service gc-root-service-type roots) + + ;; We use this procedure for the installation OS, which already defines GC + ;; roots. Add ROOTS to those. + (services (cons (simple-service 'extra-root + gc-root-service-type roots) (operating-system-user-services os))))) @@ -106,7 +149,7 @@ export GUIX_BUILD_OPTIONS=--no-grafts guix build isc-dhcp parted --script /dev/vdb mklabel gpt \\ mkpart primary ext2 1M 3M \\ - mkpart primary ext2 3M 1G \\ + mkpart primary ext2 3M 1.2G \\ set 1 boot on \\ set 1 bios_grub on mkfs.ext4 -L my-root /dev/vdb2 @@ -119,23 +162,52 @@ guix system init /mnt/etc/config.scm /mnt --no-substitutes sync reboot\n") +(define %extlinux-gpt-installation-script + ;; Shell script of a simple installation. + ;; As syslinux 6.0.3 does not handle 64bits ext4 partitions, + ;; we make sure to pass -O '^64bit' to mkfs. + "\ +. /etc/profile +set -e -x +guix --version + +export GUIX_BUILD_OPTIONS=--no-grafts +guix build isc-dhcp +parted --script /dev/vdb mklabel gpt \\ + mkpart ext2 1M 1.2G \\ + set 1 legacy_boot on +mkfs.ext4 -L my-root -O '^64bit' /dev/vdb1 +mount /dev/vdb1 /mnt +df -h /mnt +herd start cow-store /mnt +mkdir /mnt/etc +cp /etc/target-config.scm /mnt/etc/config.scm +guix system init /mnt/etc/config.scm /mnt --no-substitutes +sync +reboot\n") + (define* (run-install target-os target-os-source #:key (script %simple-installation-script) + (packages '()) (os (marionette-operating-system - ;; Since the image has no network access, use the - ;; current Guix so the store items we need are in - ;; the image. (operating-system - (inherit (operating-system-with-current-guix - installation-os)) + ;; Since the image has no network access, use the + ;; current Guix so the store items we need are in + ;; the image and add packages provided. + (inherit (operating-system-add-packages + (operating-system-with-current-guix + installation-os) + packages)) (kernel-arguments '("console=ttyS0"))) #:imported-modules '((gnu services herd) (guix combinators)))) - (target-size (* 1200 MiB))) - "Run SCRIPT (a shell script following the GuixSD installation procedure) in + (installation-disk-image-file-system-type "ext4") + (target-size (* 2200 MiB))) + "Run SCRIPT (a shell script following the system installation procedure) in OS to install TARGET-OS. Return a VM image of TARGET-SIZE bytes containing -the installed system." +the installed system. The packages specified in PACKAGES will be appended to +packages defined in installation-os." (mlet* %store-monad ((_ (set-grafting #f)) (system (current-system)) @@ -148,7 +220,9 @@ the installed system." (image (system-disk-image (operating-system-with-gc-roots os (list target)) - #:disk-image-size (* 1500 MiB)))) + #:disk-image-size 'guess + #:file-system-type + installation-disk-image-file-system-type))) (define install (with-imported-modules '((guix build utils) (gnu build marionette)) @@ -164,16 +238,25 @@ the installed system." (define marionette (make-marionette - (cons (which #$(qemu-command system)) - (cons* "-no-reboot" "-m" "800" - "-drive" - (string-append "file=" #$image - ",if=virtio,readonly") - "-drive" - (string-append "file=" #$output ",if=virtio") - (if (file-exists? "/dev/kvm") - '("-enable-kvm") - '()))))) + `(,(which #$(qemu-command system)) + "-no-reboot" + "-m" "800" + #$@(cond + ((string=? "ext4" installation-disk-image-file-system-type) + #~("-drive" + ,(string-append "file=" #$image + ",if=virtio,readonly"))) + ((string=? "iso9660" installation-disk-image-file-system-type) + #~("-cdrom" #$image)) + (else + (error + "unsupported installation-disk-image-file-system-type:" + installation-disk-image-file-system-type))) + "-drive" + ,(string-append "file=" #$output ",if=virtio") + ,@(if (file-exists? "/dev/kvm") + '("-enable-kvm") + '())))) (pk 'uname (marionette-eval '(uname) marionette)) @@ -199,8 +282,15 @@ IMAGE, a disk image. The QEMU VM is has access to MEMORY-SIZE MiB of RAM." (mlet %store-monad ((system (current-system))) (return #~(let ((image #$image)) ;; First we need a writable copy of the image. - (format #t "copying image '~a'...~%" image) - (copy-file image "disk.img") + (format #t "creating writable image from '~a'...~%" image) + (unless (zero? (system* #+(file-append qemu-minimal + "/bin/qemu-img") + "create" "-f" "qcow2" + "-o" + (string-append "backing_file=" image) + "disk.img")) + (error "failed to create writable QEMU image" image)) + (chmod "disk.img" #o644) `(,(string-append #$qemu-minimal "/bin/" #$(qemu-command system)) @@ -210,7 +300,6 @@ IMAGE, a disk image. The QEMU VM is has access to MEMORY-SIZE MiB of RAM." "-no-reboot" "-m" #$(number->string memory-size) "-drive" "file=disk.img,if=virtio"))))) - (define %test-installed-os (system-test (name "installed-os") @@ -224,6 +313,156 @@ build (current-guix) and then store a couple of full system images.") (run-basic-test %minimal-os command "installed-os"))))) +(define %test-installed-extlinux-os + (system-test + (name "installed-extlinux-os") + (description + "Test basic functionality of an OS booted with an extlinux bootloader. As +per %test-installed-os, this test is expensive in terms of CPU and storage.") + (value + (mlet* %store-monad ((image (run-install %minimal-extlinux-os + %minimal-extlinux-os-source + #:packages + (list syslinux) + #:script + %extlinux-gpt-installation-script)) + (command (qemu-command/writable-image image))) + (run-basic-test %minimal-extlinux-os command + "installed-extlinux-os"))))) + + +;;; +;;; Installation through an ISO image. +;;; + +(define-os-with-source (%minimal-os-on-vda %minimal-os-on-vda-source) + ;; The OS we want to install. + (use-modules (gnu) (gnu tests) (srfi srfi-1)) + + (operating-system + (host-name "liberigilo") + (timezone "Europe/Paris") + (locale "en_US.UTF-8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vda"))) + (kernel-arguments '("console=ttyS0")) + (file-systems (cons (file-system + (device (file-system-label "my-root")) + (mount-point "/") + (type "ext4")) + %base-file-systems)) + (users (cons (user-account + (name "alice") + (comment "Bob's sister") + (group "users") + (supplementary-groups '("wheel" "audio" "video")) + (home-directory "/home/alice")) + %base-user-accounts)) + (services (cons (service marionette-service-type + (marionette-configuration + (imported-modules '((gnu services herd) + (guix combinators))))) + %base-services)))) + +(define %simple-installation-script-for-/dev/vda + ;; Shell script of a simple installation. + "\ +. /etc/profile +set -e -x +guix --version + +export GUIX_BUILD_OPTIONS=--no-grafts +guix build isc-dhcp +parted --script /dev/vda mklabel gpt \\ + mkpart primary ext2 1M 3M \\ + mkpart primary ext2 3M 1.2G \\ + set 1 boot on \\ + set 1 bios_grub on +mkfs.ext4 -L my-root /dev/vda2 +mount /dev/vda2 /mnt +df -h /mnt +herd start cow-store /mnt +mkdir /mnt/etc +cp /etc/target-config.scm /mnt/etc/config.scm +guix system init /mnt/etc/config.scm /mnt --no-substitutes +sync +reboot\n") + +(define %test-iso-image-installer + (system-test + (name "iso-image-installer") + (description + "") + (value + (mlet* %store-monad ((image (run-install + %minimal-os-on-vda + %minimal-os-on-vda-source + #:script + %simple-installation-script-for-/dev/vda + #:installation-disk-image-file-system-type + "iso9660")) + (command (qemu-command/writable-image image))) + (run-basic-test %minimal-os-on-vda command name))))) + + +;;; +;;; Separate /home. +;;; + +(define-os-with-source (%separate-home-os %separate-home-os-source) + ;; The OS we want to install. + (use-modules (gnu) (gnu tests) (srfi srfi-1)) + + (operating-system + (host-name "liberigilo") + (timezone "Europe/Paris") + (locale "en_US.utf8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) + (kernel-arguments '("console=ttyS0")) + (file-systems (cons* (file-system + (device (file-system-label "my-root")) + (mount-point "/") + (type "ext4")) + (file-system + (device "none") + (mount-point "/home") + (type "tmpfs")) + %base-file-systems)) + (users (cons* (user-account + (name "alice") + (group "users") + (home-directory "/home/alice")) + (user-account + (name "charlie") + (group "users") + (home-directory "/home/charlie")) + %base-user-accounts)) + (services (cons (service marionette-service-type + (marionette-configuration + (imported-modules '((gnu services herd) + (guix combinators))))) + %base-services)))) + +(define %test-separate-home-os + (system-test + (name "separate-home-os") + (description + "Test basic functionality of an installed OS with a separate /home +partition. In particular, home directories must be correctly created (see +).") + (value + (mlet* %store-monad ((image (run-install %separate-home-os + %separate-home-os-source + #:script + %simple-installation-script)) + (command (qemu-command/writable-image image))) + (run-basic-test %separate-home-os command "separate-home-os"))))) + ;;; ;;; Separate /gnu/store partition. @@ -238,19 +477,18 @@ build (current-guix) and then store a couple of full system images.") (timezone "Europe/Paris") (locale "en_US.UTF-8") - (bootloader (grub-configuration (device "/dev/vdb"))) + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) (kernel-arguments '("console=ttyS0")) (file-systems (cons* (file-system - (device "root-fs") - (title 'label) + (device (file-system-label "root-fs")) (mount-point "/") (type "ext4")) (file-system - (device "store-fs") - (title 'label) + (device (file-system-label "store-fs")) (mount-point "/gnu") - (type "ext4") - (needed-for-boot? #t)) ;definitely! + (type "ext4")) %base-file-systems)) (users %base-user-accounts) (services (cons (service marionette-service-type @@ -271,7 +509,7 @@ guix build isc-dhcp parted --script /dev/vdb mklabel gpt \\ mkpart primary ext2 1M 3M \\ mkpart primary ext2 3M 100M \\ - mkpart primary ext2 100M 1G \\ + mkpart primary ext2 100M 1.2G \\ set 1 boot on \\ set 1 bios_grub on mkfs.ext4 -L root-fs /dev/vdb2 @@ -315,20 +553,20 @@ where /gnu lives on a separate partition.") (timezone "Europe/Paris") (locale "en_US.utf8") - (bootloader (grub-configuration (device "/dev/vdb"))) + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) (kernel-arguments '("console=ttyS0")) - (initrd (lambda (file-systems . rest) - ;; Add a kernel module for RAID-0 (aka. "stripe"). - (apply base-initrd file-systems - #:extra-modules '("raid0") - rest))) + + ;; Add a kernel module for RAID-0 (aka. "stripe"). + (initrd-modules (cons "raid0" %base-initrd-modules)) + (mapped-devices (list (mapped-device (source (list "/dev/vda2" "/dev/vda3")) (target "/dev/md0") (type raid-device-mapping)))) (file-systems (cons (file-system - (device "root-fs") - (title 'label) + (device (file-system-label "root-fs")) (mount-point "/") (type "ext4") (dependencies mapped-devices)) @@ -398,7 +636,9 @@ by 'mdadm'.") (timezone "Europe/Paris") (locale "en_US.UTF-8") - (bootloader (grub-configuration (device "/dev/vdb"))) + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) ;; Note: Do not pass "console=ttyS0" so we can use our passphrase prompt ;; detection logic in 'enter-luks-passphrase'. @@ -409,7 +649,6 @@ by 'mdadm'.") (type luks-device-mapping)))) (file-systems (cons (file-system (device "/dev/mapper/the-root-device") - (title 'device) (mount-point "/") (type "ext4")) %base-file-systems)) @@ -436,7 +675,7 @@ export GUIX_BUILD_OPTIONS=--no-grafts ls -l /run/current-system/gc-roots parted --script /dev/vdb mklabel gpt \\ mkpart primary ext2 1M 3M \\ - mkpart primary ext2 3M 1G \\ + mkpart primary ext2 3M 1.2G \\ set 1 boot on \\ set 1 bios_grub on echo -n thepassphrase | \\ @@ -495,7 +734,7 @@ to enter the LUKS passphrase." "/post-initrd-passphrase.ppm") #$marionette)))))) -(define %test-encrypted-os +(define %test-encrypted-root-os (system-test (name "encrypted-root-os") (description @@ -511,4 +750,79 @@ build (current-guix) and then store a couple of full system images.") (run-basic-test %encrypted-root-os command "encrypted-root-os" #:initialization enter-luks-passphrase))))) + +;;; +;;; Btrfs root file system. +;;; + +(define-os-with-source (%btrfs-root-os %btrfs-root-os-source) + ;; The OS we want to install. + (use-modules (gnu) (gnu tests) (srfi srfi-1)) + + (operating-system + (host-name "liberigilo") + (timezone "Europe/Paris") + (locale "en_US.UTF-8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "/dev/vdb"))) + (kernel-arguments '("console=ttyS0")) + (file-systems (cons (file-system + (device (file-system-label "my-root")) + (mount-point "/") + (type "btrfs")) + %base-file-systems)) + (users (cons (user-account + (name "charlie") + (group "users") + (home-directory "/home/charlie") + (supplementary-groups '("wheel" "audio" "video"))) + %base-user-accounts)) + (services (cons (service marionette-service-type + (marionette-configuration + (imported-modules '((gnu services herd) + (guix combinators))))) + %base-services)))) + +(define %btrfs-root-installation-script + ;; Shell script of a simple installation. + "\ +. /etc/profile +set -e -x +guix --version + +export GUIX_BUILD_OPTIONS=--no-grafts +ls -l /run/current-system/gc-roots +parted --script /dev/vdb mklabel gpt \\ + mkpart primary ext2 1M 3M \\ + mkpart primary ext2 3M 2G \\ + set 1 boot on \\ + set 1 bios_grub on +mkfs.btrfs -L my-root /dev/vdb2 +mount /dev/vdb2 /mnt +btrfs subvolume create /mnt/home +herd start cow-store /mnt +mkdir /mnt/etc +cp /etc/target-config.scm /mnt/etc/config.scm +guix system build /mnt/etc/config.scm +guix system init /mnt/etc/config.scm /mnt --no-substitutes +sync +reboot\n") + +(define %test-btrfs-root-os + (system-test + (name "btrfs-root-os") + (description + "Test basic functionality of an OS installed like one would do by hand. +This test is expensive in terms of CPU and storage usage since we need to +build (current-guix) and then store a couple of full system images.") + (value + (mlet* %store-monad ((image (run-install %btrfs-root-os + %btrfs-root-os-source + #:script + %btrfs-root-installation-script)) + (command (qemu-command/writable-image image))) + (run-basic-test %btrfs-root-os command "btrfs-root-os"))))) + ;;; install.scm ends here