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

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

1、添加一块空闲磁盘

2、下载编译内核

3、并为空闲磁盘安装grub

前提准备:

[root@soul ~]# fdisk /dev/sdb 分区Command (m for help): pDisk /dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x4e977ad9 Device BootStartEndBlocks Id System/dev/sdb11756196 83 Linux/dev/sdb2873530145 83 Linux/dev/sdb374107273105 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/bashaimDir=/mnt/sysrootcmdInput() {if which $cmd &> /dev/null;thencmdPath=`which –skip-alias $cmd`elseecho “No such command.”return 5fi}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,\}”`;dolibDir=`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|\) ]];thenecho “You choose quit.”exit 0 ficmdInput[ $? -eq 5 ] && continuecpCmdcpLib[ $? -eq 0 ] && echo -e “\033[36mCopy successful.\033[0m”done

一、编译内核

下载地址:https://www.kernel.org/

[root@soul ~]# lsanaconda-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/confscripts/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/

1、安装;官方下载地址:

#因为稍后需要编译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 ~]# lsanaconda-ks.cfgconfig-3.13.8-x86_64 install.log.syslogbusybox-1.22.1.tar.bz2 install.loglinux-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 menuconfigBusybox Settings —>Build Options —>[*] Build BusyBox as a static binary (no shared libs) #选中这项#其他选项都不需要改动了[root@soul busybox-1.22.1]# makeperl: warning: Setting locale failed.perl: warning: Please check that your locale settings:LANGUAGE = (unset),LC_ALL = (unset),LANG = “en”#根据提示设置下[root@soul busybox-1.22.1]# export LANGUAGE=en_US.UTF-8[root@soul busybox-1.22.1]# export LANG=en_US.UTF-8[root@soul busybox-1.22.1]# export LC_ALL=en_US.UTF-8[root@soul busybox-1.22.1]# make 再次make通过[root@soul busybox-1.22.1]# make install————————————————–You will probably need to make your busybox binarysetuid root to ensure all configured applets willwork properly.————————————————–[root@soul busybox-1.22.1]#[root@soul busybox-1.22.1]# ls _install/bin linuxrc sbin usr[root@soul busybox-1.22.1]# cp -a _install/* /mnt/sysroot/[root@soul busybox-1.22.1]# cd /mnt/sysroot/[root@soul sysroot]# lsbin linuxrc lost+found sbin usr[root@soul sysroot]# mkdir -pv etc/rc.d var/log root proc sys srv boot mnt tmp home dev lib lib64

2、提供一个grub.conf文件

所有的失败,与失去自己的失败比起来,更是微不足道

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

相关文章:

你感兴趣的文章:

标签云: