構建一個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)
[ -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

(1)
N26-深圳-城市蝸牛N26-深圳-城市蝸牛
上一篇 2018-06-05 23:59
下一篇 2018-06-06 13:55

相關推薦

  • if語句、for語句練習

    單分支之if語句 語法: if測試條件1;then arg1 … else arg2 … fi 多分支if語句   語法: if 測試條件1 ;then arg1 … elif 測試條件2 ;then arg2 … elif 測試條件3 ;then arg3 … else arg4 fi …

    2018-04-15
  • 計算機的組成及其功能

    計算機的組成

    2018-06-27
  • 小白加薪升職記之正則表達式基礎

    正則表達式基礎命令

    Linux筆記 2018-06-01
  • 1

    1

    Linux筆記 2018-05-26
  • MySQL之日志管理

    MySQL數據庫中支持多種日志類型,通過分析日志,我們可以優化數據庫性能,排除故障,甚至能夠還原數據,本節內容將帶你了解MySQL數據庫中的日志管理

    2018-06-12
  • mysql sql語言 增刪改查

    數據庫 數據 增create insert 刪drop delete 改alter update 查 select 創建數據庫db1 查看數據庫目錄db1 刪除數據庫 查看字符集列表 查看表 創建表 查看表的定義 查看表的屬性信息 創建表 查看表的定義 查看表的具體信息 查看完整表的定義 查看user表的定義 利用別的表的信息創建表 創建一張表像另一張 表 …

    Linux筆記 2018-06-11
欧美性久久久久