aboutsummaryrefslogtreecommitdiff
path: root/gnu/build/image.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/build/image.scm')
-rw-r--r--gnu/build/image.scm18
1 files changed, 18 insertions, 0 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