summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorRutherther <rutherther@ditigal.xyz>2026-01-03 15:36:00 +0100
committerRutherther <rutherther@ditigal.xyz>2026-01-14 09:17:33 +0100
commitab22501915fa57cf3a3f94dcc7fec86b433d85ad (patch)
tree5008e84b52279284d7467ae78cc78b569a89e850 /gnu
parent84a018b3569a26fbb99d0c71fdbd2addb5686467 (diff)
install: Register agetty on primary console on AArch64.
This adds the possibility to parse /proc/consoles to find a primary console. Then, on AArch64 this is used in the installation image. On AArch64, the boot usually happens with chosen device tree that contains the serial console. On x86_64, this does not happen so often, so we keep the installation iso minimal there. The primary console is chosen, but there is a fallback to any non-virtual one. Virtual console (/dev/tty0) is skipped, because that one can point to any console, like /dev/tty1 and so on. So it's not safe to register agetty on it. * gnu/build/linux-boot.scm (read-linux-consoles): New variable. * gnu/services/base.scm (default-serial-console): Use primary console as fallback. * gnu/system/install.scm (%installation-services): Add agetty tty for consoles. Change-Id: Iae01f7bc85b5ffdef2e52b1d0710889915b0f54a Signed-off-by: Rutherther <rutherther@ditigal.xyz>
Diffstat (limited to 'gnu')
-rw-r--r--gnu/build/linux-boot.scm73
-rw-r--r--gnu/services/base.scm21
-rw-r--r--gnu/system/install.scm11
3 files changed, 102 insertions, 3 deletions
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 61fa6716dba..e0743eae55a 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -46,7 +46,26 @@
46 make-static-device-nodes 46 make-static-device-nodes
47 configure-qemu-networking 47 configure-qemu-networking
48 48
49 boot-system)) 49 boot-system
50
51 linux-console
52
53 linux-console?
54 linux-console-device
55 linux-console-can-read?
56 linux-console-can-write?
57 linux-console-can-unblank?
58 linux-console-enabled?
59 linux-console-preferred?
60 linux-console-primary?
61 linux-console-printk?
62 linux-console-braille?
63 linux-console-safe-when-cpu-offline?
64 linux-console-major
65 linux-console-minor
66 linux-console-virtual?
67
68 read-linux-consoles))
50 69
51;;; Commentary: 70;;; Commentary:
52;;; 71;;;
@@ -675,4 +694,56 @@ the root file system...\n" root-delay)
675 (start-repl))))) 694 (start-repl)))))
676 #:on-error on-error)) 695 #:on-error on-error))
677 696
697(define-record-type <linux-console>
698 (make-linux-console device can-read? can-write? can-unblank?
699 enabled? preferred? primary? printk? braille?
700 safe-when-cpu-offline? major minor virtual?)
701 linux-console?
702 (device linux-console-device)
703 (can-read? linux-console-can-read?)
704 (can-write? linux-console-can-write?)
705 (can-unblank? linux-console-can-unblank?)
706 (enabled? linux-console-enabled?)
707 (preferred? linux-console-preferred?)
708 (primary? linux-console-primary?)
709 (printk? linux-console-printk?)
710 (braille? linux-console-braille?)
711 (safe-when-cpu-offline? linux-console-safe-when-cpu-offline?)
712 (major linux-console-major)
713 (minor linux-console-minor)
714 (virtual? linux-console-virtual?))
715
716(define* (read-linux-consoles #:optional (consoles-file "/proc/consoles"))
717 "Parses CONSOLES-FILE and returns a list of <linux-console> records."
718 (if (not (file-exists? consoles-file))
719 '()
720 (with-input-from-file consoles-file
721 (lambda ()
722 (let ((line-regex (make-regexp
723 "^([^ ]+)[ ]+(.+)[ ]+([0-9]+):([0-9]+)$"))
724 (virt-regex (make-regexp "^tty[0-9]+$")))
725 (let loop ((line (read-line))
726 (results '()))
727 (cond
728 ((eof-object? line)
729 (reverse results))
730 ((regexp-exec line-regex line)
731 => (lambda (m)
732 (let* ((dev (match:substring m 1))
733 (flags (match:substring m 2))
734 (major (string->number (match:substring m 3)))
735 (minor (string->number (match:substring m 4)))
736 (virtual? (regexp-exec virt-regex dev))
737 (has? (lambda (c)
738 (string-any (lambda (f) (char=? f c)) flags))))
739 (loop (read-line)
740 (cons (make-linux-console
741 dev
742 (has? #\R) (has? #\W) (has? #\U) (has? #\E)
743 (has? #\C) (has? #\B) (has? #\p) (has? #\b)
744 (has? #\a)
745 major minor virtual?)
746 results)))))
747 (else (loop (read-line) results)))))))))
748
678;;; linux-boot.scm ends here 749;;; linux-boot.scm ends here
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 4a4f1d17c18..850b651b9a3 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -1060,6 +1060,9 @@ to use as the tty. This is primarily useful for headless systems."
1060 (with-imported-modules (source-module-closure 1060 (with-imported-modules (source-module-closure
1061 '((gnu build linux-boot))) ;for 'find-long-options' 1061 '((gnu build linux-boot))) ;for 'find-long-options'
1062 #~(begin 1062 #~(begin
1063 (use-modules (gnu build linux-boot)
1064 (srfi srfi-1))
1065
1063 ;; console=device,options 1066 ;; console=device,options
1064 ;; device: can be tty0, ttyS0, lp0, ttyUSB0 (serial). 1067 ;; device: can be tty0, ttyS0, lp0, ttyUSB0 (serial).
1065 ;; options: BBBBPNF. P n|o|e, N number of bits, 1068 ;; options: BBBBPNF. P n|o|e, N number of bits,
@@ -1083,7 +1086,20 @@ to use as the tty. This is primarily useful for headless systems."
1083 (find-long-options "console" command))) 1086 (find-long-options "console" command)))
1084 (specs (append agetty-specs console-specs))) 1087 (specs (append agetty-specs console-specs)))
1085 (match specs 1088 (match specs
1086 (() #f) 1089 ;; Fallback to a physical console registered in /proc/consoles.
1090 (() (let* ((consoles (read-linux-consoles))
1091 (chosen-console
1092 ;; Prioritize preferred, if none, choose any enabled.
1093 (or (find (lambda (c)
1094 (and (not (linux-console-virtual? c))
1095 (linux-console-preferred? c)))
1096 consoles)
1097 (find (lambda (c)
1098 (and (not (linux-console-virtual? c))
1099 (linux-console-enabled? c)))
1100 consoles))))
1101 (and chosen-console
1102 (linux-console-device chosen-console))))
1087 ((spec _ ...) 1103 ((spec _ ...)
1088 ;; Extract device name from first spec. 1104 ;; Extract device name from first spec.
1089 (match (string-tokenize spec not-comma) 1105 (match (string-tokenize spec not-comma)
@@ -1111,7 +1127,8 @@ to use as the tty. This is primarily useful for headless systems."
1111 (requirement (cons* 'user-processes 'host-name 'udev 1127 (requirement (cons* 'user-processes 'host-name 'udev
1112 shepherd-requirement)) 1128 shepherd-requirement))
1113 1129
1114 (modules '((ice-9 match) (gnu build linux-boot))) 1130 (modules '((ice-9 match) (gnu build linux-boot)
1131 (srfi srfi-1)))
1115 (start 1132 (start
1116 (with-imported-modules (source-module-closure 1133 (with-imported-modules (source-module-closure
1117 '((gnu build linux-boot))) 1134 '((gnu build linux-boot)))
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index e5dfdbb427b..80332b7b534 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -483,6 +483,17 @@ Access documentation at any time by pressing Alt-F2.\x1b[0m
483 483
484 ;; Specific system services 484 ;; Specific system services
485 485
486 ;; AArch64 has a better detection of consoles, mainly because device
487 ;; trees are utilized. On x86_64, the detection is usually done
488 ;; through BIOS and consoles do not get registered to /proc/console.
489 ;; The only way they would is if the user used console linux argument.
490 `(,@(if (target-aarch64? system)
491 (list (service agetty-service-type
492 (agetty-configuration (tty #f)
493 (auto-login "root")
494 (login-pause? #t))))
495 '()))
496
486 ;; Machines without Kernel Mode Setting (those with many old and 497 ;; Machines without Kernel Mode Setting (those with many old and
487 ;; current AMD GPUs, SiS GPUs, ...) need uvesafb to show the GUI 498 ;; current AMD GPUs, SiS GPUs, ...) need uvesafb to show the GUI
488 ;; installer. Some may also need a kernel parameter like nomodeset 499 ;; installer. Some may also need a kernel parameter like nomodeset