diff options
| author | 45mg <45mg.writes@gmail.com> | 2025-09-22 18:42:04 +0530 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-10-06 10:21:16 +0200 |
| commit | 73cbb94d1dd8a72405c023adeb89ab6940d0d82e (patch) | |
| tree | c416196ac34837eb0c0e333d92fe6adb3f80db8f | |
| parent | e9aa1e945954f44bf6a15b91ff1bae48e7b7b772 (diff) | |
mapped-devices/luks: Support extra options.
Allow passing extra options to the 'cryptsetup open' command.
* gnu/system/mapped-devices.scm (luks-device-mapping-with-options):
[#:extra-options]: New argument.
(open-luks-device): Use it.
(check-luks-device): Validate it.
* doc/guix.texi (Mapped Devices): Document it.
* gnu/tests/install.scm (%test-encrypted-root-extra-options-os): New
test for it, as well as the previously untested #:allow-discards?
option.
(%encrypted-root-extra-options-os): New os declaration for the test.
Change-Id: I265a431efb0c81ed7cfc984344c6b8a4cc2f1624
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
| -rw-r--r-- | doc/guix.texi | 21 | ||||
| -rw-r--r-- | gnu/system/mapped-devices.scm | 29 | ||||
| -rw-r--r-- | gnu/tests/install.scm | 68 |
3 files changed, 112 insertions, 6 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 3fd2a139685..0c002113078 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -18783,6 +18783,27 @@ this option can have a negative security impact because it can make | |||
| 18783 | file system level operations visible on the physical device. For more | 18783 | file system level operations visible on the physical device. For more |
| 18784 | information, refer to the description of the @code{--allow-discards} | 18784 | information, refer to the description of the @code{--allow-discards} |
| 18785 | option in the @code{cryptsetup-open(8)} man page. | 18785 | option in the @code{cryptsetup-open(8)} man page. |
| 18786 | |||
| 18787 | @item #:extra-options | ||
| 18788 | List of additional command-line options for the @code{cryptsetup open} | ||
| 18789 | command. See the @code{cryptsetup-open(8)} man page for a list of | ||
| 18790 | supported options. | ||
| 18791 | |||
| 18792 | For example, here is how you could specify the | ||
| 18793 | @option{--perf-no_read_workqueue} and @option{--perf-no_write_workqueue} | ||
| 18794 | options, along with @option{--allow-discards}: | ||
| 18795 | |||
| 18796 | @lisp | ||
| 18797 | (mapped-device | ||
| 18798 | (source "/dev/sdb1") | ||
| 18799 | (target "data") | ||
| 18800 | (type luks-device-mapping) | ||
| 18801 | (arguments '(#:allow-discards? #t | ||
| 18802 | #:extra-options | ||
| 18803 | ("--perf-no_read_workqueue" | ||
| 18804 | "--perf-no_write_workqueue"))))) | ||
| 18805 | @end lisp | ||
| 18806 | |||
| 18786 | @end table | 18807 | @end table |
| 18787 | @end defvar | 18808 | @end defvar |
| 18788 | 18809 | ||
diff --git a/gnu/system/mapped-devices.scm b/gnu/system/mapped-devices.scm index b0a6beef280..d568bddc4ff 100644 --- a/gnu/system/mapped-devices.scm +++ b/gnu/system/mapped-devices.scm | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #:use-module (srfi srfi-34) | 43 | #:use-module (srfi srfi-34) |
| 44 | #:use-module (srfi srfi-35) | 44 | #:use-module (srfi srfi-35) |
| 45 | #:use-module (ice-9 match) | 45 | #:use-module (ice-9 match) |
| 46 | #:use-module (ice-9 optargs) | ||
| 46 | #:use-module (ice-9 format) | 47 | #:use-module (ice-9 format) |
| 47 | #:export (%mapped-device | 48 | #:export (%mapped-device |
| 48 | mapped-device | 49 | mapped-device |
| @@ -200,10 +201,12 @@ option of @command{guix system}.\n") | |||
| 200 | ;;; Common device mappings. | 201 | ;;; Common device mappings. |
| 201 | ;;; | 202 | ;;; |
| 202 | 203 | ||
| 203 | (define* (open-luks-device source targets #:key key-file allow-discards?) | 204 | (define* (open-luks-device source targets |
| 205 | #:key key-file allow-discards? (extra-options '())) | ||
| 204 | "Return a gexp that maps SOURCE to TARGET as a LUKS device, using | 206 | "Return a gexp that maps SOURCE to TARGET as a LUKS device, using |
| 205 | 'cryptsetup'. When ALLOW-DISCARDS? is true, the use of discard (TRIM) | 207 | 'cryptsetup'. When ALLOW-DISCARDS? is true, the use of discard (TRIM) |
| 206 | requests is allowed for the underlying device." | 208 | requests is allowed for the underlying device. EXTRA-OPTIONS is a list of |
| 209 | additional options to be passed to the 'cryptsetup open' command." | ||
| 207 | (with-imported-modules (source-module-closure | 210 | (with-imported-modules (source-module-closure |
| 208 | '((gnu build file-systems) | 211 | '((gnu build file-systems) |
| 209 | (guix build utils))) ;; For mkdir-p | 212 | (guix build utils))) ;; For mkdir-p |
| @@ -244,10 +247,13 @@ requests is allowed for the underlying device." | |||
| 244 | (let ((cryptsetup #$(file-append cryptsetup-static | 247 | (let ((cryptsetup #$(file-append cryptsetup-static |
| 245 | "/sbin/cryptsetup")) | 248 | "/sbin/cryptsetup")) |
| 246 | (cryptsetup-flags (cons* | 249 | (cryptsetup-flags (cons* |
| 247 | "open" "--type" "luks" partition #$target | 250 | "open" "--type" "luks" |
| 248 | (if #$allow-discards? | 251 | (append |
| 249 | '("--allow-discards") | 252 | (if #$allow-discards? |
| 250 | '())))) | 253 | '("--allow-discards") |
| 254 | '()) | ||
| 255 | '#$extra-options | ||
| 256 | (list partition #$target))))) | ||
| 251 | ;; We want to fallback to the password unlock if the keyfile | 257 | ;; We want to fallback to the password unlock if the keyfile |
| 252 | ;; fails. | 258 | ;; fails. |
| 253 | (or (and keyfile | 259 | (or (and keyfile |
| @@ -271,6 +277,17 @@ requests is allowed for the underlying device." | |||
| 271 | "Ensure the source of MD is valid." | 277 | "Ensure the source of MD is valid." |
| 272 | (let ((source (mapped-device-source md)) | 278 | (let ((source (mapped-device-source md)) |
| 273 | (location (mapped-device-location md))) | 279 | (location (mapped-device-location md))) |
| 280 | (let-keywords (mapped-device-arguments md) #t | ||
| 281 | ((extra-options '()) | ||
| 282 | key-file allow-discards) | ||
| 283 | (unless (list? extra-options) | ||
| 284 | (raise (make-compound-condition | ||
| 285 | (formatted-message (G_ "invalid value ~s for #:extra-options \ | ||
| 286 | argument of `open-luks-device'") | ||
| 287 | extra-options) | ||
| 288 | (condition | ||
| 289 | (&error-location | ||
| 290 | (location (source-properties->location location)))))))) | ||
| 274 | (or (not (zero? (getuid))) | 291 | (or (not (zero? (getuid))) |
| 275 | (if (uuid? source) | 292 | (if (uuid? source) |
| 276 | (match (find-partition-by-luks-uuid (uuid-bytevector source)) | 293 | (match (find-partition-by-luks-uuid (uuid-bytevector source)) |
diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm index b26dc890a44..cb845c64cc2 100644 --- a/gnu/tests/install.scm +++ b/gnu/tests/install.scm | |||
| @@ -67,6 +67,7 @@ | |||
| 67 | %test-separate-home-os | 67 | %test-separate-home-os |
| 68 | %test-raid-root-os | 68 | %test-raid-root-os |
| 69 | %test-encrypted-root-os | 69 | %test-encrypted-root-os |
| 70 | %test-encrypted-root-extra-options-os | ||
| 70 | %test-encrypted-home-os | 71 | %test-encrypted-home-os |
| 71 | %test-encrypted-home-os-key-file | 72 | %test-encrypted-home-os-key-file |
| 72 | %test-encrypted-root-not-boot-os | 73 | %test-encrypted-root-not-boot-os |
| @@ -844,6 +845,73 @@ build (current-guix) and then store a couple of full system images.") | |||
| 844 | 845 | ||
| 845 | 846 | ||
| 846 | ;;; | 847 | ;;; |
| 848 | ;;; LUKS-encrypted root with extra options: --allow-discards, | ||
| 849 | ;;; --perf-no_read_workqueue and --perf-no_write_workqueue | ||
| 850 | ;;; | ||
| 851 | |||
| 852 | ;; Except for the 'mapped-devices' field, this is exactly the same as | ||
| 853 | ;; %encrypted-root-os. | ||
| 854 | (define-os-with-source (%encrypted-root-extra-options-os | ||
| 855 | %encrypted-root-extra-options-os-source) | ||
| 856 | ;; The OS we want to install. | ||
| 857 | (use-modules (gnu) (gnu tests) (srfi srfi-1)) | ||
| 858 | |||
| 859 | (operating-system | ||
| 860 | (host-name "liberigilo") | ||
| 861 | (timezone "Europe/Paris") | ||
| 862 | (locale "en_US.UTF-8") | ||
| 863 | |||
| 864 | (bootloader (bootloader-configuration | ||
| 865 | (bootloader grub-bootloader) | ||
| 866 | (targets '("/dev/vdb")))) | ||
| 867 | |||
| 868 | ;; Note: Do not pass "console=ttyS0" so we can use our passphrase prompt | ||
| 869 | ;; detection logic in 'enter-luks-passphrase'. | ||
| 870 | |||
| 871 | (mapped-devices (list (mapped-device | ||
| 872 | (source (uuid "12345678-1234-1234-1234-123456789abc")) | ||
| 873 | (target "the-root-device") | ||
| 874 | (type luks-device-mapping) | ||
| 875 | (arguments '(#:allow-discards? #t | ||
| 876 | #:extra-options | ||
| 877 | ("--perf-no_read_workqueue" | ||
| 878 | "--perf-no_write_workqueue")))))) | ||
| 879 | (file-systems (cons (file-system | ||
| 880 | (device "/dev/mapper/the-root-device") | ||
| 881 | (mount-point "/") | ||
| 882 | (type "ext4")) | ||
| 883 | %base-file-systems)) | ||
| 884 | (users (cons (user-account | ||
| 885 | (name "charlie") | ||
| 886 | (group "users") | ||
| 887 | (supplementary-groups '("wheel" "audio" "video"))) | ||
| 888 | %base-user-accounts)) | ||
| 889 | (services (cons (service marionette-service-type | ||
| 890 | (marionette-configuration | ||
| 891 | (imported-modules '((gnu services herd) | ||
| 892 | (guix combinators))))) | ||
| 893 | %base-services)))) | ||
| 894 | |||
| 895 | (define %test-encrypted-root-extra-options-os | ||
| 896 | (system-test | ||
| 897 | (name "encrypted-root-extra-options-os") | ||
| 898 | (description | ||
| 899 | "Test basic functionality of an OS installed like one would do by hand, | ||
| 900 | with an LUKS-encrypted root partition opened with extra options | ||
| 901 | (--allow-discards, --perf-no_read_workqueue and --perf-no_write_workqueue). | ||
| 902 | This test is expensive in terms of CPU and storage usage since we need to | ||
| 903 | build (current-guix) and then store a couple of full system images.") | ||
| 904 | (value | ||
| 905 | (mlet* %store-monad ((images (run-install %encrypted-root-extra-options-os | ||
| 906 | %encrypted-root-extra-options-os-source | ||
| 907 | #:script | ||
| 908 | %encrypted-root-installation-script)) | ||
| 909 | (command (qemu-command* images))) | ||
| 910 | (run-basic-test %encrypted-root-os command "encrypted-root-extra-options-os" | ||
| 911 | #:initialization enter-luks-passphrase))))) | ||
| 912 | |||
| 913 | |||
| 914 | ;;; | ||
| 847 | ;;; Separate /home on LVM | 915 | ;;; Separate /home on LVM |
| 848 | ;;; | 916 | ;;; |
| 849 | 917 | ||
