<div class="artical-content-bak main-content editor-side-new">
<div class="con editor-preview-side" id="result">
<blockquote>
<p>为什么要自己编译linux呢?</p>
<p> 因为可以更高效的利用系统资源,把应用使用中没有必要加载的模块可以去掉,以使系统运行更加流畅。编译时可以根据硬件的芯片的不同做出一定的修改、匹配,使能更加稳定的运行。也就是为硬件定制了一套特有的操作系统。</p>
<p>下面的操作仅供参考,</p>
</blockquote>
<blockquote>
<p>机器型号:(虚拟机上编译)</p>
<p>processor : 0 <br>vendor_id : GenuineIntel <br>cpu family : 6 <br>model : 37 <br>model name : Intel(R) Core(TM) i3 CPU M 380 @ 2.53GHz <br>stepping : 5 <br>microcode : 0x2 <br>cpu MHz : 2525.993 <br>cache size : 3072 KB <br>physical id : 0</p>
</blockquote>
<p> </p>
<p>说明:(由于编译时截图太多没有在这里体现,图片在我的相册中有,大家可以参考) <br>----------------------------------------------------------------------------------------- </p>
<p>实例:手动编译内核, <br> 1、下载安装包并解压 <br> 内核包linux-3.13.6.tar.xz <br> #tar xf linux-3.13.6.tar.xz -C /usr/src <br> # cd /usr/src <br> # ln -sv linux-3.13.6/ linux <br> # cd linux <br> # make allnoconfig <br> # make menuconfig(有截图) <br> # make -j 3 <br> Kernel: arch/x86/boot/bzImage is ready (#1)(编译完成后,指明的kernel的存放位置) <br> # cp arch/x86/boot/bzImage /mnt/boot/(复制编译最后一样kernel到/mnt/boot/) <br> # sync <br> 2、分区格式划磁盘(新添加磁盘) <br> # fdisk /dev/sdb (sdb1 50M;sdb2 512M) <br> # mke2fs -t ext4 /dev/sdb1 <br> # mke2fs -t ext4 /dev/sdb2 <br> # mkdir /mnt/{boot,sysroot} <br> # mount /dev/sdb1 /mnt/boot <br> # mount /dev/sdb2 /mnt/sysroot <br> # grub-install --root-directory=/mnt /dev/sdb <br> # vim /mnt/boot/grub/grub.conf</p>
<p> timeout=5 <br> default=0 <br> title Customed Linux (3.13.8) <br> root (hd0,0) <br> kernel /bzImage ro root=/dev/sda2 init=/sbin/init <br> # cd /mnt/sysroot <br> # mkdir -pv proc sys dev tmp etc/init.d var usr mnt media home root boot sbin <br> # vim /mnt/sysroot/sbin/init</p>
<p> #!/bin/bash <br> # <br> echo -e "Welcome to \033[34mCustomed\033[0m Linux" <br> mount -n -t proc proc /proc <br> mount -n -t sysfs sysfs /sys <br> mount -n -t devtmpfs none /dev <br> mount -n -o remount,rw /dev/sda2 / <br> /bin/bash <br> # chmod +x /mnt/sysroot/sbin/init <br> # bash -n /mnt/sysroot/sbin/init <br> # bash 1.sh <br> Plz enter a command: bash <br> Plz enter a command: mount <br> Plz enter a command: umount <br> Plz enter a command: ls <br> Plz enter a command: ps <br> Plz enter a command: kill <br> Plz enter a command: cat <br> Plz enter a command: quit <br> #sync <br> # chroot /mnt/sysroot(测试下) <br> bash-4.1# ls <br> bin boot dev etc home lib64 lost+found media mnt proc root sbin sys tmp usr var <br> bash-4.1# exit <br> exit</p>
<p> 把硬盘挂载新建虚拟机上启用,能正常启动!</p>
<p> <br> 3、完善功能添加网络功能 <br> # cd /usr/src/linux <br> # make menuconfig(有截图) <br> # make -j 3 <br> Kernel: arch/x86/boot/bzImage is ready (#2) <br> # cp arch/x86/boot/bzImage /mnt/boot/(编译完成后复制kernel覆盖原文件) <br> cp: overwrite `/mnt/boot/bzImage'? y <br> # sync <br> # bash 1.sh (复制一些网络功能的命令) <br> Plz enter a command: ifconfig <br> Plz enter a command: route <br> Plz enter a command: netstat <br> Plz enter a command: ping <br> Plz enter a command: quit <br> # sync <br> 挂起再次测试: <br> #export PATH=/bin:/sbin:/usr/bin:/usr/sbin <br> #ifconfig -a (有图)</p>
<p><a href="https://s1.51cto.com/attachment/201408/23/1384120_1408826617x2oE.jpg"><img alt="测试成功图" border="0" height="772" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-969f107165139f3d11e68b0bda4ae99d.jpg" style="border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;" title="测试成功图"></a> <br> 4、完善目标机器的命令功能装入busybox <br> 软件包:busybox-1.22.1.tar.bz2(或者从网站下载www.busybox.net) <br> 静态编译busybox <br> |
|