Boot your Linux silently

Posted by | Comments (15) | Trackback (1)

When you freshly set up a Linux distribution by hand, you get a lot of verbose output when booting into your system, but also install'n'go distributions like Ubuntu oder SUSE output some text when loading the kernel. This is not always desired and many people want to suppress these insistent system messages, but it's not as easy as you might think.

Booting your system quietly has some advantages as well as some disadvantages. The following list points out the main arguments for and against silent boot processes. Advantages are:

  • No unsightly raw text output
  • Feeling of a solid and monolithic system ready to use
  • No confusing messages for ingenuous end-users

On the other hand there are also some disadvantages:

  • Less control, some errors during boot process might stay undetected
  • No useful error output at all if kernel panics

There might be some other important points I forgot. If you find any other, please don't hesitate to leave a comment on this article. Whether you choose making your boot process silent or not is of course up to your own preference, but the following three-steps Howto will show you how to get this done.

Step 1: Shut up Kernel!

When your kernel is loaded, it will show lots of things about decompression state and what it's doing right at the moment. Normally, you wouldn't read this because it's too much and of course too fast; but these messages can help you identifying causes for possible boot failures. However, if your kernel works correctly, you don't need this output here. If you need to take a look at it anyhow, you can also do this at a later time with the command dmesg, which shows you all output your kernel has produced. This includes also very early information which is only stored in RAM because no disk was mounted at that time.

To get rid of this text you have the option to reconfigure your kernel or just add a kernel parameter to your bootloader's kernel command line. To do it in the kernel, you have to set at least CONFIG_X86_VERBOSE_BOOTUP=n and CONFIG_EARLY_PRINTK=n. If you use make menuconfig it's

  Kernel hacking --->
        [ ] Enable verbose x86 bootup info messages
        [ ] Early printk

Note that EARLY_PRINTK depends on EMBEDDED, which has to be enabled in order to change the state of EARLY_PRINTK. For menuconfig it is

    General setup --->
        [*] Configure standard kernel features (for small systems) --->

Recompile your kernel and install it. From now on you should not see kernel decompression output anymore when booting.

Personally, I try to avoid this way and prefer to add a kernel parameter instead. That's much easier and I have the choice to omit this parameter for recovery boot entries. To get a silent boot this way, just add quiet to your kernel parameters. E.g.

title My Linux
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.34 root=/dev/sda3 ro rootfstype=ext4 quiet
    initrd /boot/initramfs

Note that with both variants, you'll still see error messages but normal status output will be hidden.

Step 2: Hide init output

This is probably the most complex part. After the kernel is initialized, init will fork all your startup services, which results in a long list of loaded modules, started daemons and so on and so forth. You could now of course patch init to hide output, but you shouldn't do that because startup services might change and could also fail, but you'd never be informed about this. Therefore, the much better way is to use a nice splash screen, which shows up instead. Then you are always able to toggle between splash screen and init output (mostly with <F2> key).

I can't show you how to setup a splash screen here since it's a complex setup and many distributions use their own bootsplash programs. For Gentoo you would normally use fbsplash. (The Gentoo Wiki describes how to install fbsplash. Don't forget to add fbcondecor to your boot runlevel!) In contrast, some other distributions like Ubuntu instead use Plymouth or the older USplash and so on and so forth. You see, on this behalf you have to inform yourself about which program is appropriate to you.

Step 3: Making GRUB less verbose

You've now done the work making your OS silent, but GRUB still prints some ridiculous text to the screen which nobody is interested in. To also fix this, we actually have to modify the GRUB source code. This procedure is different for GRUB Legacy and GRUB2.

Quietening GRUB Legacy

When you're using GRUB Legacy (<= GRUB 0.97), you might see some output like

  Booting 'My Linux 2.6.34'

root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
kernel /boot/vmlinuz-2.6.34 root=/dev/sda3 ro rootfstype=ext4 quiet
   [Linux-bzImage, setup=0x3000, size=0x4c2b80]
initrd /boot/initramfs
   [Linux-initrd @ 0x37f5b000, 0x94d97 bytes]


_

Suppressing this text requires a little hacking. First download GRUB sources and put them into a folder of your choice. If you use a source code based distribution like Gentoo Linux or added source code repositories to your tree, you can also copy the tarball from your package manager. Next unpack the tarball and make changes to stage2/cmdline.c, stage2/stage2.c, stage2/builtins.c and stage2/boot.c as described further on. In stage2/cmdline.c comment out lines 239/240:

            if (! (builtin->flags & BUILTIN_NO_ECHO))
    grub_printf ("%s\n", old_entry);

so they look like

      /*if (! (builtin->flags & BUILTIN_NO_ECHO))
    grub_printf ("%s\n", old_entry);*/

In stage2/stage2.c comment out lines 720-724, which should be

      if (config_entries)
	printf ("  Booting \'%s\'\n\n",
		get_entry (menu_entries, first_entry + entryno, 0));
      else
    printf ("  Booting command-list\n\n");

and in stage2/builtins.c comment out line 3168, which is

      print_fsys_type ();

Finally also comment out all program lines containing a printf() or grub_printf() call in stage2/boot.c. Be aware that a program line in C does not automatically end with a linefeed but with a semicolon. Thus,

	  grub_printf ("   [Linux-%s, setup=0x%x, size=0x%x]\n",
               (big_linux ? "bzImage" : "zImage"), data_len, text_len);

for instance, is one single program line, which has to be commented out completely. Otherwise you'd get a compiler error.

For your convenience I've created a patch file with all those changes. To apply it, copy it to your GRUB sources folder and run

patch -p0 < ./silent_grub.patch

That will apply all the changes from above for you automatically.

When you're done, configure and compile the sources and install them

./configure
make
make install

Since we edited only Stage2, you do not need to install GRUB to your MBR (Master Boot Record) again so grub-install procedure can be omitted.

Cut off GRUB2 output

The new GRUB2 (>= GRUB 1.98) makes things easier and by default its boot message is ways simpler:

  Booting 'My Linux, with Linux 2.6.34'
Loading Linux 2.6.34 ...
Loading initial ramdisk ...
_

To cut off this short message, we only have to edit one GRUB source file and one configuration file. Let's start with the latter one. The appropriate Bash code is usually defined at /etc/grub.d/10-linux. There simply remove the lines

	echo	$(printf "$(gettext "Loading Linux %s ...")" ${version})

and

	echo	$(gettext "Loading initial ramdisk ...")

You can't just comment them out with # because they're inside a Heredoc block.

To remove the first line of output, you need to patch the GRUB sources themselves. Download the tarball as described in the section above and comment out lines 495-497, which are:

  grub_printf ("  ");
  grub_printf_ (N_("Booting \'%s\'"), entry->title);
  grub_printf ("\n\n");

Of course, I also created a patch file for this change. Apply it as usual from within your sources folder, rebuild GRUB2 and install it. That's it, you're done!

Trackbacks

Comments

There have been 15 comments submitted yet. Add one as well!
Michele
Michele wrote on : (permalink)

Thank you very much, really useful!

I’m on a Gentoo, and thanks to your guide I get a (quite*) perfect silent boot.

I’m writing this just to say I add:
—- stage2/stage1_5.c 2003-07-09 13:45:53.000000000 +0100
+++ stage2/stage1_5.c.new 2010-09-08 22:20:46.147289966 +0200
-33,1 +33,1
- grub_printf (”\n\nGRUB loading, please wait…\n”);
+ //grub_printf (”\n\nGRUB loading, please wait…\n”);
—- stage2/start.S 2003-07-09 13:45:53.000000000 +0100
+++ stage2/start.S.new 2010-09-08 22:20:46.147289966 +0200
-342,1 +342,1
-notification_string: .string “Loading stage1.5”
+notification_string: .string “”
-347,1 +347,1
-notification_step: .string “.”
+notification_step: .string “”
-348,1 +348,1
-notification_done: .string “\r\n”
+notification_done: .string “”
—- stage1/stage1.S 2003-07-09 13:45:53.000000000 +0100
+++ stage1/stage1.S.new 2010-09-08 22:20:46.147289966 +0200
-403,1 +403,1
-notification_string: .string “GRUB
+notification_string: .string “”

in silent_grub.patch, to remove the string “GRUB . Loading stage1.5”.
It works like a charm with grub 0.97.
I also edited the ebuild to install it using the “official” gentoo way.

*It would be absolutely PERFECT if it’d be possible to hide the blinking cursor smile

Thank you again,
Michele

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

Thank you really much for your addition.
I doubt it would be possible to remove the cursor without changing bigger parts of Grub, but I’m not sure as I’m not a Grub developer.

Mrk
Mrk wrote on : (permalink)

Very interested in these – CONFIG_X86_VERBOSE_BOOTUP=n and CONFIG_EARLY_PRINTK=n

Will it totally shut up the kernel? I’ve been meaning to get rid of the unwanted and FUGLY text for so long. Anyway it’s too fast to see what comes up on screen during boot so it’s useless to display. Logs will do just fine as long as you know where to look. The boot messages still gets logged?

It’s been a while since I’ve compiled kernel. I avoid is as much as possible. So how long do you think will it take an i5 2410M 4-core with 8GB RAM to recompile 2.6.38-12-generic? I’m on Ubuntu 11.04.

The problem, more like my problem, is that as a modern desktop no kernel boot messages should ever be seen.Not unless the user wants to. Ubuntu boot process is almost perfect. You will never see text while Plymouth is enabled and quite splash directive is in grub . However you will see bits and pieces of those fugly text on (1) logout and (2) shutdown. Really very ugly to look at.

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

Yeah, that should take care of any or at least most output. But generally the quiet kernel parameter should do the job equally well.

But just try it out. Once you’ve set up your config, compiling the kernel shouldn’t take too long. I don’t know how long it’s gonna take on an i5 machine, but on my i7 with 8GB RAM it takes about two or three minutes. Just make sure to compile with multiple make jobs. That’ll speed up things immensely. On my quad core with hyperthreading I use 7 jobs (make -j7). On a dual core with hyperthreading, you might use 3, 4 or 5. Since you have a quad core i5, you might also try more but at some point you won’t get any more acceleration. Instead it’ll slow down your computer.

Mrk
Mrk wrote on : (permalink)

Thanks for the quick reply. I want to try it out this weekend. As I’ve mentioned above, logout and shutdown shows parts of the text messages which makes it bad to look at. If I wanted to look at all these, I would have dropped to recovery console or single user mode. I really don’t understand why they can’t fix this. It’s been what, 10 years or more, since the first boot splash came out and it’s still not perfect until now. Not complaining. Just wondering why. laugh

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

Just be aware that not everything you might see upon startup or shutdown is kernel stuff.
What you describe is typical for init/rc output. It is common behavior throughout all Linux distributions and their splash screen implementations that verbose mode is turned on as soon as an error occurs. If you see things like * or *[fail] then it’s not a kernel message.

Errors on shutdown often occur when processes hang (e.g. networkmanager sometimes doesn’t shut down properly) or when some file system related stuff went wrong (e.g. stopping MD RAID for the system partition usually doesn’t work and throws an error causing your rc system to show an error message as well as any following output).

These messages can’t be handled by any kernel parameter. Instead you need to fix the hanging daemons.

Mrk
Mrk wrote on : (permalink)

Looks like it’s a no go. I was researching this stuff further and found out exactly what you said. The kernel messages stops when init starts. At least that is how I understood it. I think recompiling the kernel is not enough to do the trick.

Can you point me to ways of “shutting up” the init messages? Logs is fine for me. It does not have to be redundant seeing these messages on screen. I check logs all the time anyway. Part of how I was used to do for having been using linux desktops for that long.

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

Unfortunately, no. I guess you have to patch your init system or your splash screen to hide any (error) output or fix the issues causing Plymouth to switch to verbose mode. The last way is the cleanest and I suggest you google the message you get to find some appropriate solution.

The only other way which might work is to replace /dev/console with a symlink to /dev/null. But this won’t survive a reboot and it might also have some unwanted side effects.

Mrk
Mrk wrote on : (permalink)

My systems appears to be snappier after compiling a customer kernel but I am not certain if the kernel is now more “quieter” than before. It appears to be the same.

This option I cannot find the exact one – [ * ] Configure standard kernel features (for small systems) – but there is a similar one under the same branch General Setup but it says – [ * ] Configure standard kernel features (for experts only) – or something to that effect. It is supposed to be selected right?

As for the options below, the first one is not selected by default (but I did a make oldconfig and Ubuntu kernels don’t enable that option by default when I checked) under /boot/config-KERNEL_VERSION. The 2nd one I unselected.

Kernel hacking —-> [ ] Enable verbose x86 bootup info messages [ ] Early printk

I did a few readings on Startup. It seems it has an option of console <logged|output|owner|none>. My google has so far not been very fruitful. The explanation I am getting is rather shallow so I can’t understand what it does exactly. I experimented on changing all /etc/init/*conf files that had “console output” to “console logged” and the effect was not good. My system was stuck at Plymouth. Thankfully I only need to restore back to previous setting (console output) to fix it.

I don’t think I need to patch Plymouth. It is working fine. The thing is that I don’t see the verbose text messages that are present during boot but is hidden with Plymouth in the foreground, unless on

(1) logout – when X appears to stutter and restart and there is that brief moment where the screen shows the VT behind with the boot messages readable, before GDM shows

(2) restart/shutdown – where before Plymouth is started by the restart/shutdown scripts the VT is visible and, of course, the boot messages are there including the init 0 or 6 messages briefly.

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

As I said: it’s not all kernel output. What those options do (and what the quiet option does as well) is to hide the decompression output which normally shows up when the kernel is loaded.

What you mention are things where I guess you can’t do much. When logging out, X restarts and that takes a while. Here on my Gentoo system I don’t see anything there, but that might be different on other systems (also depending on how many modules or drivers are loaded). It can be that your first VT is activated for a short time when X shuts down. So one thing you might try is to clear all the boot messages once your getty is loaded. I found some Arch Linux specific information about this.
The article depicts how to disable clearing the boot messages, but I guess you can do it vice versa. Just fiddle around with it to get what you need for your Ubuntu system.

Mr.Pine
Mr.Pine wrote on : (permalink)

Hi,
I’m useing kernel 3.2.1 on gentoo linux and set CONFIG_X86_VERBOSE_BOOTUP=n and CONFIG_EARLY_PRINTK=n. and restart my gentoo with new kernel. but it shows all messages!
any other option should I change !?

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

Hi,

Use the quiet boot option, that should work for you. It’s the best and simplest method, anyway.

Mr.Pine
Mr.Pine wrote on : (permalink)

Hi,
TNX for reply, But I want to force kernel to no show messages. my user may change grub option to see kernel messages!. I dont wat to let him to do this!.
I want to set kernel messages to be quiet!

Janek Bevendorff
Janek Bevendorff wrote on : (permalink)

Why would you want to do that? When the user has the rights to change the kernel command line, he will also be able to recompile the kernel with different options.
And I can’t imagine any kernel output that a user must not see. What the kernel prints out in it’s early boot phase is not much more than some decompression messages. There is nothing the user couldn’t also see in dmesg later on. Hiding the output is no security feature, it’s just to make the boot process look nicer.

xorg62
xorg62 wrote on : (permalink)

For grub 0.97:

Redirecting it to a serial port seems to do the trick

menu.lst:

serial —unit=0 —speed=9600
terminal serial

Write a comment:

HTML-Tags will be converted to Entities.
Textile-formatting allowed
Standard emoticons like :-) and ;-) are converted to images.
Design and Code Copyright © 2010-2014 Janek Bevendorff Content on this site is published under the terms of the GNU Free Documentation License (GFDL). You may redistribute content only in compliance with these terms. tweetbackcheck