aboutsummaryrefslogtreecommitdiff
path: root/gnu/tests/image.scm
blob: be6852cae0a41415810eb3f5dced46499d026ea7 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Mathieu Othacehe <othacehe@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu tests image)
  #:use-module (gnu)
  #:use-module (gnu image)
  #:use-module (gnu tests)
  #:autoload   (gnu system image) (system-image root-offset image-with-os efi-disk-image)
  #:use-module (gnu system uuid)
  #:use-module (gnu system vm)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages guile-xyz)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (ice-9 format)
  #:export (%test-images))

;;; Commentary:
;;;
;;; This module provides tests for the image creation process that is
;;; performed by "genimage" under the hood.
;;;
;;; The image partitionment is checked using Guile-Parted.  The content of the
;;; images is out of the scope of this module.  Other test modules such as
;;; (gnu tests installation) make sure that the produced images are viable.
;;;
;;; Code:

;; A dummy initializer creating a simple file in the partition.
(define dummy-initializer
  #~(lambda* (root . rest)
      (mkdir root)
      (call-with-output-file
          (string-append root "/test")
        (lambda (port)
          (format port "content")))))

(define %simple-efi-os
  (operating-system
    (inherit %simple-os)
    (bootloader (bootloader-configuration
                 (bootloader grub-efi-bootloader)
                 (targets '("/boot/efi"))))))

;; An MBR disk image with a single ext4 partition.
(define i1
  (image
   (format 'disk-image)
   (operating-system %simple-os)
   (partitions
    (list
     (partition
      (size (* 1024 1024)) ;1MiB
      (offset root-offset)
      (label "test")
      (file-system "ext4")
      (flags '(boot))
      (initializer dummy-initializer))))))

;; A GPT disk image with a single ext4 partition.
(define i2
  (image
   (format 'disk-image)
   (operating-system %simple-efi-os)
   (partition-table-type 'gpt)
   (partitions
    (list
     (partition
      (size (* 1024 1024)) ;1MiB
      (offset root-offset)
      (label "test")
      (file-system "ext4")
      (flags '(boot))
      (initializer dummy-initializer))))))

;; An MBR disk image with multiple ext4 partitions.
(define i3
  (image
   (format 'disk-image)
   (operating-system %simple-os)
   (partitions
    (list
     (partition
      (size (* 1024 1024)) ;1MiB
      (offset root-offset)
      (label "test")
      (file-system "ext4")
      (flags '(boot))
      (initializer dummy-initializer))
     (partition
      (size (* 1024 1024)) ;1MiB
      (label "test2")
      (file-system "ext4")
      (flags '())
      (initializer dummy-initializer))))))

;; A GPT disk image with multiple ext4 partitions.
(define i4
  (image
   (format 'disk-image)
   (operating-system %simple-efi-os)
   (partition-table-type 'gpt)
   (partitions
    (list
     (partition
      (size (* 1024 1024)) ;1MiB
      (offset root-offset)
      (label "test")
      (file-system "ext4")
      (flags '(boot))
      (initializer dummy-initializer))
     (partition
      (size (* 1024 1024)) ;1MiB
      (label "test2")
      (file-system "ext4")
      (flags '())
      (initializer dummy-initializer))))))

;; A GPT disk image with fat32 and ext4 partitions.
(define i5
  (image
   (format 'disk-image)
   (operating-system %simple-efi-os)
   (partition-table-type 'gpt)
   (partitions
    (list
     (partition
      (size (* 1024 1024 128)) ;128MiB
      (offset root-offset)
      (label "test")
      (file-system "fat32")
      (flags '(esp))
      (initializer dummy-initializer))
     (partition
      (size (* 1024 1024 256)) ;256MiB
      (label "test2")
      (file-system "ext4")
      (flags '(boot))
      (initializer dummy-initializer))))))

;; A efi disk image with default partitions
(define i6
  (image-with-os efi-disk-image %simple-efi-os))

(define (run-images-test)
  (define test
    (with-imported-modules '((srfi srfi-64)
                             (gnu build marionette))
      (with-extensions (list guile-parted guile-bytestructures)
        #~(begin
            (use-modules (gnu build marionette)
                         (srfi srfi-1)
                         (srfi srfi-26)
                         (srfi srfi-64)
                         (parted))

            (define (image->disk img)
              (disk-new (get-device img)))

            (test-runner-current (system-test-runner #$output))
            (test-begin "images")

            ;; Image i1.
            (define i1-image
              #$(system-image i1))
            (define d1-device
              (get-device i1-image))

            (test-equal "msdos"
              (disk-type-name (disk-probe d1-device)))

            (test-equal 1
              (disk-get-primary-partition-count (disk-new d1-device)))

            (test-assert
                (let* ((disk (disk-new d1-device))
                       (partitions (disk-partitions disk))
                       (boot-partition (find normal-partition? partitions)))
                  (partition-get-flag boot-partition PARTITION-FLAG-BOOT)))

            ;; Image i2.
            (define i2-image
              #$(system-image i2))
            (define d2-device
              (get-device i2-image))

            (test-equal "gpt"
              (disk-type-name (disk-probe d2-device)))

            (test-equal 1
              (disk-get-primary-partition-count (disk-new d2-device)))

            (test-equal "test"
              (let* ((disk (disk-new d2-device))
                     (partitions (disk-partitions disk))
                     (boot-partition (find normal-partition? partitions)))
                (partition-get-name boot-partition)))

            ;; Image i3.
            (define i3-image
              #$(system-image i3))
            (define d3-device
              (get-device i3-image))

            (test-equal "msdos"
              (disk-type-name (disk-probe d3-device)))

            (test-equal 2
              (disk-get-primary-partition-count (disk-new d3-device)))

            ;; Image i4.
            (define i4-image
              #$(system-image i4))
            (define d4-device
              (get-device i4-image))

            (test-equal "gpt"
              (disk-type-name (disk-probe d4-device)))

            (test-equal 2
              (disk-get-primary-partition-count (disk-new d4-device)))

            ;; Image i5.
            (define i5-image
              #$(system-image i5))
            (define d5-device
              (get-device i5-image))

            (define (sector->byte sector)
              (/ (* sector (device-sector-size d5-device))
                 MEBIBYTE-SIZE))

            (test-equal "gpt"
              (disk-type-name (disk-probe d5-device)))

            (test-equal 2
              (disk-get-primary-partition-count (disk-new d5-device)))

            (test-equal '("fat32" "ext4")
              (map (compose filesystem-type-name partition-fs-type)
                   (filter data-partition?
                           (disk-partitions (disk-new d5-device)))))

            ;; The first partition has a 1MiB offset has a 128MiB size. The
            ;; second partition should then start at 129MiB.
            (test-equal '(1 129)
              (map (compose sector->byte partition-start)
                   (filter data-partition?
                           (disk-partitions (disk-new d5-device)))))

            ;; Image i6.
            (define i6-image
              #$(system-image i6))
            (define d6-device
              (get-device i6-image))

            (test-equal "gpt"
              (disk-type-name (disk-probe d6-device)))

            (test-end)))))

  (gexp->derivation "images-test" test))

(define %test-images
  (system-test
   (name "images")
   (description "Build and test basic system images.")
   (value (run-images-test))))
p-service-type. Leo Famulari 2021-12-28installer: Offer the CUPS printing service on a dedicated page....Currently, the installer page RUN-OTHER-SERVICES-CBT-PAGE offers to the user all installer services that are not of the types 'desktop', 'network-management', or 'networking'. Concretely, this means that it offers the CUPS printing service, because that is the only service of a different type defined in the installer. In later commits, we will add some services of a new type, and we only want them to be offered when the user is installing a non-graphical system. At least one of these new services (NTP) is part of %DESKTOP-SERVICES. If it was also offered on RUN-OTHER-SERVICES-CBT-PAGE, and the user had configured a system using %DESKTOP-SERVICES, the user could accidentally add NTP to their services twice, which is an error and would break installation. So, this commit makes the RUN-OTHER-SERVICES-CBT-PAGE be more specific about what services to offer. This makes it easier to discriminate between desktop and non-desktop installations, in terms of when a given service is offered. * gnu/installer/newt/services.scm (RUN-OTHER-SERVICES-CBT-PAGE): Rename to ... (RUN-PRINTING-SERVICES-CBT-PAGE): ... new variable, and select only 'document' services. (RUN-SERVICES-PAGE): Adjust accordingly. * gnu/installer/tests.scm (CHOOSE-SERVICES): Adjust accordingly. Leo Famulari 2021-10-21installer: Reorder file system type listbox....Recommending ext4 over btrfs is probably ill-advised nowadays. See the regular bug reports about running out of /gnu/store directory entries, for which the documented fix then breaks booting with GRUB. Instead, just list regular file systems alphabetically. We can bikeshed bcachefs later ;-) Move second-class file systems like NTFS to their own section at the end of the list. * gnu/packages/package-management.scm (run-fs-type-page): Reorder the LISTBOX-ITEMS. Tobias Geerinckx-Rice 2021-09-23installer: Support XFS....* gnu/installer/newt/partition.scm (run-fs-type-page): Add ‘xfs’ to the list box. * gnu/installer/parted.scm (user-fs-type-name, user-fs-type->mount-type) (partition-filesystem-user-type): Add ‘xfs’ mapping. (create-xfs-file-system): New procedure. (format-user-partitions): Use it. * gnu/installer.scm (set-installer-path): Add xfsprogs. Tobias Geerinckx-Rice 2021-06-30installer: Offer the CUPS printing service....* gnu/installer/services.scm (%system-services): Add CUPS. * gnu/installer/newt/services.scm (run-other-services-cbt-page): New procedure. (run-services-page): Call it last. Tobias Geerinckx-Rice 2021-06-29installer: Fix crash when deleting a free space partition....Fixes: <https://issues.guix.gnu.org/49126>. * gnu/installer/newt/partition.scm (run-disk-page): Fix the return value when removing a free space partition. Mathieu Othacehe 2021-06-12installer: Check partitions UUIDs....* gnu/installer/parted.scm (&cannot-read-uuid): New condition. (cannot-read-uuid?, cannot-read-uuid-partition): New procedures. (check-user-partitions): Check that all user-partitions have a valid UUID, raide the above condition otherwise. * gnu/installer/newt/partition.scm (run-disk-page): Run an error page if the &cannot-read-uuid condition is raised. Mathieu Othacehe 2021-06-12installer: Print user partitions....* gnu/installer/newt/partition.scm (run-partitioning-page): Print user-partitions to syslog. Mathieu Othacehe 2021-04-28installer: Force GPT disk label when UEFI is supported....* gnu/installer/newt/partition.scm (run-label-page): Force the GPT disk label when UEFI is supported. Mathieu Othacehe 2021-01-31installer: Edit desktop selection prompt....* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page): Fix and clarify the #:info-text. Tobias Geerinckx-Rice 2021-01-12installer: Fix crash in parameters menu....Fixes: <https://issues.guix.gnu.org/45378>. * gnu/installer/newt/keymap.scm (run-layout-page): Return false when "Continue" button is pressed. (run-keymap-page): Do not try to compute variants if layout is false. Also do not try to format the result if layout is false. * gnu/installer.scm (compute-keymap-step): Do not apply keymap if "run-keymap-page" returns false. Mathieu Othacehe 2020-12-11install: Discover local substitute servers....* gnu/installer/substitutes.scm: New file. * gnu/installer/newt/substitutes.scm: New file. * gnu/local.mk (INSTALLER_MODULES): Add them. * po/guix/POTFILES.in: Add gnu/installer/newt/substitutes.scm. * gnu/installer/proxy.scm (with-silent-shepherd): Move to ... * gnu/installer/utils.scm: ... here. * gnu/installer/record.scm (<installer>)[substitutes-page]: New field. * gnu/installer/newt.scm (substitutes-page): New procedure, (newt-installer): register it. * gnu/installer.scm (installer-steps): Add "substitutes-page" step. * gnu/system/install.scm (%installation-services): Add avahi-service-type and enable substitute server discover in guix-service-type. [<name-service-switch>]: Set it to %mdns-host-lookup-nss. Mathieu Othacehe