summaryrefslogtreecommitdiffstats
path: root/debian/patches/maybe-quiet.patch
blob: 33d1e0f6351952d9100062b449ac3f54482f1809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
From 0b33def5d9ace3488fa612e09a5bb813c5e3cd90 Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwatson@ubuntu.com>
Date: Mon, 13 Jan 2014 12:13:26 +0000
Subject: Add configure option to reduce visual clutter at boot time

If this option is enabled, then do all of the following:

Don't display introductory message about line editing unless we're
actually offering a shell prompt.  (This is believed to be a workaround
for a different bug.  We'll go with this for now, but will drop this in
favour of a better fix upstream if somebody figures out what that is.)

Don't clear the screen just before booting if we never drew the menu in
the first place.

Remove verbose messages printed before reading configuration.  In some
ways this is awkward because it makes debugging harder, but it's a
requirement for a smooth-looking boot process; we may be able to do
better in future.  Upstream doesn't want this, though.

Disable the cursor as well, for similar reasons of tidiness.

Suppress kernel/initrd progress messages, except in recovery mode.

Suppress "GRUB loading" message unless Shift is held down.  Upstream
doesn't want this, as it makes debugging harder.  Ubuntu wants it to
provide a cleaner boot experience.

Author: Will Thompson <will@willthompson.co.uk>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/386922
Bug-Ubuntu: https://bugs.launchpad.net/bugs/861048
Forwarded: (partial) http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00056.html
Last-Update: 2021-09-24

Patch-Name: maybe-quiet.patch
---
 config.h.in                       |  2 ++
 configure.ac                      | 16 ++++++++++++++++
 grub-core/boot/i386/pc/boot.S     | 11 +++++++++++
 grub-core/boot/i386/pc/diskboot.S | 26 ++++++++++++++++++++++++++
 grub-core/kern/main.c             | 17 +++++++++++++++++
 grub-core/kern/rescue_reader.c    |  2 ++
 grub-core/normal/main.c           | 11 +++++++++++
 grub-core/normal/menu.c           | 17 +++++++++++++++--
 util/grub.d/10_linux.in           | 15 +++++++++++----
 9 files changed, 111 insertions(+), 6 deletions(-)

diff --git a/config.h.in b/config.h.in
index 9e8f9911b..d2c4ce8e5 100644
--- a/config.h.in
+++ b/config.h.in
@@ -12,6 +12,8 @@
 /* Define to 1 to enable disk cache statistics.  */
 #define DISK_CACHE_STATS @DISK_CACHE_STATS@
 #define BOOT_TIME_STATS @BOOT_TIME_STATS@
+/* Define to 1 to make GRUB quieter at boot time.  */
+#define QUIET_BOOT @QUIET_BOOT@
 
 /* We don't need those.  */
 #define MINILZO_CFG_SKIP_LZO_PTR 1
diff --git a/configure.ac b/configure.ac
index 74778a6f8..256fc44ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1915,6 +1915,17 @@ else
 fi
 AC_SUBST([UBUNTU_RECOVERY])
 
+AC_ARG_ENABLE([quiet-boot],
+              [AS_HELP_STRING([--enable-quiet-boot],
+                              [emit fewer messages at boot time (default=no)])],
+              [], [enable_quiet_boot=no])
+if test x"$enable_quiet_boot" = xyes ; then
+  QUIET_BOOT=1
+else
+  QUIET_BOOT=0
+fi
+AC_SUBST([QUIET_BOOT])
+
 LIBS=""
 
 AC_SUBST([FONT_SOURCE])
@@ -2177,5 +2188,10 @@ echo "With stack smashing protector: Yes"
 else
 echo "With stack smashing protector: No"
 fi
+if [ x"$enable_quiet_boot" = xyes ]; then
+echo With quiet boot: Yes
+else
+echo With quiet boot: No
+fi
 echo "*******************************************************"
 ]
diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S
index 2bd0b2d28..b0c0f2225 100644
--- a/grub-core/boot/i386/pc/boot.S
+++ b/grub-core/boot/i386/pc/boot.S
@@ -19,6 +19,9 @@
 
 #include <grub/symbol.h>
 #include <grub/machine/boot.h>
+#if QUIET_BOOT && !defined(HYBRID_BOOT)
+#include <grub/machine/memory.h>
+#endif
 
 /*
  *  defines for the code go here
@@ -249,9 +252,17 @@ real_start:
 	/* save drive reference first thing! */
 	pushw	%dx
 
+#if QUIET_BOOT && !defined(HYBRID_BOOT)
+	/* is either shift key held down? */
+	movw	$(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
+	testb	$3, (%bx)
+	jz	2f
+#endif
+
 	/* print a notification message on the screen */
 	MSG(notification_string)
 
+2:
 	/* set %si to the disk address packet */
 	movw	$disk_address_packet, %si
 
diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S
index c1addc0df..9b6d7a7ed 100644
--- a/grub-core/boot/i386/pc/diskboot.S
+++ b/grub-core/boot/i386/pc/diskboot.S
@@ -18,6 +18,9 @@
 
 #include <grub/symbol.h>
 #include <grub/machine/boot.h>
+#if QUIET_BOOT
+#include <grub/machine/memory.h>
+#endif
 
 /*
  *  defines for the code go here
@@ -25,6 +28,12 @@
 
 #define MSG(x)	movw $x, %si; call LOCAL(message)
 
+#if QUIET_BOOT
+#define SILENT(x)	call LOCAL(check_silent); jz LOCAL(x)
+#else
+#define SILENT(x)
+#endif
+
 	.file	"diskboot.S"
 
 	.text
@@ -50,11 +59,14 @@ _start:
 	/* save drive reference first thing! */
 	pushw	%dx
 
+	SILENT(after_notification_string)
+
 	/* print a notification message on the screen */
 	pushw	%si
 	MSG(notification_string)
 	popw	%si
 
+LOCAL(after_notification_string):
 	/* this sets up for the first run through "bootloop" */
 	movw	$LOCAL(firstlist), %di
 
@@ -279,7 +291,10 @@ LOCAL(copy_buffer):
 	/* restore addressing regs and print a dot with correct DS
 	   (MSG modifies SI, which is saved, and unused AX and BX) */
 	popw	%ds
+	SILENT(after_notification_step)
 	MSG(notification_step)
+
+LOCAL(after_notification_step):
 	popa
 
 	/* check if finished with this dataset */
@@ -295,8 +310,11 @@ LOCAL(copy_buffer):
 /* END OF MAIN LOOP */
 
 LOCAL(bootit):
+	SILENT(after_notification_done)
 	/* print a newline */
 	MSG(notification_done)
+
+LOCAL(after_notification_done):
 	popw	%dx	/* this makes sure %dl is our "boot" drive */
 	ljmp	$0, $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
 
@@ -320,6 +338,14 @@ LOCAL(general_error):
 /* go here when you need to stop the machine hard after an error condition */
 LOCAL(stop):	jmp	LOCAL(stop)
 
+#if QUIET_BOOT
+LOCAL(check_silent):
+	/* is either shift key held down? */
+	movw	$(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
+	testb	$3, (%bx)
+	ret
+#endif
+
 notification_string:	.asciz "loading"
 
 notification_step:	.asciz "."
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 73967e2f5..2879d644a 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -265,15 +265,25 @@ reclaim_module_space (void)
 void __attribute__ ((noreturn))
 grub_main (void)
 {
+#if QUIET_BOOT
+  struct grub_term_output *term;
+#endif
+
   /* First of all, initialize the machine.  */
   grub_machine_init ();
 
   grub_boot_time ("After machine init.");
 
+#if QUIET_BOOT
+  /* Disable the cursor until we need it.  */
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+    grub_term_setcursor (term, 0);
+#else
   /* Hello.  */
   grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
   grub_printf ("Welcome to GRUB!\n\n");
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
+#endif
 
   /* Init verifiers API. */
   grub_verifiers_init ();
@@ -312,5 +322,12 @@ grub_main (void)
   grub_boot_time ("After execution of embedded config. Attempt to go to normal mode");
 
   grub_load_normal_mode ();
+
+#if QUIET_BOOT
+  /* If we have to enter rescue mode, enable the cursor again.  */
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+    grub_term_setcursor (term, 1);
+#endif
+
   grub_rescue_run ();
 }
diff --git a/grub-core/kern/rescue_reader.c b/grub-core/kern/rescue_reader.c
index dcd7d4439..a93524eab 100644
--- a/grub-core/kern/rescue_reader.c
+++ b/grub-core/kern/rescue_reader.c
@@ -78,7 +78,9 @@ grub_rescue_read_line (char **line, int cont,
 void __attribute__ ((noreturn))
 grub_rescue_run (void)
 {
+#if QUIET_BOOT
   grub_printf ("Entering rescue mode...\n");
+#endif
 
   while (1)
     {
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index c4ebe9e22..a1750e09c 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -407,6 +407,15 @@ static grub_err_t
 grub_normal_read_line_real (char **line, int cont, int nested)
 {
   const char *prompt;
+#if QUIET_BOOT
+  static int displayed_intro;
+
+  if (! displayed_intro)
+    {
+      grub_normal_reader_init (nested);
+      displayed_intro = 1;
+    }
+#endif
 
   if (cont)
     /* TRANSLATORS: it's command line prompt.  */
@@ -459,7 +468,9 @@ grub_cmdline_run (int nested, int force_auth)
       return;
     }
 
+#if !QUIET_BOOT
   grub_normal_reader_init (nested);
+#endif
 
   while (1)
     {
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
index 8397886fa..e9d8444b5 100644
--- a/grub-core/normal/menu.c
+++ b/grub-core/normal/menu.c
@@ -807,12 +807,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
 
 /* Callback invoked immediately before a menu entry is executed.  */
 static void
-notify_booting (grub_menu_entry_t entry,
+notify_booting (grub_menu_entry_t entry
+#if QUIET_BOOT
+		__attribute__((unused))
+#endif
+		,
 		void *userdata __attribute__((unused)))
 {
+#if !QUIET_BOOT
   grub_printf ("  ");
   grub_printf_ (N_("Booting `%s'"), entry->title);
   grub_printf ("\n\n");
+#endif
 }
 
 /* Callback invoked when a default menu entry executed because of a timeout
@@ -860,6 +866,9 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
       int boot_entry;
       grub_menu_entry_t e;
       int auto_boot;
+#if QUIET_BOOT
+      int initial_timeout = grub_menu_get_timeout ();
+#endif
 
       boot_entry = run_menu (menu, nested, &auto_boot);
       if (boot_entry < 0)
@@ -869,7 +878,11 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
       if (! e)
 	continue; /* Menu is empty.  */
 
-      grub_cls ();
+#if QUIET_BOOT
+      /* Only clear the screen if we drew the menu in the first place.  */
+      if (initial_timeout != 0)
+#endif
+	grub_cls ();
 
       if (auto_boot)
 	grub_menu_execute_with_fallback (menu, e, autobooted,
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 1b8c6e146..869a7eec5 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -21,6 +21,7 @@ prefix="@prefix@"
 exec_prefix="@exec_prefix@"
 datarootdir="@datarootdir@"
 ubuntu_recovery="@UBUNTU_RECOVERY@"
+quiet_boot="@QUIET_BOOT@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
@@ -158,10 +159,12 @@ linux_entry ()
     fi
     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   fi
-  message="$(gettext_printf "Loading Linux %s ..." ${version})"
-  sed "s/^/$submenu_indentation/" << EOF
+  if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
+    message="$(gettext_printf "Loading Linux %s ..." ${version})"
+    sed "s/^/$submenu_indentation/" << EOF
 	echo	'$(echo "$message" | grub_quote)'
 EOF
+  fi
   if test -d /sys/firmware/efi && test -e "${linux}.efi.signed"; then
     sed "s/^/$submenu_indentation/" << EOF
 	linux	${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} ro ${args}
@@ -173,13 +176,17 @@ EOF
   fi
   if test -n "${initrd}" ; then
     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
-    message="$(gettext_printf "Loading initial ramdisk ...")"
+    if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
+      message="$(gettext_printf "Loading initial ramdisk ...")"
+      sed "s/^/$submenu_indentation/" << EOF
+	echo	'$(echo "$message" | grub_quote)'
+EOF
+    fi
     initrd_path=
     for i in ${initrd}; do
       initrd_path="${initrd_path} ${rel_dirname}/${i}"
     done
     sed "s/^/$submenu_indentation/" << EOF
-	echo	'$(echo "$message" | grub_quote)'
 	initrd	$(echo $initrd_path)
 EOF
   fi