Boot your Linux silently
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!
RT @reflinux: New Blog post: Boot your Linux silently http://bit.ly/cpaGMg