生成系统默认的最小内核配置 tinyconfig - Configure the tiniest possible kernel
1
make ARCH=x86 tinyconfig
在最小配置基础之上添加必要配置
1
make ARCH=x86 menuconfig
1
Processor type and features ---> Processor family(Pentium-Pro)---> 486DX
1
Device Drivers ---> Character devices ---> Enable TTY
1 2
General setup ---> Configure standard kernel features(expert users)---> Enable support for printk ---> Initial RAM filesystem and RAM disk(initramfs/initrd)support --->只保留compressed using XZ即可
1 2
Executable file formats ---> Kernel support for ELF binaries ---> Kernel support for scripts starting with #!
Init Utilities ---> poweroff, reboot, init, Support reading an inittab file(NEW)
1
Linux System Utilities ---> mount, umount
1
Miscellaneous Utilities ---> less
1
Shells ---> ash, Optimize for size instead of speed, Alias support, helpbuiltin
BASE环境变量按需配置
1 2 3 4
sed -i"s|.*CONFIG_CROSS_COMPILER_PREFIX.*|CONFIG_CROSS_COMPILER_PREFIX="\"${BASE}"i486-linux-musl-cross/bin/i486-linux-musl-\"|" .config sed -i"s|.*CONFIG_SYSROOT.*|CONFIG_SYSROOT=\""${BASE}"i486-linux-musl-cross\"|" .config sed -i"s|.*CONFIG_EXTRA_CFLAGS.*|CONFIG_EXTRA_CFLAGS=-I$BASE/i486-linux-musl-cross/include|" .config sed -i"s|.*CONFIG_EXTRA_LDFLAGS.*|CONFIG_EXTRA_LDFLAGS=-L$BASE/i486-linux-musl-cross/lib|" .config
Init Utilities ---> poweroff, reboot, init, Support reading an inittab file(NEW)
内核编译时的选项
1 2
General setup ---> Configure standard kernel features(expert users)---> Enable support for printk ---> Initial RAM filesystem and RAM disk(initramfs/initrd)support --->只保留compressed using XZ即可
这时基本流程清晰了: Kernel —> Init —> /bin/sh(Busybox)
再深究,就需要扣源码了… …
也就明白Kernel就是个Kernel,没有周边设施的话干不了活
Kernel咋就知道我选取的哪种init呢
内核源码init/main.c中的static int __ref kernel_init(void *unused)函数中看到如下关键信息
1 2 3 4 5 6 7 8
if (!try_to_run_init_process("/sbin/init") || !try_to_run_init_process("/etc/init") || !try_to_run_init_process("/bin/init") || !try_to_run_init_process("/bin/sh")) return 0;
panic("No working init found. Try passing init= option to kernel. " "See Linux Documentation/admin-guide/init.rst for guidance.");