构建一个mini linux系统

mini linux:

启动流程:

centos6:post》bootsequence(bios)》BootLoader(mbr)》kernel(如无法直接识别硬盘驱动,需借助ramdisk)》rootfs》/sbin/init

centos7:post》bootsequence(bios)》BootLoader(mbr)》kernel(如无法直接识别硬盘驱动,需借助ramfs)》rootfs》/sbin/systemd

bootloader:lilo、grub legacy、grub2

stage1:mbr

stage1_5:filesystem driver

stage2:grub程序本身

内核编译步骤:

1、make menuconfig》生成.config文件

2、make [-j #]

3、make modules_install

4、make install

mini linux步骤:

1、内核:kernel(非模块方式)

2、根文件系统:busybox

3、按需进行命令移植

复制程序及其依赖的库文件脚本示例:

#!/bin/bash
#
target=/mnt/sysroot
[ -d $target ] || mkdir $target

read -p "a command:" command

libcp() {
for lib in $(ldd $1 | grep -o "[^[:space:]]/lib[^[:space:]]");do
libdir=$(dirname $lib)
[ -d $target$libdir ] || mkdir -p $target$libdir
[ -f $target$lib ] || cp $lib $target$lib
done
}

while [ "$command" != "quit" ];do
if ! which $command &> /dev/null;then
read -p "no such command, enter again:" command
continue
fi
command=$(which --skip-alias $command)
cmnddir=$(dirname $command)

yum groupinstall "development tools" "server platform development" -y

tar xf linux-3.16.56.tar.xz -C /usr/local/

cd /usr/local/

ln -sv linux-3.16.56 linux

cd linux

make allnoconfig

make menuconfig

根据cpu、pci、ethernet、filesystem等设备信息挑选内核参数,lscpu、lspci、lsusb等

编译时选择的基本模块与功能介绍

1.[*] 64-bit kernel #编译64位内核

2.Enable loadable module suppose #支持内核的装载与卸载 [*] module unloding

3.Bus options #相关PCI接口支持

4.Processor type and features #关于处理器版本选择,选择自己处理器合适的

5.Device drivers #关于硬盘,网卡各设备的驱动lspci查看系统设备信息(自己选择)

6.File Systems #文件系统支持(自己选择)

7.Excutable file formates/Emulattions #支持文件可执行文件的格式(自己选择)

8.Networking Support #网络服务支持

make -j 4 bzImage

准备硬盘,安装grub,分区,复制编译后的内核

mkfs -t ext4 /dev/sdb1

mkfs -t ext4 /dev/sdb2

mkdir -pv /mnt/{boot,sysroot}

mount /dev/sdb1 /mnt/boot

mount /dev/sdb2 /mnt/sysroot/

grub-install --root-directory=/mnt /dev/sdb

cp /usr/local/linux/arch/x86/boot/bzImage /mnt/boot/bzImage

vim /mnt/boot/grub/grub.conf

default=0
timeout=3
title minilinux
root (hd0,0)
kernel /bzImage ro root=/dev/sda2

猜你喜欢

转载自blog.51cto.com/11476314/2125851