From b66973344e3387f1a8450d091489a8a9671e8738 Mon Sep 17 00:00:00 2001 From: Matthew Brooks Date: Sun, 29 Mar 2020 14:55:34 -0500 Subject: [PATCH] Cookbook: Adding example of bind-mounting in the operating system definition. --- doc/guix-cookbook.texi | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index 477b7e3dff..78b99abda8 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -1320,6 +1320,7 @@ reference. @menu * Customizing the Kernel:: Creating and using a custom Linux kernel on Guix System. +* Bind-mounting file systems:: Setting up a bind-mount in the file-systems definition. @end menu @node Customizing the Kernel @@ -1562,6 +1563,51 @@ likely that you'll need to modify the initrd on a machine using a custom kernel, since certain modules which are expected to be built may not be available for inclusion into the initrd. +@c ********************************************************************* +@node Bind-mounting file-systems +@section Bind-mounting file-systems + +To bind-mount a file-system, one must first set up some definitions before the @code{operating-system} section of the system definition. In this example we will bind-mount a folder from a spinning disk drive to @code{/tmp}, to save wear and tear on the primary +SSD, without dedicating an entire partition to be mounted as @code{/tmp}. + +First, the source drive that hosts the folder we wish to bind mount should be defined, so that the bind-mount can depend on it. + +@lisp +(define source-drive ;; "source-drive" can be named anything you want. + (file-system + (device (uuid "UUID goes here")) + (mount-point "/path-to-spinning-disk-goes-here") + (type "ext4"))) ;; Make sure to set this to the appropriate type for your drive. +@end lisp + +The source folder must also be defined, so that guix will know it's not a regular block device, but a folder. +@lisp +(define (%source-directory) "/path-to-spinning-disk-goes-here/tmp") ;; "source-directory" can be named any valid variable name. +@end lisp + +Finally, inside the @code{file-systems} definition, we must add the mount itself. + +@lisp +(file-systems (cons* + + ...... + + source-drive ;; Must match the name you gave the source drive in the earlier definition. + + (file-system + (device (%source-directory)) ;; Make sure "source-directory" matches your earlier definition. + (mount-point "/tmp") + (type "none") ;; We are mounting a folder, not a partition, so this type needs to be "none" + (flags '(bind-mount)) + (dependencies (list source-drive)) ;; Ensure "source-drive" matches what you've named the variable for the drive. + ) + + ...... + + )) +@end lisp + + @c ********************************************************************* @node Advanced package management @chapter Advanced package management -- 2.25.1