mini linux busybox编译:

mini linux busybox编译:

一、编译内核

1、解压文件

[root@localhost ~]# tar -Jxf linux-3.10.105.tar.xz -C /usr/src/

[root@localhost ~]# cd /usr/src/

[root@localhost src]# ln -sv linux-3.10.105 /usr/src/linux

`/usr/src/linux’ -> `linux-3.10.105′

[root@localhost src]# cd linux

[root@localhost linux]# yum -y install *curses*

2、清空默认配置

[root@localhost linux]# make allnoconfig

[root@localhost linux]# make menuconfig

3、支持64位

[*] 64-bit kernel

4、允许动态加载模块

[*] Enable loadable module support —> [*] Module unloading

5、cpu类型

Processor type and features —>

[*] Symmetric multi-processing support

Processor family (Core 2/newer Xeon) —>

6、支持pci

Bus options (PCI etc.) —> Bus options (PCI etc.) —>

7、支持scsi硬盘

Device Drivers —>

<*> SCSI device support

<*> SCSI disk support

[*] Fusion MPT device support —>

<*> Fusion MPT ScsiHost drivers for SPI

[*] Fusion MPT logging facility

<*> Fusion MPT misc device (ioctl) driver

8、支持文件系统

File systems —>

<*> The Extended 4 (ext4) filesystem

9、支持鼠标键盘

鼠标:

Input device support —>[*] Mice —> <*> PS/2 mouse (NEW)

Input device support —><*> Mouse interface

10、usb驱动:

[*] USB support —>

<*> Support for Host-side USB

<*> EHCI HCD (USB 2.0) support

<*> OHCI HCD support

<*> UHCI HCD (most Intel and VIA) support

11、安装网络

Device Drivers —> [*] Network device support —> <*> Ethernet driver support —> [*]

Intel devices (NEW) —-> <*> Intel(R) PRO/1000 Gigabit Ethernet support

Networking options —>

[*] TCP/IP networking

[*] IP: advanced router

12、支持运行的程序

Executable file formats / Emulations —>

[*] Kernel support for ELF binaries

[*] Write ELF core dumps with partial segments (NEW)

<*> Kernel support for scripts starting with #!

13、编译能够加载基本硬件驱动的内核。

Device Drivers —>

Generic Driver Options —>

[*] Maintain a devtmpfs filesystem to mount at /dev

[*] Automount devtmpfs at /dev, after the kernel mounted the rootfs

二、创建grub

1、添加新硬盘并挂载

[root@localhost ~]# mkfs -t ext4 /dev/sdb2

[root@localhost ~]# mkfs -t ext4 /dev/sdb1

[root@localhost ~]# mkdir -pv /mnt/sysroot/boot/

[root@localhost ~]# mount -t ext4 /dev/sdb2 /mnt/sysroot/

[root@localhost ~]# mount -t ext4 /dev/sdb1 /mnt/sysroot/boot/

[root@localhost ~]# grub-install –root-directory=/mnt/sysroot/ /dev/sdb

[root@localhost sysroot]# cp /usr/src/linux/arch/x86/boot/bzImage /mnt/sysroot/boot/

2、创建grub配置文件

[root@localhost ~]# vim /mnt/sysroot/boot/grub/grub.conf

default=0

timeount=5

title minilinux busy box

root (hd0,0)

kernel=/bzImage ro root=/dev/sda2

三、安装busybox

1、解压编译安装busybox

[root@localhost ~]# tar -xf busybox-1.22.1.tar.bz2

[root@localhost busybox-1.26.2]# yum -y install glibc-static

[root@localhost busybox-1.26.2]# make menuconfig

Busybox Settings —> [*] Build BusyBox as a static binary (no shared libs)

What kind of applet links to install (as soft-links) —>

(./_install) BusyBox installation prefix (NEW)

[root@localhost busybox-1.22.1]# make && make install

[root@localhost sysroot]# cp -av /root/busybox-1.22.1/_install/* /mnt/sysroot/

[root@localhost ~]# chroot /mnt/sysroot/ /bin/ash

[root@localhost sysroot]# vim boot/grub/grub.conf

[root@localhost sysroot]# mkdir boot dev etc mnt opt proc root srv sys -pv

[root@localhost etc]# cd /mnt/sysroot/etc/

2、为init创建配置文件:

[root@localhost sysroot]# vim /mnt/sysroot/etc/inittab

::sysinit:/etc/rc.d/rc.sysinit

console::respawn:/bin/sh

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

3、创建初始化脚本:

[root@localhost ~]# mkdir /mnt/sysroot/etc/rc.d/ -pv

[root@localhost etc]# vim /mnt/sysroot/etc/rc.d/rc.sysinit

#!/bin/sh

#

echo -e “\tWelcome to \033[32mMini\033[0m Linux”

mount -n -t proc proc /proc

mount -n -t sysfs sysfs /sys

mount -n -o remount,rw /dev/sda2 /

给予初始化脚本执行权限:

[root@localhost ~]# chmod +x /mnt/sysroot/etc/rc.d/rc.sysinit

四、继续配置系统

1、为busybox的init程序提供配置文件

[root@localhost ~]# vim /mnt/sysroot/etc/inittab

::sysinit:/etc/rc.d/rc.sysinit

tty1::askfirst:/bin/sh

tty2::askfirst:/bin/sh

tty3::askfirst:/bin/sh

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

2、添加系统初始化脚本

[root@localhost ~]# vim /mnt/sysroot/etc/rc.d/rc.sysinit

#!/bin/sh

#

echo -e “\t Welcome to \033[32mMini\033[0m Linux”

mount -n -t proc proc /proc

mount -n -t sysfs sysfs /sys

mount -n -o remount,rw /dev/sda2 /

echo -e “\t\033[32mscan /sys and to potulate to /dev\033[0m\n”

mdev -s

echo -e “\t\033[32mmount -a filesystems..\033[0m\n”

mount -a

3、创建自动挂载配置文件

[root@localhost linux]# vim /mnt/sysroot/etc/fstab

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

/dev/sda1 /boot ext4 defaults 0 0

/dev/sda2 / ext4 defaults 0 0

五、手动编译网卡为模块

1、取消内核中网卡驱动

[root@localhost linux]# cd /usr/src/linux

[root@localhost linux]# make menuconfig

Device Drivers —> [*] Network device support —> [*] Ethernet driver support —> [*] Intel devices–>

<M> Intel(R) PRO/1000 Gigabit Ethernet support

[root@localhost linux]# make bzImage

[root@localhost linux]# cp -a arch/x86/boot/bzImage /mnt/sysroot/boot/

2、编译模块

[root@localhost linux]# make M=drivers/net/ethernet/intel/e1000/

Building modules, stage 2.

MODPOST 1 modules

LD [M] drivers/net/ethernet/intel/e1000/e1000.ko

[root@localhost linux]# mkdir /mnt/sysroot/lib/modules/ -pv

[root@localhost linux]# cp drivers/net/ethernet/intel/e1000/e1000.ko /mnt/sysroot/lib/modules/

3、定义加载网卡

编辑初始化脚本加载模块并配置ip地址:

[root@localhost ~]# vim /mnt/sysroot/etc/rc.d/rc.sysinit

echo -e “\t\033[32m Load modules e1000 \033[0m\n”

insmod /lib/modules/e1000.ko

echo -e “\t\033[32m Initializing ethnet card! \033[0m\n”

ifconfig eth0 11.100.40.110 up

ifconfig lo 127.0.0,1 up

4、自动配置主机名:

编辑初始化脚本:

[root@localhost ~]# vim /mnt/sysroot/etc/rc.d/rc.sysinit

[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

[ -z “$HOSTNAME” -o “HOSTNAME” == ‘(none)’ ] && HOSTNAME=’localhost’

hostname $HOSTNAME

创建配置文件:

[root@localhost ~]# mkdir /mnt/sysroot/etc/sysconfig/ -pv

[root@localhost ~]# vim /mnt/sysroot/etc/sysconfig/network

HOSTNAME=Minilinux.cpe.com

5、登陆认证

创建账号及密码:

[root@localhost ~]# chroot /mnt/sysroot/ /bin/sh

/ # touch /etc/group /etc/shadow /etc/passwd

/ # adduser root

注意要手动把用户id,gid改为0:

/ # vi /etc/passwd

root:x:0:0:Linux User,,,:/root:/bin/sh

/ # vi /etc/group

root:x:0:

创建密码文件:

[root@localhost ~]# head -1 /etc/shadow > /mnt/sysroot/etc/shadow

[root@localhost ~]# rm -rf /mnt/sysroot/etc/*-

由于busy不支持,所以要利用openssl手动创建:

[root@localhost ~]# openssl passwd -1 -salt $(openssl rand -hex 4)

Password:

$1$4dea2279$b1aqVY.Wye9oqwAK87xRL.

[root@localhost ~]# vim /mnt/sysroot/etc/shadow

root:$1$4dea2279$b1aqVY.Wye9oqwAK87xRL.:17204:0:99999:7:::

编辑init配置文件,添加tty终端:

[root@localhost ~]# vim /mnt/sysroot/etc/inittab

::sysinit:/etc/rc.d/rc.sysinit

::respawn:/sbin/getty 9600 tty1

::respawn:/sbin/getty 9600 tty2

::respawn:/sbin/getty 9600 tty3

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

6、打印登陆信息

[root@localhost ~]# vim /mnt/sysroot/etc/issue

Mini Linux by jia

Kernel \r on an \m

7、使用bash

复制bash及库文件:

[root@localhost ~]# ./cpcm.sh

please input a command:bash

设置用户登陆shell:

[root@localhost sysroot]# vim /mnt/sysroot/etc/passwd

root:x:0:0:Linux User,,,:/root:/bin/bash

设置登陆后#左边显示:

[root@localhost ~]# vim /mnt/sysroot/root/.bash_profile

export PS1='[\u@\h\w]\$’

当磁盘不同步时处理:

[root@localhost mnt]# fsck.ext4 -ft /dev/sdb2

7、安装ssh

解压并编译安装ssh:

[root@Minilinux ~]# tar xf dropbear-2013.58.tar.bz2

[root@Minilinux ~]# cd dropbear-2013.58

[root@Minilinux dropbear-2013.58]# ./configure

[root@Minilinux dropbear-2013.58]# make

[root@Minilinux dropbear-2013.58]# make install、

复制dropbear、dropbearkey、dbclient程序及模块到mini linux文件下

[root@Minilinux ~]# ./cpcm.sh

please input a command:dropbear

please input a command:dropbearkey

please input a command:dbclient

挂载pts终端保障ssh登陆

[root@Minilinux ~]# mkdir /mnt/sysroot/dev/pts -pv

[root@Minilinux ~]# vim /mnt/sysroot/etc/fstab

sysfs /sys sysfs defaults 0 0

proc /proc proc mode=620 0 0

devpts /dev/pts devpts defaults 0 0

/dev/sda1 /boot ext4 defaults 0 0

/dev/sda2 / ext4 defaults 0 0

创建dropdear密钥对:

[root@Minilinux ~]# mkdir /mnt/sysroot/etc/dropbear -pv

[root@Minilinux ~]# cd /mnt/sysroot/etc/dropbear/

[root@Minilinux dropbear]# dropbearkey -t rsa -s 2048 -f dropbear_rsa_host_key

[root@Minilinux dropbear]# dropbearkey -t dss -f dropbear_dss_host_key

配置安全shell,让ssh能够登陆:

[root@Minilinux sysroot]# vim /mnt/sysroot/etc/shells

/bin/sh

/bin/ash

/bin/hush

/bin/bash

/sbin/nologin

创建查询文件:

[root@Minilinux sysroot]# vim /mnt/sysroot/etc/nsswitch.conf

passwd: files

group: files

shadow: files

hosts: files dns

复制查询文件所依赖的库:

[root@localhost sysroot]# mkdir /mnt/sysroot/usr/lib64 -pv

mkdir: created directory `usr/lib64′

[root@Minilinux sysroot]# cp -d /lib64/libnss_files* lib64/

[root@Minilinux sysroot]# cp -d /usr/lib64/libnss3.so usr/lib64/

[root@Minilinux sysroot]# cp -d /usr/lib64/libnssutil3.so usr/lib64/

[root@Minilinux sysroot]# cp -d /usr/lib64/libnss_files.so usr/lib64/

设置环境变量便于ssh登陆:

[root@localhost ~]# vim /mnt/sysroot/root/.bash_profile

export PATH=$PATH:/usr/local/bin:/usr/local/sbin

启动dropdear:

[root@localhost sysroot]# mkdir /var/run/ -pv

[root@localhost sysroot]# dropbear -F -E

设置用户登陆后的环境变量:

[root@localhost ~]# vim /etc/profile

[ $UID -eq 0 ] && export PATH=/bin:/sbin/:/usr/bin:/usr/sbin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值