linux内核编译支持ssh,编译内核+BusyBox定制一个Linux提供ssh和web服务

本次试验大致规划和步骤:完全定制一个linux系统;能让其远程登录和提供web服务。

1、添加一块空闲磁盘

2、下载编译内核

3、并为空闲磁盘安装grub

前提准备:[root@soul ~]# fdisk /dev/sdb 分区

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x4e977ad9

Device Boot Start End Blocks Id System

/dev/sdb1 1 7 56196 83 Linux

/dev/sdb2 8 73 530145 83 Linux

/dev/sdb3 74 107 273105 82 Linux swap / Solaris

#格式化操作

[root@soul ~]# mke2fs -t ext4 /dev/sdb1

[root@soul ~]# mke2fs -t ext4 /dev/sdb2

[root@soul ~]# mkswap /dev/sdb3

[root@soul ~]# mkdir -pv /mnt/{boot,sysroot}

[root@soul ~]# mount /dev/sdb1 /mnt/boot/

[root@soul ~]# mount /dev/sdb2 /mnt/sysroot/

[root@soul ~]# grub-install --root-directory=/mnt /dev/sdb 安装grub

[root@soul ~]# ls /mnt/boot/

grub lost+found

[root@soul ~]# 上述信息显示安装成功

其中需要一个脚本来移植命令和所依赖的库文件:#脚本可能不完善;不过可用

#!/bin/bash

aimDir=/mnt/sysroot

cmdInput() {

if which $cmd &> /dev/null;then

cmdPath=`which --skip-alias $cmd`

else

echo "No such command."

return 5

fi

}

cpCmd() {

cmdDir=`dirname $cmdPath`

[ -d ${aimDir}${cmdDir} ] || mkdir -p ${aimDir}${cmdDir}

[ -f $cmdPath ] && cp $cmdPath ${aimDir}${cmdDir}

}

cpLib() {

for libPath in `ldd $cmdPath | grep -o "/[^[:space:]]\{1,\}"`;do

libDir=`dirname $libPath`

[ -d ${aimDir}${libDir} ] || mkdir -p ${aimDir}${libDir}

[ -f $libPath ] && cp $libPath ${aimDir}${libDir}

done

}

echo "You can input [q|Q] quit."

while true;do

read -p "Enter a command: " cmd

if [[ "$cmd" =~ \(|q|Q|\) ]];then

echo "You choose quit."

exit 0

fi

cmdInput

[ $? -eq 5 ] && continue

cpCmd

cpLib

[ $? -eq 0 ] && echo -e "\033[36mCopy successful.\033[0m"

done

一、编译内核

[root@soul ~]# ls

anaconda-ks.cfg install.log install.log.syslog linux-3.13.8.tar.xz

[root@soul ~]# 这里下载的是目前最新的稳定版

[root@soul ~]# tar xf linux-3.13.8.tar.xz -C /usr/src/

[root@soul ~]# ln -sv /usr/src/linux-3.13.8/ /usr/src/linux 创建链接

`/usr/src/linux' -> `/usr/src/linux-3.13.8/'

[root@soul ~]# cd /usr/src/linux

[root@soul linux]#

#编译

[root@soul linux]# make allnoconfig 清除所有选择;然后重新选择定制

HOSTCC scripts/basic/fixdep

HOSTCC scripts/kconfig/conf.o

SHIPPED scripts/kconfig/zconf.tab.c

SHIPPED scripts/kconfig/zconf.lex.c

SHIPPED scripts/kconfig/zconf.hash.c

HOSTCC scripts/kconfig/zconf.tab.o

HOSTLD scripts/kconfig/conf

scripts/kconfig/conf --allnoconfig Kconfig

#

# configuration written to .config

#

[root@soul linux]# make menuconfig

#下面的选择没办法列出来;给个大概

1、选择CPU类型

2、支持动态模块装载

3、PCI总线支持

4、硬盘驱动

5、文件系统

6、可执行文件格式

7、I/O驱动;USB驱动

8、devtmpfs支持

9、选择网络支持以及网卡驱动

#结束后备份下配置文件;然后编译成bzImage格式

[root@soul linux]# cp .config /root/config-3.13.8-x86_64

[root@soul linux]# make bzImage

[root@soul linux]# cp arch/x86/boot/bzImage /mnt/boot/

二、安装BusyBox

BusyBox是一个遵循GPL协议、以自由软件形式发布的应用程序。Busybox在单一的可执行文件中提供了精简的Unix工具集(例如shell、init、getty、login...),可运行于多款POSIX环境的操作系统,例如Linux(包括Android)、Hurd、FreeBSD等等。

1、安装;官方下载地址:http://www.busybox.net/

#因为稍后需要编译busybox为静态二进制程序;所以需要实现安装glibc-static和libmcrypt-devel;

#glibc-static在安装光盘的第二张光盘上;可以挂在安装;也可以到网上下载

[root@soul busybox-1.22.1]# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

[root@soul busybox-1.22.1]# yum -y install /media/Packages/glibc-static-2.12-1.132.el6.x86_64.rpm

[root@soul ~]# ls

anaconda-ks.cfg config-3.13.8-x86_64 install.log.syslog

busybox-1.22.1.tar.bz2 install.log linux-3.13.8.tar.xz

[root@soul ~]#

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

[root@soul ~]# cd busybox-1.22.1 #安装可以查看INSTALL文件说明

[root@soul busybox-1.22.1]# make menuconfig

Busybox Settings --->

Build Options --->

[*] Build BusyBox as a static

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值