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)
[ -d $target$cmnddir ] || mkdir -p $target$cmnddir
[ -f $target$command ] || cp $command $target$command
libcp $command
read -p “a other command(quit):” command
done
# 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 mrproper ? ? ?清理所有
# make allnoconfig
# make defconfig ? ? ? ? 根據參考你的機器架構生成一份基本能用的基礎配置
# 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
編譯安裝單文件的busybox,靜態方式編輯依賴glibc-static
# yum install glibc-static
# wget https://busybox.net/downloads/busybox-1.2.2.1.tar.bz2
# tar xvf busybox-1.28.4.tar.bz2
# cd busybox-1.2.2.1
# make menuconfig
選擇
[*] Build static binary (no shared libs) ? ? ?靜態編譯
What kind of applet links to install (as soft-links) —> ? ? ?? (X) as soft-links
(./_install) Destination path for ‘make install’ ? ? ? ? ? ? ?定義安裝路徑
# make && make install
# cp -a _install/* /mnt/sysroot/
# vim /mnt/boot/grub/grub.conf
default=0
timeout=3
title minilinux
root (hd0,0)
kernel /bzImage ro root=/dev/sda2 init=/sbin/init
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/100493