aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2021-02-23 20:28:07 +0000
committerChristopher Baines <mail@cbaines.net>2021-02-23 20:28:07 +0000
commit56903beb02cf956f64bf76fe6d572b02faea3a5f (patch)
tree1ea1ac0b860498eaff5637d6ff6b6b8c30554510
parenteec127822a74c6a1a6100b07d94c8fb275d571bf (diff)
downloadguix-childhurd-swap.tar
guix-childhurd-swap.tar.gz
-rw-r--r--gnu/build/image.scm18
-rw-r--r--gnu/services/virtualization.scm2
-rw-r--r--gnu/system/image.scm28
-rw-r--r--gnu/system/images/hurd.scm6
4 files changed, 40 insertions, 14 deletions
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index f6e5cb42f6..78e84f463f 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -60,6 +60,11 @@
(number->string
(inexact->exact (ceiling (/ size 1024)))))
+(define (size-in-mib size)
+ "Convert SIZE expressed in bytes, to ... and return it as a string."
+ (number->string
+ (inexact->exact (ceiling (/ size (* 1024 1024))))))
+
(define (estimate-partition-size root)
"Given the ROOT directory, evalute and return its size. As this doesn't
take the partition metadata size into account, take a 25% margin."
@@ -107,6 +112,17 @@ take the partition metadata size into account, take a 25% margin."
(string-append "::" file))))
(scandir root))))
+(define* (make-swap-image partition target root)
+ "Handle the creation of SWAP partition images. See 'make-partition-image'."
+ (let ((size (partition-size partition))
+ (label (partition-label partition)))
+ (invoke "dd"
+ "if=/dev/zero"
+ (string-append "of=" target)
+ "bs=1MiB"
+ (simple-format #f "count=~A" (size-in-mib size)))
+ (invoke "mkswap" "-L" label target)))
+
(define* (make-partition-image partition-sexp target root)
"Create and return the image of PARTITION-SEXP as TARGET. Use the given
ROOT directory to populate the image."
@@ -117,6 +133,8 @@ ROOT directory to populate the image."
(make-ext-image partition target root))
((string=? type "vfat")
(make-vfat-image partition target root))
+ ((string=? type "swap")
+ (make-swap-image partition target root))
(else
(raise (condition
(&message
diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm
index a45da14a80..b0e9d6e6da 100644
--- a/gnu/services/virtualization.scm
+++ b/gnu/services/virtualization.scm
@@ -897,6 +897,8 @@ that will be listening to receive secret keys on port 1004, TCP."
(default (hurd-vm-disk-image this-record)))
(disk-size hurd-vm-configuration-disk-size ;number or 'guess
(default 'guess))
+ (swap-size hurd-vm-configuration-swap-size
+ (default 512))
(memory-size hurd-vm-configuration-memory-size ;number
(default 512))
(options hurd-vm-configuration-options ;list of string
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index 1012fa6158..6e3fd51294 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -326,7 +326,8 @@ used in the image."
(image-builder
(with-imported-modules*
(let ((initializer #$(partition-initializer partition))
- (inputs '#+(list e2fsprogs fakeroot dosfstools mtools))
+ (inputs '#+(list coreutils e2fsprogs fakeroot dosfstools
+ mtools util-linux))
(image-root "tmp-root"))
(sql-schema #$schema)
@@ -338,18 +339,19 @@ used in the image."
#+(file-append glibc-utf8-locales "/lib/locale"))
(setlocale LC_ALL "en_US.utf8")
- (initializer image-root
- #:references-graphs '#$graph
- #:deduplicate? #f
- #:system-directory #$os
- #:grub-efi #+grub-efi
- #:bootloader-package
- #+(bootloader-package bootloader)
- #:bootloader-installer
- #+(bootloader-installer bootloader)
- #:bootcfg #$bootcfg
- #:bootcfg-location
- #$(bootloader-configuration-file bootloader))
+ (when initializer
+ (initializer image-root
+ #:references-graphs '#$graph
+ #:deduplicate? #f
+ #:system-directory #$os
+ #:grub-efi #+grub-efi
+ #:bootloader-package
+ #+(bootloader-package bootloader)
+ #:bootloader-installer
+ #+(bootloader-installer bootloader)
+ #:bootcfg #$bootcfg
+ #:bootcfg-location
+ #$(bootloader-configuration-file bootloader)))
(make-partition-image #$(partition->gexp partition)
#$output
image-root)))))
diff --git a/gnu/system/images/hurd.scm b/gnu/system/images/hurd.scm
index eac5b7f7e6..54fcf32cdd 100644
--- a/gnu/system/images/hurd.scm
+++ b/gnu/system/images/hurd.scm
@@ -84,7 +84,11 @@
(file-system "ext2")
(file-system-options '("-o" "hurd" "-O" "ext_attr"))
(flags '(boot))
- (initializer hurd-initialize-root-partition))))))
+ (initializer hurd-initialize-root-partition))
+ (partition
+ (size (* (expt 1024 2) 512))
+ (label "swap")
+ (file-system "swap"))))))
(define hurd-image-type
(image-type