构建一个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.178linux.com/100493

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

相关推荐

  • VM虚拟机克隆中的网络问题

    使用VM中的虚拟机克隆,可以很方便的搭建一些实验或生成环境,但在克隆时应注意几个问题: 1、网络 一般在克隆后,配置好的网络地址都会保留,需要重新对克隆的机器更改IP地址和hostname 具体更改方法为: IP地址:使用vi编辑 /etc/sysconfig/network-scripts/ifcfg-eno16777736文件,将ip地址更改为需要的ip…

    Linux笔记 2018-05-08
  • 新开始,新航程

           每一个夏天都是变动的季节,这个夏季我毕业了。大学最后的时光是在实验室度过的,每天都被瓶瓶罐罐所包围,鼻子里不时的飘进乙酸乙酯的香味,研究完了生物柴油的催化,是时候该为自己的未来找一条出路了。         大二的时候出于对计算机的着迷,一不小心点进了51cto,从此就走上了不归路。从计算机网络到linux,再到mysql,我在这个世界里乐此不…

    Linux笔记 2018-07-21
  • 修改Centos7的网卡命名方式及网卡的相关配置

    修改主机名centos6vim /etc/sysconfig/network永久有效hostname newname 立即临时生效也可以存网关,但优先级低于网卡配置文件GATEWAY=**centos7 /etc/hostname修改主机名hostnamectl set-hostname newname修改主机名直接生效 /etc/hosts :添加域名对应…

    Linux笔记 2018-05-03
  • 变量的理解

    有点绕多动动手就好了

    Linux笔记 2018-04-15
  • 实验:在软件RAID搭建LVM逻辑卷进行管理

    在上一节我们了解到,RAID可以实现磁盘的高性能读写,并实现冗余,而LVM逻辑卷则可以实现磁盘的弹性扩展,那么如何将两者配合使用并将它们的优势充分发挥呢,今天我们来实验在软件RAID上搭建LVM逻辑卷

    2018-04-27
  • 在CentOS 7.3中创建本地yum源

    1.挂载系统光盘 1.1创建挂载文件 [root@centos7 ~]# mkdir /mnt/cdrom                          #创建文件 1.2挂载光驱 [root@centos7 ~]# mount /dev/cdrom /mnt/cdrom/              #挂载光驱  mount: /dev/sr0 is w…

    Linux笔记 2017-05-18