1. 屏蔽grub的信息
Gentoo上amd64 grub的版本是0.97-r12,需要修改源码来屏蔽屏幕打印。
- 创建本地overlay:/usr/local/portage/xxx-overlay,添加内容:PORTDIR_OVERLAY="/usr/local/portage/xxx-overlay"到/etc/make.conf
- 在本地overlay目录下创建:sys-boot-xxx/grub,将grub-0.97-r12.ebuild(来自gentoo官方portage树)和metadata.xml拷贝到这里
- 修改ebuild,因为我们要加入自己的patch,所以在
EPATCH_SUFFIX="patch" epatch "${WORKDIR}"/patch
这句的后面添加:
epatch "${FILESDIR}/<your patch filename>.patch"
- 在本地overlay目录下创建files目录,将我们的patch文件放进去,这里我的patch文件是(消除了所有正常情况下的输出):
diff -u -d -r grub-0.97.bak/stage1/stage1.S grub-0.97/stage1/stage1.S --- grub-0.97.bak/stage1/stage1.S 2012-12-21 19:13:16.864283386 +0800 +++ grub-0.97/stage1/stage1.S 2012-12-21 19:41:52.792201571 +0800 @@ -151,7 +151,7 @@ pushw %dx /* print a notification message on the screen */ - MSG(notification_string) + /* MSG(notification_string) */ /* do not probe LBA if the drive is a floppy */ testb $STAGE1_BIOS_HD_FLAG, %dl diff -u -d -r grub-0.97.bak/stage2/boot.c grub-0.97/stage2/boot.c --- grub-0.97.bak/stage2/boot.c 2012-12-21 19:13:16.855282243 +0800 +++ grub-0.97/stage2/boot.c 2012-12-21 19:15:08.341435413 +0800 @@ -280,8 +280,8 @@ errnum = ERR_WONT_FIT; else { - grub_printf (" [Linux-%s, setup=0x%x, size=0x%x]\n", - (big_linux ? "bzImage" : "zImage"), data_len, text_len); + /* grub_printf (" [Linux-%s, setup=0x%x, size=0x%x]\n", + (big_linux ? "bzImage" : "zImage"), data_len, text_len); */ /* Video mode selection support. What a mess! */ /* NOTE: Even the word "mess" is not still enough to diff -u -d -r grub-0.97.bak/stage2/cmdline.c grub-0.97/stage2/cmdline.c --- grub-0.97.bak/stage2/cmdline.c 2012-12-21 19:13:16.861283005 +0800 +++ grub-0.97/stage2/cmdline.c 2012-12-21 19:14:47.768836881 +0800 @@ -232,12 +232,12 @@ builtin = find_command (heap); if (! builtin) { - grub_printf ("%s\n", old_entry); + /* grub_printf ("%s\n", old_entry); */ continue; } - if (! (builtin->flags & BUILTIN_NO_ECHO)) - grub_printf ("%s\n", old_entry); + /* if (! (builtin->flags & BUILTIN_NO_ECHO)) + grub_printf ("%s\n", old_entry); */ /* If BUILTIN cannot be run in the command-line, skip it. */ if (! (builtin->flags & BUILTIN_CMDLINE)) diff -u -d -r grub-0.97.bak/stage2/disk_io.c grub-0.97/stage2/disk_io.c --- grub-0.97.bak/stage2/disk_io.c 2012-12-21 19:13:16.858282624 +0800 +++ grub-0.97/stage2/disk_io.c 2012-12-21 19:22:50.732885018 +0800 @@ -1351,7 +1351,7 @@ { if (! do_completion) { - printf (" Filesystem type "); + /* printf (" Filesystem type "); if (fsys_type != NUM_FSYS) printf ("is %s, ", fsys_table[fsys_type].name); @@ -1361,7 +1361,8 @@ if (current_partition == 0xFFFFFF) printf ("using whole disk\n"); else - printf ("partition type 0x%x\n", current_slice & 0xFF); + printf ("partition type 0x%x\n", current_slice & 0xFF); */ + return; } } #endif /* STAGE1_5 */ diff -u -d -r grub-0.97.bak/stage2/stage1_5.c grub-0.97/stage2/stage1_5.c --- grub-0.97.bak/stage2/stage1_5.c 2012-12-21 19:13:16.862283132 +0800 +++ grub-0.97/stage2/stage1_5.c 2012-12-21 19:24:14.499534514 +0800 @@ -30,7 +30,7 @@ void cmain (void) { - grub_printf ("\n\nGRUB loading, please wait...\n"); + /* grub_printf ("\n\nGRUB loading, please wait...\n"); */ /* * Here load the true second-stage boot-loader. diff -u -d -r grub-0.97.bak/stage2/stage2.c grub-0.97/stage2/stage2.c --- grub-0.97.bak/stage2/stage2.c 2012-12-21 19:13:16.857282497 +0800 +++ grub-0.97/stage2/stage2.c 2012-12-21 20:02:25.576707562 +0800 @@ -288,8 +288,8 @@ grub_timeout--; /* Print a message. */ - grub_printf ("\rPress `ESC' to enter the menu... %d ", - grub_timeout); + /* grub_printf ("\rPress `ESC' to enter the menu... %d ", + grub_timeout); */ } } } @@ -730,11 +730,11 @@ while (1) { - if (config_entries) + /* if (config_entries) printf (" Booting \'%s\'\n\n", get_entry (menu_entries, first_entry + entryno, 0)); else - printf (" Booting command-list\n\n"); + printf (" Booting command-list\n\n"); */ if (! cur_entry) cur_entry = get_entry (config_entries, first_entry + entryno, 1); diff -u -d -r grub-0.97.bak/stage2/start.S grub-0.97/stage2/start.S --- grub-0.97.bak/stage2/start.S 2012-12-21 19:13:16.857282497 +0800 +++ grub-0.97/stage2/start.S 2012-12-21 20:18:41.119650361 +0800 @@ -67,7 +67,7 @@ /* print a notification message on the screen */ pushw %si - MSG(notification_string) + /* MSG(notification_string) */ popw %si /* this sets up for the first run through "bootloop" */ @@ -293,7 +293,7 @@ /* restore addressing regs and print a dot with correct DS (MSG modifies SI, which is saved, and unused AX and BX) */ popw %ds - MSG(notification_step) + /* MSG(notification_step) */ popa /* check if finished with this dataset */ @@ -310,7 +310,7 @@ bootit: /* print a newline */ - MSG(notification_done) + /* MSG(notification_done) */ popw %dx /* this makes sure %dl is our "boot" drive */ #ifdef STAGE1_5 ljmp $0, $0x2200
- ebuild grub-0.97-r12.ebuild manifest
- 前面我们创建的grub包所属的category是sys-boot-xxx,这是为了区别系统的sys-boot/grub,方便emerge我们自己的grub。为了让这个category能被emerge认识,为此,在我们的overlay根目录(/usr/local/portage/xxx-overlay)下创建目录profiles,然后继续在profiles下新建文件categories,在其中输入内容:sys-boot-xxx
- emerge -C sys-boot/grub
- emerge -avt sys-boot-xxx/grub,这里注意观察我们的patch是否被apply了(官方grub本身就有很多patch会打,所以注意观察我们的,是最后一个打的。我们制作这个patch时,其实也是在官方grub+官方patch的基础上制作出来的,否则patch是打不上的)。
- grub编译安装完成了,运行:grub --no-floppy,然后:root (hd0,0) -> setup (hd0) -> quit
- 编辑/boot/grub/grub.conf,加入一行:hiddenmenu,这样grub的menu就不会出现了。如果只是将timeout设成0的话,还是有一个闪动的画面,所以这里禁止了menu。
- Done. 可以重启试一下。
2. 屏蔽kernel和Linux启动信息(init开始执行之后产生的信息)
这相对就简单很多了。网上有说添加kernel command option:console=/dev/null或者console=/dev/ttyS0,但是这样还有一小部分信息无法屏蔽,比如一开始的Uncompressing kernel...。所以我的做法是直接关掉所有的console,也就是VGA console(x86架构)和framebuffer console,make menuconfig轻松搞定。需要注意首先要enable CONFIG_EXPERT,否则VGA console是默认enable并且无法更改的。
Done. 现在除了BIOS信息,其他就什么信息都没有了。