From ae7a316b9da0d1a50c5abdc531c68c8e98e561c9 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 20 Mar 2019 12:19:14 +0100 Subject: system: Initialize console keyboard layout in the initrd. Partially fixes . * gnu/system.scm ()[keyboard-layout]: New field. (operating-system-initrd-file): Pass #:keyboard-layout to MAKE-INITRD. * gnu/system/linux-initrd.scm (raw-initrd): Add #:keyboard-layout. Pass #:keymap-file to 'boot-system'. (base-initrd): Add #:keyboard-layout. [helper-packages]: Add LOADKEYS-STATIC when KEYBOARD-LAYOUT is true. Pass #:keyboard-layout to 'raw-initrd'. * gnu/build/linux-boot.scm (boot-system): Add #:keymap-file and honor it. * doc/guix.texi (operating-system Reference): Document the 'keyboard-layout' field. (Initial RAM Disk): Update 'raw-initrd' and 'base-initrd' documentation. --- gnu/build/linux-boot.scm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index 44b3506284..a35d18ad7c 100644 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès +;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès ;;; Copyright © 2017 Mathieu Othacehe ;;; ;;; This file is part of GNU Guix. @@ -437,6 +437,7 @@ bailing out.~%root contents: ~s~%" (scandir "/")) (define* (boot-system #:key (linux-modules '()) linux-module-directory + keymap-file qemu-guest-networking? volatile-root? pre-mount @@ -444,7 +445,8 @@ bailing out.~%root contents: ~s~%" (scandir "/")) (on-error 'debug)) "This procedure is meant to be called from an initrd. Boot a system by first loading LINUX-MODULES (a list of module names) from -LINUX-MODULE-DIRECTORY, then setting up QEMU guest networking if +LINUX-MODULE-DIRECTORY, then installing KEYMAP-FILE with 'loadkeys' (if +KEYMAP-FILE is true), then setting up QEMU guest networking if QEMU-GUEST-NETWORKING? is true, calling PRE-MOUNT, mounting the file systems specified in MOUNTS, and finally booting into the new root if any. The initrd supports kernel command-line options '--load', '--root', and '--repl'. @@ -491,6 +493,15 @@ upon error." #:lookup-module lookup-module) (map lookup-module linux-modules)) + (when keymap-file + (let ((status (system* "loadkeys" keymap-file))) + (unless (zero? status) + ;; Emit a warning rather than abort when we cannot load + ;; KEYMAP-FILE. + (format (current-error-port) + "warning: 'loadkeys' exited with status ~a~%" + status)))) + (when qemu-guest-networking? (unless (configure-qemu-networking) (display "network interface is DOWN\n"))) -- cgit v1.2.3 From af76c020bf19de5fe2e92f31d8b85cbd55c481de Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 2 Apr 2019 10:34:48 +0200 Subject: linux-container: Make the guest UID and GID a parameter. * gnu/build/linux-container.scm (initialize-user-namespace): Add #:guest-uid and #:guest-gid parameters and honor them. (run-container): Likewise. (call-with-container): Likewise. * tests/containers.scm ("call-with-container, user namespace, guest UID/GID"): New test. --- gnu/build/linux-container.scm | 48 ++++++++++++++++++++++++++++--------------- tests/containers.scm | 11 ++++++++++ 2 files changed, 43 insertions(+), 16 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/linux-container.scm b/gnu/build/linux-container.scm index 65e1325577..3d7b52f098 100644 --- a/gnu/build/linux-container.scm +++ b/gnu/build/linux-container.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 David Thompson -;;; Copyright © 2017, 2018 Ludovic Courtès +;;; Copyright © 2017, 2018, 2019 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -168,9 +168,12 @@ for the process." (umount "real-root" MNT_DETACH) (rmdir "real-root"))) -(define (initialize-user-namespace pid host-uids) +(define* (initialize-user-namespace pid host-uids + #:key (guest-uid 0) (guest-gid 0)) "Configure the user namespace for PID. HOST-UIDS specifies the number of -host user identifiers to map into the user namespace." +host user identifiers to map into the user namespace. GUEST-UID and GUEST-GID +specify the first UID (respectively GID) that host UIDs (respectively GIDs) +map to in the namespace." (define proc-dir (string-append "/proc/" (number->string pid))) @@ -191,10 +194,10 @@ host user identifiers to map into the user namespace." ;; within the container. (call-with-output-file (scope "/uid_map") (lambda (port) - (format port "0 ~d ~d" uid host-uids))) + (format port "~d ~d ~d" guest-uid uid host-uids))) (call-with-output-file (scope "/gid_map") (lambda (port) - (format port "0 ~d ~d" gid host-uids))))) + (format port "~d ~d ~d" guest-gid gid host-uids))))) (define (namespaces->bit-mask namespaces) "Return the number suitable for the 'flags' argument of 'clone' that @@ -210,13 +213,17 @@ corresponds to the symbols in NAMESPACES." ('net CLONE_NEWNET)) namespaces))) -(define (run-container root mounts namespaces host-uids thunk) +(define* (run-container root mounts namespaces host-uids thunk + #:key (guest-uid 0) (guest-gid 0)) "Run THUNK in a new container process and return its PID. ROOT specifies the root directory for the container. MOUNTS is a list of objects that specify file systems to mount inside the container. NAMESPACES is a list of symbols that correspond to the possible Linux namespaces: mnt, -ipc, uts, user, and net. HOST-UIDS specifies the number of -host user identifiers to map into the user namespace." +ipc, uts, user, and net. + +HOST-UIDS specifies the number of host user identifiers to map into the user +namespace. GUEST-UID and GUEST-GID specify the first UID (respectively GID) +that host UIDs (respectively GIDs) map to in the namespace." ;; The parent process must initialize the user namespace for the child ;; before it can boot. To negotiate this, a pipe is used such that the ;; child process blocks until the parent writes to it. @@ -254,7 +261,9 @@ host user identifiers to map into the user namespace." (pid (close-port child) (when (memq 'user namespaces) - (initialize-user-namespace pid host-uids)) + (initialize-user-namespace pid host-uids + #:guest-uid guest-uid + #:guest-gid guest-gid)) ;; TODO: Initialize cgroups. (write 'ready parent) (newline parent) @@ -271,23 +280,30 @@ host user identifiers to map into the user namespace." #f))))))))) (define* (call-with-container mounts thunk #:key (namespaces %namespaces) - (host-uids 1)) + (host-uids 1) (guest-uid 0) (guest-gid 0)) "Run THUNK in a new container process and return its exit status. MOUNTS is a list of objects that specify file systems to mount inside the container. NAMESPACES is a list of symbols corresponding to the identifiers for Linux namespaces: mnt, ipc, uts, pid, user, and net. By -default, all namespaces are used. HOST-UIDS is the number of host user -identifiers to map into the container's user namespace, if there is one. By -default, only a single uid/gid, that of the current user, is mapped into the -container. The host user that creates the container is the root user (uid/gid -0) within the container. Only root can map more than a single uid/gid. +default, all namespaces are used. + +HOST-UIDS is the number of host user identifiers to map into the container's +user namespace, if there is one. By default, only a single uid/gid, that of +the current user, is mapped into the container. The host user that creates +the container is the root user (uid/gid 0) within the container. Only root +can map more than a single uid/gid. + +GUEST-UID and GUEST-GID specify the first UID (respectively GID) that host +UIDs (respectively GIDs) map to in the namespace. Note that if THUNK needs to load any additional Guile modules, the relevant module files must be present in one of the mappings in MOUNTS and the Guile load path must be adjusted as needed." (call-with-temporary-directory (lambda (root) - (let ((pid (run-container root mounts namespaces host-uids thunk))) + (let ((pid (run-container root mounts namespaces host-uids thunk + #:guest-uid guest-uid + #:guest-gid guest-gid))) ;; Catch SIGINT and kill the container process. (sigaction SIGINT (lambda (signum) diff --git a/tests/containers.scm b/tests/containers.scm index 5323e5037d..37408f380d 100644 --- a/tests/containers.scm +++ b/tests/containers.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 David Thompson +;;; Copyright © 2016, 2017, 2019 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,6 +52,16 @@ (assert-exit (and (zero? (getuid)) (zero? (getgid))))) #:namespaces '(user)))) +(skip-if-unsupported) +(test-assert "call-with-container, user namespace, guest UID/GID" + (zero? + (call-with-container '() + (lambda () + (assert-exit (and (= 42 (getuid)) (= 77 (getgid))))) + #:guest-uid 42 + #:guest-gid 77 + #:namespaces '(user)))) + (skip-if-unsupported) (test-assert "call-with-container, uts namespace" (zero? -- cgit v1.2.3 From f6e3f0f9b1287eca120517a0161e3d0b1ed6ed44 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 14 Apr 2019 23:31:28 +0200 Subject: vm: Remove Xorriso "-padding" option. This is a followup to 66ec389580d4f1e4b81e1c72afe2749a547a0e7c. This reverts 178be030c0e4fdeac5e1c968b5c99d84bb4691db, which is no longer needed. * gnu/build/vm.scm (make-iso9660-image): Remove "-padding" option. --- gnu/build/vm.scm | 5 ----- 1 file changed, 5 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 6d6a0c4cb4..e15ca4d5fb 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -471,11 +471,6 @@ GRUB configuration and OS-DRV as the stuff in it." "mnt=/tmp/root/mnt" "-path-list" "-" "--" - - ;; XXX: Add padding to avoid I/O errors on i686: - ;; . - "-padding" "10m" - "-volid" (string-upcase volume-id) (if volume-uuid `("-volume_date" "uuid" -- cgit v1.2.3 From 833480cc1fa934b64a192fe7b2401491d4f169df Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 20 Apr 2019 14:42:53 +0200 Subject: vm: Reset file timestamps in ISO images. Partly fixes . Reported by Florian Pelz . * gnu/build/vm.scm (make-iso9660-image): Pass "-volume_date all_file_dates =1". --- gnu/build/vm.scm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnu/build') diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index e15ca4d5fb..75f1394d1a 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -471,6 +471,10 @@ GRUB configuration and OS-DRV as the stuff in it." "mnt=/tmp/root/mnt" "-path-list" "-" "--" + + ;; Set all timestamps to 1. + "-volume_date" "all_file_dates" "=1" + "-volid" (string-upcase volume-id) (if volume-uuid `("-volume_date" "uuid" -- cgit v1.2.3 From 6901b9248ea21f81f033e7b0de32502e389a5b71 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 20 Apr 2019 22:34:28 +0200 Subject: vm: Reset file timestamps of the EFI image in ISO images. Partly fixes . * gnu/build/vm.scm (make-iso9660-image): Set the 'SOURCE_DATE_EPOCH' environment variable. --- gnu/build/vm.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gnu/build') diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 75f1394d1a..a63a5d2eea 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -37,6 +37,7 @@ #:use-module (ice-9 popen) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) + #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:export (qemu-command load-in-linux-vm @@ -458,6 +459,15 @@ GRUB configuration and OS-DRV as the stuff in it." closures) (register-bootcfg-root "/tmp/root" config-file)) + ;; 'grub-mkrescue' calls out to mtools programs to create 'efi.img', a FAT + ;; file system image, and mtools honors SOURCE_DATE_EPOCH for the mtime of + ;; those files. The epoch for FAT is Jan. 1st 1980, not 1970, so choose + ;; that. + (setenv "SOURCE_DATE_EPOCH" + (number->string + (time-second + (date->time-utc (make-date 0 0 0 0 1 1 1980 0))))) + (let ((pipe (apply open-pipe* OPEN_WRITE grub-mkrescue "-o" target -- cgit v1.2.3 From 605815023cd21becc0156916f4ce08950b4459e5 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 21 Apr 2019 00:16:57 +0200 Subject: vm: Use a fixed FAT serial number for 'efi.img' in ISO images. Partly fixes . * gnu/build/vm.scm (make-iso9660-image): Set the 'GRUB_FAT_SERIAL_NUMBER' environment variable. --- gnu/build/vm.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gnu/build') diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index a63a5d2eea..f2953621ec 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -468,6 +468,16 @@ GRUB configuration and OS-DRV as the stuff in it." (time-second (date->time-utc (make-date 0 0 0 0 1 1 1980 0))))) + ;; Our patched 'grub-mkrescue' honors this environment variable and passes + ;; it to 'mformat', which makes it the serial number of 'efi.img'. This + ;; allows for deterministic builds. + (setenv "GRUB_FAT_SERIAL_NUMBER" + (number->string (if volume-uuid + (string-hash (iso9660-uuid->string volume-uuid) + (expt 2 32)) + #x77777777) + 16)) + (let ((pipe (apply open-pipe* OPEN_WRITE grub-mkrescue "-o" target -- cgit v1.2.3 From ecb33b87aafd9e240c2cb351525814cb1bb5ceb1 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 25 Apr 2019 00:43:42 +0200 Subject: vm: Adjust FAT serial number code to 32-bit Guile. On 32-bit systems, 'string-hash' would raise an out-of-range exception when the second argument was 2^32. * gnu/build/vm.scm (make-iso9660-image): Pass 2^32 - 1 to 'string-hash'. --- gnu/build/vm.scm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gnu/build') diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index f2953621ec..372cf63c68 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -473,8 +473,12 @@ GRUB configuration and OS-DRV as the stuff in it." ;; allows for deterministic builds. (setenv "GRUB_FAT_SERIAL_NUMBER" (number->string (if volume-uuid + + ;; On 32-bit systems the 2nd argument must be + ;; lower than 2^32. (string-hash (iso9660-uuid->string volume-uuid) - (expt 2 32)) + (- (expt 2 32) 1)) + #x77777777) 16)) -- cgit v1.2.3 From 504a0fc636ec591e65b4a229a37e522e425d8a0c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 26 Apr 2019 10:19:56 +0200 Subject: accounts: Always honor the configured user account shell. Starting from commit 0ae735bcc8ff7fdc89d67b492bdee9091ee19e86, Guix System would preserve the user shell across reconfigure and reboot. This was done so as to allow for the use of 'chsh'. This proved to be a misguided decision. This commit goes back to considering user shells as config and not "state." * gnu/build/accounts.scm (allocate-passwd): Do not use shell from PREVIOUS. --- gnu/build/accounts.scm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/accounts.scm b/gnu/build/accounts.scm index 6b44ab610b..c43ce85b60 100644 --- a/gnu/build/accounts.scm +++ b/gnu/build/accounts.scm @@ -483,9 +483,12 @@ new UIDs." (real-name (if previous (password-entry-real-name previous) real-name)) - (shell (if previous - (password-entry-shell previous) - shell))) + + ;; Do not reuse the shell of PREVIOUS since (1) + ;; that could lead to confusion, and (2) the + ;; shell might have been GC'd. See + ;; . + (shell shell)) result) allocation)))) '() -- cgit v1.2.3 From 9d3053819dfd834a1c29a03427c41d8524b8a7d5 Mon Sep 17 00:00:00 2001 From: rendaw <7e9wc56emjakcm@s.rendaw.me> Date: Mon, 29 Apr 2019 12:08:51 +0200 Subject: file-systems: Support the 'no-atime' flag. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build/syscalls.scm (MS_NOATIME): New variable. * gnu/build/file-systems.scm (mount-flags->bit-mask): Support it. * doc/guix.texi (File Systems): Document it and add cross-references to the relevant documentation. Co-authored-by: Ludovic Courtès --- doc/guix.texi | 9 +++++++-- gnu/build/file-systems.scm | 2 ++ guix/build/syscalls.scm | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'gnu/build') diff --git a/doc/guix.texi b/doc/guix.texi index 8f6e5bc20c..39d2ee476a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10753,10 +10753,15 @@ corresponding device mapping established. This is a list of symbols denoting mount flags. Recognized flags include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow access to special files), @code{no-suid} (ignore setuid and setgid -bits), and @code{no-exec} (disallow program execution.) +bits), @code{no-atime} (do not update file access times), and @code{no-exec} +(disallow program execution). @xref{Mount-Unmount-Remount,,, libc, The GNU C +Library Reference Manual}, for more information on these flags. @item @code{options} (default: @code{#f}) -This is either @code{#f}, or a string denoting mount options. +This is either @code{#f}, or a string denoting mount options passed to the +file system driver. @xref{Mount-Unmount-Remount,,, libc, The GNU C Library +Reference Manual}, for details and run @command{man 8 mount} for options for +various file systems. @item @code{mount?} (default: @code{#t}) This value indicates whether to automatically mount the file system when diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index c468144170..8bb10d574d 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -575,6 +575,8 @@ corresponds to the symbols listed in FLAGS." (logior MS_NODEV (loop rest))) (('no-exec rest ...) (logior MS_NOEXEC (loop rest))) + (('no-atime rest ...) + (logior MS_NOATIME (loop rest))) (() 0)))) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 66d63a2931..3316dc8dc5 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -39,6 +39,7 @@ MS_NODEV MS_NOEXEC MS_REMOUNT + MS_NOATIME MS_BIND MS_MOVE MS_STRICTATIME @@ -451,6 +452,7 @@ the returned procedure is called." (define MS_NODEV 4) (define MS_NOEXEC 8) (define MS_REMOUNT 32) +(define MS_NOATIME 1024) (define MS_BIND 4096) (define MS_MOVE 8192) (define MS_STRICTATIME 16777216) -- cgit v1.2.3 From 05344275517e12ea60039272b5d8936d18fd4338 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 27 Apr 2019 21:43:25 +0100 Subject: vm: Pass -smp to QEMU to allow use of multiple cores. * gnu/build/vm.scm (load-in-linux-vm): Pass (parallel-job-count) to QEMU with -smp to allow using multiple cores. --- gnu/build/vm.scm | 1 + 1 file changed, 1 insertion(+) (limited to 'gnu/build') diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 372cf63c68..ac99d6b1a3 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -145,6 +145,7 @@ the #:references-graphs parameter of 'derivation'." (_ #f)) (apply invoke qemu "-nographic" "-no-reboot" + "-smp" (number->string (parallel-job-count)) "-m" (number->string memory-size) "-object" "rng-random,filename=/dev/urandom,id=guixsd-vm-rng" "-device" "virtio-rng-pci,rng=guixsd-vm-rng" -- cgit v1.2.3