Linux运维知识之linux-裁剪Linux功能,编译/bin/login, busybox编译linux
小标 2018-09-07 来源 : 阅读 1896 评论 0

摘要:本文主要向大家介绍了Linux运维知识之linux-裁剪Linux功能,编译/bin/login, busybox编译linux,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

本文主要向大家介绍了Linux运维知识之linux-裁剪Linux功能,编译/bin/login, busybox编译linux,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

linux功能:终端提示信息

[aliyunzixun@xxx.com ~]# cat /etc/issueRed Hat Enterprise Linux Server release 5.8 (Tikanga)Kernel /r on an /m

[aliyunzixun@xxx.com ~]# uname -r2.6.18-308.el5[aliyunzixun@xxx.com ~]# uname -mx86_64[aliyunzixun@xxx.com ~]#

linux功能:用户

nsswitch: Network Service Switch (网络服务转换)框架:/etc/passwd, /etc/shadow, /etc/group库:libnss_file.so, libnss_nis.so, libnsss_ldap.so配置文件: /etc/nsswitch.conf

[aliyunzixun@xxx.com ~]# cat /etc/nsswitch.conf ## /etc/nsswitch.conf## An example Name Service Switch config file. This file should be# sorted with the most-used services at the beginning.## The entry ‘[NOTFOUND=return]’ means that the search for an# entry should stop if the search in the previous entry turned# up nothing. Note that if the search failed due to some other reason# (like no NIS server responding) then the search continues with the# next entry.## Legal entries are:##nisplus or nis+Use NIS+ (NIS version 3)#nis or ypUse NIS (NIS version 2), also called YP#dnsUse DNS (Domain Name Service)#filesUse the local files#dbUse the local database (.db) files#compatUse NIS on compat mode#hesiodUse Hesiod for user lookups#[NOTFOUND=return]Stop searching if not found so far#

# To use db, put the "db" in front of "files" for entries you want to be# looked up first in the databases## Example:#passwd: db files nisplus nis#shadow: db files nisplus nis#group: db files nisplus nis

passwd: filesshadow: filesgroup: files

#hosts: db files nisplus nis dnshosts: files dns

# Example – obey only what nisplus tells us…#services: nisplus [NOTFOUND=return] files#networks: nisplus [NOTFOUND=return] files#protocols: nisplus [NOTFOUND=return] files#rpc: nisplus [NOTFOUND=return] files#ethers: nisplus [NOTFOUND=return] files#netmasks: nisplus [NOTFOUND=return] files

bootparams: nisplus [NOTFOUND=return] files

ethers: filesnetmasks: filesnetworks: filesprotocols: filesrpc: filesservices: files

netgroup: nisplus

publickey: nisplus

automount: files nisplusaliases: files nisplus

sudoers: files ldap# Do not remove the following line, or various programs 2 # that require network functionality will fail. 3 127.0.0.1 localhost.localdomain localhost 4 ::1 localhost6.localdomain6 localhost6~ ~

[aliyunzixun@xxx.com ~]# ll /lib/libnss* (库文件)-rwxr-xr-x 1 root root 36416 Jan 19 2012 /lib/libnss_compat-2.5.solrwxrwxrwx 1 root root 20 Mar 13 10:30 /lib/libnss_compat.so.2 -> libnss_compat-2.5.so-rwxr-xr-x 1 root root 825028 Apr 8 2010 /lib/libnss_db-2.2.solrwxrwxrwx 1 root root 16 Mar 13 10:31 /lib/libnss_db.so.2 -> libnss_db-2.2.so-rwxr-xr-x 1 root root 21948 Jan 19 2012 /lib/libnss_dns-2.5.solrwxrwxrwx 1 root root 17 Mar 13 10:30 /lib/libnss_dns.so.2 -> libnss_dns-2.5.so-rwxr-xr-x 1 root root 50848 Jan 19 2012 /lib/libnss_files-2.5.solrwxrwxrwx 1 root root 19 Mar 13 10:30 /lib/libnss_files.so.2 -> libnss_files-2.5.so-rwxr-xr-x 1 root root 22764 Jan 19 2012 /lib/libnss_hesiod-2.5.solrwxrwxrwx 1 root root 20 Mar 13 10:30 /lib/libnss_hesiod.so.2 -> libnss_hesiod-2.5.so-rwxr-xr-x 1 root root 3208576 Dec 4 2011 /lib/libnss_ldap-2.5.solrwxrwxrwx 1 root root 18 Mar 13 10:31 /lib/libnss_ldap.so.2 -> libnss_ldap-2.5.so-rwxr-xr-x 1 root root 46568 Jan 19 2012 /lib/libnss_nis-2.5.so-rwxr-xr-x 1 root root 55804 Jan 19 2012 /lib/libnss_nisplus-2.5.solrwxrwxrwx 1 root root 21 Mar 13 10:30 /lib/libnss_nisplus.so.2 -> libnss_nisplus-2.5.solrwxrwxrwx 1 root root 17 Mar 13 10:30 /lib/libnss_nis.so.2 -> libnss_nis-2.5.so[aliyunzixun@xxx.com ~]# ll /usr/lib/libnss*-rwxr-xr-x 1 root root 1205444 Jan 13 2012 /usr/lib/libnss3.so-rwxr-xr-x 1 root root 435184 Jan 13 2012 /usr/lib/libnssckbi.solrwxrwxrwx 1 root root 24 Mar 13 10:31 /usr/lib/libnss_db.so -> ../../lib/libnss_db.so.2lrwxrwxrwx 1 root root 26 Mar 13 10:31 /usr/lib/libnss_ldap.so -> ../../lib/libnss_ldap.so.2-rwxr-xr-x 1 root root 102788 Jan 13 2012 /usr/lib/libnssutil3.so[aliyunzixun@xxx.com ~]#

移植库文件

[aliyunzixun@xxx.com ~]# cp -d /lib64/libnss_files* /mnt/sysroot/lib64/[aliyunzixun@xxx.com ~]# ls /mnt/sysroot/lib64/ld-linux-x86-64.so.2 libblkid.so.1 libdl.so.2 libnss_files.so.2 librt.so.1 libtermcap.so.2libacl.so.1 libc.so.6 libm.so.6 libpthread.so.0 libselinux.so.1 libuuid.so.1libattr.so.1 libdevmapper.so.1.02 libnss_files-2.5.so libresolv.so.2 libsepol.so.1 modules[aliyunzixun@xxx.com ~]# ll /mnt/sysroot/lib64/total 3444-rwxr-xr-x 1 root root 144776 Mar 19 07:20 ld-linux-x86-64.so.2-rwxr-xr-x 1 root root 27920 Mar 19 07:20 libacl.so.1-rwxr-xr-x 1 root root 18176 Mar 19 07:20 libattr.so.1-rwxr-xr-x 1 root root 43808 Mar 19 07:20 libblkid.so.1-rwxr-xr-x 1 root root 1722328 Mar 19 07:20 libc.so.6-r-xr-xr-x 1 root root 154640 Mar 19 07:20 libdevmapper.so.1.02-rwxr-xr-x 1 root root 23360 Mar 19 07:20 libdl.so.2-rwxr-xr-x 1 root root 615136 Mar 19 07:20 libm.so.6-rwxr-xr-x 1 root root 53880 Mar 19 07:43 libnss_files-2.5.solrwxrwxrwx 1 root root 19 Mar 19 07:43 libnss_files.so.2 -> libnss_files-2.5.so-rwxr-xr-x 1 root root 145872 Mar 19 07:20 libpthread.so.0-rwxr-xr-x 1 root root 92816 Mar 19 07:20 libresolv.so.2-rwxr-xr-x 1 root root 53448 Mar 19 07:20 librt.so.1-rwxr-xr-x 1 root root 95464 Mar 19 07:20 libselinux.so.1-rwxr-xr-x 1 root root 247496 Mar 19 07:20 libsepol.so.1-rwxr-xr-x 1 root root 15840 Mar 19 07:20 libtermcap.so.2-rwxr-xr-x 1 root root 17936 Mar 19 07:20 libuuid.so.1drwxr-xr-x 2 root root 1024 Mar 19 07:20 modules[aliyunzixun@xxx.com ~]# ls /mnt/sysroot/usr/bin lib64 local sbin[aliyunzixun@xxx.com ~]# cp -d /usr/lib64/libnss_files.so /mnt/sysroot/usr/lib64/[aliyunzixun@xxx.com ~]# cp -d /usr/lib64/libnss3.so /mnt/sysroot/usr/lib64/[aliyunzixun@xxx.com ~]# cp -d /usr/lib64/libnssutil3.so /mnt/sysroot/usr/lib64/[aliyunzixun@xxx.com ~]# ll /mnt/sysroot/usr/lib64/total 1716-rwxr-xr-x 1 root root 380464 Mar 19 07:20 libncurses.so.5-rwxr-xr-x 1 root root 1237944 Mar 19 07:44 libnss3.solrwxrwxrwx 1 root root 29 Mar 19 07:44 libnss_files.so -> ../../lib64/libnss_files.so.2-rwxr-xr-x 1 root root 123152 Mar 19 07:44 libnssutil3.so[aliyunzixun@xxx.com ~]#

[aliyunzixun@xxx.com ~]# cat /mnt/sysroot/etc/nsswitch.confpasswd: filesshadow: filesgroup: files#hosts: db files nisplus nis dnshosts: files dns[aliyunzixun@xxx.com ~]#

[aliyunzixun@xxx.com ~]# grep -E "^root|hadoop" /etc/shadowroot:$1$TjFLtg.N$BtOWZtw9.UBGwxTE07PK81:17238:0:99999:7:::hadoop:$1$zYoVuMh.$ySUuGs9FGRe1UFdaxWQ8B.:17244:0:99999:7:::[aliyunzixun@xxx.com ~]# grep -E "^root|hadoop" /etc/shadow > /mnt/sysroot/shadow

[aliyunzixun@xxx.com ~]# grep -E "^root|hadoop" /etc/shadow > /mnt/sysroot/etc/shadow[aliyunzixun@xxx.com ~]# grep -E "^root|hadoop" /etc/group > /mnt/sysroot/etc/group

[aliyunzixun@xxx.com ~]# ll /mnt/sysroot/etc/total 18-rw-r–r– 1 root root 125 Mar 19 07:20 fstab-rw-r–r– 1 root root 28 Mar 19 07:53 group-rw-r–r– 1 root root 239 Mar 19 07:20 inittab-rw-r–r– 1 root root 74 Mar 19 07:30 issue-rw-r–r– 1 root root 113 Mar 19 07:47 nsswitch.conf-rw-r–r– 1 root root 73 Mar 19 07:52 passwddrwxr-xr-x 6 root root 1024 Mar 19 07:20 rc.d-rw-r–r– 1 root root 120 Mar 19 07:53 shadowdrwxr-xr-x 3 root root 1024 Mar 19 07:20 sysconfig[aliyunzixun@xxx.com ~]#

添加

[aliyunzixun@xxx.com ~]# bash copylib.sh Your command: mingettycopy /sbin/mingetty finished.Continue: passwdcopy lib /usr/lib64/libuser.so.1 finished.copy lib /lib64/libcrypt.so.1 finished.copy lib /lib64/libgobject-2.0.so.0 finished.copy lib /lib64/libgmodule-2.0.so.0 finished.copy lib /lib64/libglib-2.0.so.0 finished.copy lib /usr/lib64/libpopt.so.0 finished.copy lib /lib64/libpam_misc.so.0 finished.copy lib /lib64/libaudit.so.0 finished.copy lib /lib64/libpam.so.0 finished.copy /usr/bin/passwd finished.Continue: useraddcopy /usr/sbin/useradd finished.Continue: userdelcopy /usr/sbin/userdel finished.Continue: usermodcopy /usr/sbin/usermod finished.Continue: groupaddcopy /usr/sbin/groupadd finished.Continue:

[aliyunzixun@xxx.com sysroot]# cat etc/inittab id:3:initdefault:si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0l3:3:wait:/etc/rc.d/rc 3l6:6:wait:/etc/rc.d/rc 6

1:2345:respawn:/sbin/agetty -n -l /bin/bash 38400 tty12:2345:respawn:/sbin/agetty -n -l /bin/bash 38400 tty2[aliyunzixun@xxx.com sysroot]#

[aliyunzixun@xxx.com sysroot]# cat etc/inittabid:3:initdefault:si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0l3:3:wait:/etc/rc.d/rc 3l6:6:wait:/etc/rc.d/rc 6

1:2345:respawn:/sbin/mingetty tty12:2345:respawn:/sbin/mingetty tty2[aliyunzixun@xxx.com sysroot]#

编译/bin/login程序,不需要密码认证

//www.cnblogs.com/xianyunhe/archive/2011/08/08/2124342.html

(1) 查看/bin/login所属的软件包[aliyunzixun@xxx.com ~]# rpm -qf /bin/loginutil-linux-2.13-0.47.el5(2)下载login对应的源码util-linux-2.13-0.47.e15.src.rpm(3)解压源码包[aliyunzixun@xxx.com Desktop]# rpm -ivh util-linux-2.13-0.47.e15.src.rp

解压后的源码包所在的目录为: /usr/src/redhat/SOURCES/查看解压的文件:

[aliyunzixun@xxx.com ~]# ls /usr/src/redhat/SOURCES/floppy-0.12-locale.patch util-linux-2.13-blockdev-rmparts.patch util-linux-2.13-mount-comment.patchfloppy-0.12.tar.gz util-linux-2.13-cal-3.patch util-linux-2.13-mount-context.patchnologin.8 util-linux-2.13-cal-wide.patch util-linux-2.13-mount-fake.patchnologin.c util-linux-2.13-cramfs-maxentries.patch util-linux-2.13-mount-fsname.patchraw-handle-nonpresent-devs.patch util-linux-2.13-cramfs-zerofiles.patch util-linux-2.13-mount-man-bind.patchutil-linux-2.11f-rawman.patch util-linux-2.13-ctrlaltdel-man.patch util-linux-2.13-mount-man-bugs.patchutil-linux-2.11y-chsh-103004.patch util-linux-2.13-ctty3.patch util-linux-2.13-mount-man-ext.patchutil-linux-2.11y-fdisksegv-103954.patch util-linux-2.13-fdisk-1TB.patch util-linux-2.13-mount-man-nfs4.patchutil-linux-2.11y-multibyte.patch util-linux-2.13-fdisk-b-4096.patch util-linux-2.13-mount-man-nfs.patchutil-linux-2.11y-procpartitions-37436.patch util-linux-2.13-fdisk-dm.patch util-linux-2.13-mount-man-vfat.patchutil-linux-2.11y-skipraid2.patch util-linux-2.13-fdisk-dos.patch util-linux-2.13-mount-move.patchutil-linux-2.12a-126572-fdiskman.patch util-linux-2.13-fdisk-gpt.patch util-linux-2.13-mount-mtabfake.patchutil-linux-2.12a-16415-rdevman.patch util-linux-2.13-fdisk-isfull.patch util-linux-2.13-mount-mtab.patchutil-linux-2.12a-ipcs-84243-86285.patch util-linux-2.13-fdisk-limit.patch util-linux-2.13-mount-nonfs.patchutil-linux-2.12a-mountbylabel-dm.patch util-linux-2.13-fdisk-man.patch util-linux-2.13-mount-setuid.patchutil-linux-2.12a-mount-man-cifs.patch util-linux-2.13-fdisk-sectors.patch util-linux-2.13-mount-sloppy.patchutil-linux-2.12a-pamsession.patch util-linux-2.13-fdisk-sleep.patch util-linux-2.13-mount-subtree.patchutil-linux-2.12a-pamstart.patch util-linux-2.13-fdisk-vmware.patch util-linux-2.13-mount-twiceloop.patchutil-linux-2.12a-partlimit.patch util-linux-2.13-flock-segfaults.patch util-linux-2.13-mount-uhelper.patchutil-linux-2.12a-raw-man-dd.patch util-linux-2.13-fsfreeze.patch util-linux-2.13-mount-uuid.patchutil-linux-2.12j-113790-hotkeys.patch util-linux-2.13-fstab-man.patch util-linux-2.13-partx-man.patchutil-linux-2.12j-managed.patch util-linux-2.13-hexdump-gcc.patch util-linux-2.13-pre7.tar.bz2util-linux-2.12j-pamconsole.patch util-linux-2.13-ipcs-32bit.patch util-linux-2.13-raw-raw0.patchutil-linux-2.12p-cal-wide.patch util-linux-2.13-ipcs-rc.patch util-linux-2.13-rnetdev.patchutil-linux-2.12p-col-EILSEQ.patch util-linux-2.13-ipcs-shmax.patch util-linux-2.13-schedutils-man.patchutil-linux-2.12p-execl.patch util-linux-2.13-localedir.patch util-linux-2.13-schedutils-SCHED_BATCH.patchutil-linux-2.12p-fdformat-ide.patch util-linux-2.13-login-hang.patch util-linux-2.13-script-races.patchutil-linux-2.12p-floppy-generic.patch util-linux-2.13-login-hush.patch util-linux-2.13-script-utempter.patchutil-linux-2.12p-fstab-man.patch util-linux-2.13-login-ipv6.patch util-linux-2.13-sfdisk-geo.patchutil-linux-2.12p-ipcs-typo.patch util-linux-2.13-login-man-userswitch.patch util-linux-2.13-sfdisk-sectors.patchutil-linux-2.12p-login-lastlog.patch util-linux-2.13-login-pam-acct.patch util-linux-2.13-sfdisk-write.patchutil-linux-2.12p-look-separator.patch util-linux-2.13-login-timeval.patch util-linux-2.13-swapon-ignore.patchutil-linux-2.12p-lvm2dupes-76467.patch util-linux-2.13-login-utmp.patch util-linux-2.13-swapon-suspend.patchutil-linux-2.12p-mount-ocfs2.patch util-linux-2.13-losetup-all.patch util-linux-2.13-swap-page.patchutil-linux-2.12p-mtab-lock.patch util-linux-2.13-losetup-deprecated.patch util-linux-2.13-umount-sysfs.patchutil-linux-2.12p-swaponsymlink-57300.patch util-linux-2.13-losetup-rdonly.patch util-linux-60-raw.rulesutil-linux-2.12p-vipw-perm.patch util-linux-2.13-mkfs-man.patch util-linux-chsh-chfn.pamdutil-linux-2.13-arch.patch util-linux-2.13-mkswap-mounted.patch util-linux-login.pamdutil-linux-2.13-audit-hwclock.patch util-linux-2.13-mkswap-selinux.patch util-linux-remote.pamdutil-linux-2.13-audit-login.patch util-linux-2.13-mkswap-v0.patchutil-linux-2.13-blockdev-man.patch util-linux-2.13-moretc.patch[aliyunzixun@xxx.com ~]# ls /usr/src/redhat/SOURCES/util-linux-2.13*tar*util-linux-2.13-pre7.tar.bz2继续解压文件[aliyunzixun@xxx.com ~]# tar xf /usr/src/redhat/SOURCES/util-linux-2.13-pre7.tar.bz2解压后的文件夹为util-linux-2.13-pre7。

[aliyunzixun@xxx.com ~]# lsanaconda-ks.cfg fuse-libs-2.7.4-8_12.el5.x86_64.rpm reload.sh util-linux-2.13-0.59.el5.src.rpmboot.gz initrd-2.6.18-308.el5.img.gz screen-4.0.3 util-linux-2.13-0.59.el5.x86_64.rpmcopylib.sh install.log screen-4.0.3.tar.gz util-linux-2.13-pre7Desktop install.log.syslog sysroot3.gz vim74fuse-2.7.4 iso sysroot4.gz vim-7.4.tar.bz2fuse-2.7.4-8_12.el5.x86_64.rpm linux-2.6.28.10.tar.gz sysroot6.gzfuse-2.7.4.tar.gz ntfs-3g-2009.4.4 sysroot.gzfuse-kmdl-2.6.18-308.24.1.el5-2.7.4-8_12.el5.x86_64.rpm ntfs-3g-2009.4.4.gz test[aliyunzixun@xxx.com ~]#

其中login的源码的目录为/usr/src/redhat/SOURCES/util-linux-2.13-pre7/login-utilslogin-utils文件中不存在make文件,因此,需要自己编写编译命令来生成login。

[aliyunzixun@xxx.com util-linux-2.13-pre7]# lsABOUT-NLS config configure.ac example.files hwclock lib m4 misc-utils partx schedutilsaclocal.m4 config.h.in COPYING fdisk include licenses Makefile.am mount po sys-utilsAUTHORS configure disk-utils getopt INSTALL login-utils Makefile.in NEWS README text-utils[aliyunzixun@xxx.com util-linux-2.13-pre7]# ls login-utils/agetty.8 chsh.1 initctl.8 last.c Makefile.in newgrp.c selinux_utils.c shutdown.c ttymsg.h wall.cagetty.c chsh.c initctl.c login.1 mesg.1 README.getty selinux_utils.h simpleinit.8 vigr.8checktty.c fastboot.8 islocal.c login.c mesg.c README.modems-with-agetty setpwnam.c simpleinit.c vipw.8chfn.1 fasthalt.8 islocal.h login.h my_crypt.h README.poeigl setpwnam.h simpleinit.h vipw.cchfn.c halt.8 last.1 Makefile.am newgrp.1 reboot.8 shutdown.8 ttymsg.c wall.1[aliyunzixun@xxx.com util-linux-2.13-pre7]#

(4)修改login.c中的代码把344行的passwd_req = 1;更改为passwd_req = 0;在文件中添加locale.h头文件#include(5)编译生成login[aliyunzixun@xxx.com login-utils]# gcc -o login login.c ../lib/setproctitle.c checktty.c -Wall -lcrypt -I ../include/(6)更新login[aliyunzixun@xxx.com login-utils]# cp login /bin/login

重启,即可在文本模式中以root账户登录。

修改输入提示符

[aliyunzixun@xxx.com sysroot]# cat .bash_profile PS1='[/aliyunzixun@xxx.com/h /w]/$’ (用户名、主机名、工作目录名的基名、#)export PS1[aliyunzixun@xxx.com sysroot]#


查看本机硬件设备信息:1、cat /proc/cpuinfo

2、lsusb

3、lspci

4、hal-deviceHardware Abstract Layer

[aliyunzixun@xxx.com ~]# lsusbProtocol spec without prior Class and Subclass spec at line 4297Bus 001 Device 001: ID 0000:0000 Bus 002 Device 001: ID 0000:0000 Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual MouseBus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub[aliyunzixun@xxx.com ~]# lspci00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX – 82443BX/ZX/DX Host bridge (rev 01)00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX – 82443BX/ZX/DX AGP bridge (rev 01)00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)00:0f.0 VGA compatible controller: VMware SVGA II Adapter00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)00:11.0 PCI bridge: VMware PCI bridge (rev 02)00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01)00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01)00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01)00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)02:00.0 USB controller: VMware USB1.1 UHCI Controller02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)02:02.0 Multimedia audio controller: Ensoniq ES1371 [AudioPCI-97] (rev 02)02:03.0 USB controller: VMware USB2 EHCI Controller02:05.0 SATA controller: VMware Device 07e0[aliyunzixun@xxx.com ~]#

编译内核:1、配置make menuconfigmake gconfigmake kconfigmake oldconfigmake config

保存为.config

2、编译makemake modules_installmake install

模块安装位置:/lib/modules/KERNEL_VERSION/

如何实现部分编译:1、只编译某子目录下的相关代码:make dir/

make arch/make drivers/net/

2、只编译部分模块make M=drivers/net/

3、只编译某一模块make drivers/net/pcnet32.ko

4、将编译完成的结果放置于别的目录中make O=/tmp/kernel

5、交叉编译make ARCH=

www.busybox.net

busybox可以模拟大部分linux命令;kernel+busybox可以模拟linux

initrd也是一个linux,busybox也可以模拟initrd

rootfs

如何编译busybox:(静态编译)

[aliyunzixun@xxx.com ~]# cd busybox-1.20.2[aliyunzixun@xxx.com busybox-1.20.2]# make menuconfig



准备分区IDE: /dev/hdb1: ext3 /boot/dev/hdb2: ext3 /

[aliyunzixun@xxx.com ~]# fdisk -l

Disk /dev/hda: 21.4 GB, 21474836480 bytes15 heads, 63 sectors/track, 44384 cylindersUnits = cylinders of 945 * 512 = 483840 bytes

Device Boot Start End Blocks Id System/dev/hda1 1 42 19813+ 83 Linux/dev/hda2 43 1101 500377+ 83 Linux

Disk /dev/hdb: 21.4 GB, 21474836480 bytes15 heads, 63 sectors/track, 44384 cylindersUnits = cylinders of 945 * 512 = 483840 bytes

Disk /dev/hdb doesn’t contain a valid partition table

Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System/dev/sda1 * 1 38 305203+ 83 Linux/dev/sda2 39 2484 19647495 83 Linux/dev/sda3 2485 2610 1012095 82 Linux swap / Solaris[aliyunzixun@xxx.com ~]# fdisk /dev/hdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won’t be recoverable.

The number of cylinders for this disk is set to 44384.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-44384, default 1): Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-44384, default 44384): +20M

Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 2First cylinder (43-44384, default 43): Using default value 43Last cylinder or +size or +sizeM or +sizeK (43-44384, default 44384): +512M

Command (m for help): p

Disk /dev/hdb: 21.4 GB, 21474836480 bytes15 heads, 63 sectors/track, 44384 cylindersUnits = cylinders of 945 * 512 = 483840 bytes

Device Boot Start End Blocks Id System/dev/hdb1 1 42 19813+ 83 Linux/dev/hdb2 43 1101 500377+ 83 Linux

Command (m for help): wThe partition table has been altered!

Calling ioctl() to re-read partition table.Syncing disks.[aliyunzixun@xxx.com ~]# mke2fs -j /dev/hdb1 mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)4968 inodes, 19812 blocks990 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=204472323 block groups8192 blocks per group, 8192 fragments per group1656 inodes per groupSuperblock backups stored on blocks: 8193

Writing inode tables: done Creating journal (1024 blocks): doneWriting superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[aliyunzixun@xxx.com ~]# mke2fs -j /dev/hdb2 mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)125488 inodes, 500376 blocks25018 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6763315262 block groups8192 blocks per group, 8192 fragments per group2024 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[aliyunzixun@xxx.com ~]#

busybox编译过程失败

内核头版本较低,缺少头文件,导致busybox编译失败

解决办法:将内核linux-2.6.38.5/include/mtd/ubi-user.h复制到/root/busybox-1.20.2/mtd/ 下

[aliyunzixun@xxx.com ~]# tar xf busybox-1.20.2.tar.bz2 [aliyunzixun@xxx.com ~]# cd busybox-1.20.2[aliyunzixun@xxx.com busybox-1.20.2]# lsapplets AUTHORS coreutils editors init LICENSE Makefile.custom modutils README shell TODO_unicodeapplets_sh Config.in debianutils examples INSTALL loginutils Makefile.flags networking runit sysklogd util-linuxarch configs docs findutils libbb mailutils Makefile.help printutils scripts testsuitearchival console-tools e2fsprogs include libpwdgrp Makefile miscutils procps selinux TODO[aliyunzixun@xxx.com busybox-1.20.2]# cd include/[aliyunzixun@xxx.com include]# lsapplet_metadata.h ar.h bb_e2fs_defs.h dump.h grp_.h libbb.h platform.h rtc_.h unicode.h volume_id.h xregex.happlets.src.h bb_archive.h busybox.h fix_u32.h inet_common.h liblzo_interface.h pwd_.h shadow_.h usage.src.h xatonum.h[aliyunzixun@xxx.com include]# mkdir mtd[aliyunzixun@xxx.com include]# cp /usr/src/linux-2.6.38.5/include/mtd/ubi-user.h mtd/[aliyunzixun@xxx.com include]# ls mtd/ubi-user.h[aliyunzixun@xxx.com include]# cd ..[aliyunzixun@xxx.com busybox-1.20.2]# pwd/root/busybox-1.20.2[aliyunzixun@xxx.com busybox-1.20.2]# [aliyunzixun@xxx.com busybox-1.20.2]# [aliyunzixun@xxx.com busybox-1.20.2]# make install

[aliyunzixun@xxx.com busybox-1.20.2]# lsapplets busybox Config.in docs include libpwdgrp Makefile.custom networking scripts TODOapplets_sh busybox.links configs e2fsprogs init LICENSE Makefile.flags printutils selinux TODO_unicodearch busybox_unstripped console-tools editors _install loginutils Makefile.help procps shell util-linuxarchival busybox_unstripped.map coreutils examples INSTALL mailutils miscutils README sysklogdAUTHORS busybox_unstripped.out debianutils findutils libbb Makefile modutils runit testsuite[aliyunzixun@xxx.com busybox-1.20.2]# ls _install/ (生成_install文件,作为模板)

bin linuxrc sbin usr[aliyunzixun@xxx.com busybox-1.20.2]#

initrd仅需要提供内核访问真正的rootfs所在存储设备、文件系统相关的驱动;

[aliyunzixun@xxx.com busybox-1.20.2]# cp _install /tmp/busybox -a[aliyunzixun@xxx.com busybox-1.20.2]# cd /tmp/busybox/[aliyunzixun@xxx.com busybox]# lsbin linuxrc sbin usr[aliyunzixun@xxx.com busybox]# rm -f linuxrc [aliyunzixun@xxx.com busybox]# lltotal 24drwxr-xr-x 2 root root 4096 Mar 20 09:39 bindrwxr-xr-x 2 root root 4096 Mar 20 09:39 sbindrwxr-xr-x 4 root root 4096 Mar 20 09:39 usr[aliyunzixun@xxx.com busybox]# mkdir porc sys etc dev sysroot lib /modules -pv (以busybox生成initrd)mkdir: created directory `porc’mkdir: created directory `sys’mkdir: created directory `etc’mkdir: created directory `dev’mkdir: created directory `sysroot’mkdir: created directory `lib’mkdir: created directory `/modules’ [aliyunzixun@xxx.com busybox]# modinfo ext3 (为kernel访问rootfs ext3提供模块)

filename: /lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.kolicense: GPLdescription: Second Extended Filesystem with journaling extensionsauthor: Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts’o and otherssrcversion: 26DC008FC415305C5F65313depends: jbdvermagic: 2.6.18-308.el5 SMP mod_unload gcc-4.1module_sig:883f3504f2324332d3142b3e704051112141c09f45fe672e4db062f41923995d307c2a22213ac59609f5474bd4a6ca7665da553738c019557064a811c2[aliyunzixun@xxx.com busybox]# modinfo jbdfilename: /lib/modules/2.6.18-308.el5/kernel/fs/jbd/jbd.kolicense: GPLsrcversion: 11842879E04FE2392B988CCdepends: vermagic: 2.6.18-308.el5 SMP mod_unload gcc-4.1module_sig:883f3504f2324332d3142b3e704051112263609f7a68e7433c9b3b9465cadb5165e78eb997ad1309e22e1a42144eb69c67e660a3d2f4ba94e2f12f42

[aliyunzixun@xxx.com busybox]# cp /lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko lib/modules/cp: overwrite `lib/modules/ext3.ko’? y[aliyunzixun@xxx.com busybox]# cp /lib/modules/2.6.18-308.el5/kernel/fs/jbd/jbd.ko lib/modules/cp: overwrite `lib/modules/jbd.ko’? y[aliyunzixun@xxx.com busybox]#[aliyunzixun@xxx.com busybox]# ls lib/modules/ext3.ko jbd.ko

[aliyunzixun@xxx.com ~]# mount/dev/sda2 on / type ext3 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)/dev/sda1 on /boot type ext3 (rw)tmpfs on /dev/shm type tmpfs (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)none on /proc/fs/vmblock/mountPoint type vmblock (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)/dev/hdb1 on /opt/boot type ext3 (rw)/dev/hdb2 on /opt/sysroot type ext3 (rw)[aliyunzixun@xxx.com ~]# grub-install –root-directory=/opt /dev/hdbProbing devices to guess BIOS drives. This may take a long time.Installation finished. No error reported.This is the contents of the device map /opt/boot/grub/device.map.Check if this is correct or not. If any of the lines is incorrect,fix it and re-run the script `grub-install’.

(fd0)/dev/fd0(hd0)/dev/hda(hd1)/dev/hdb(hd2)/dev/sda[aliyunzixun@xxx.com ~]# ls /opt/boot/grub vmlinuz

[aliyunzixun@xxx.com busybox]# mknod dev/console c 5 1[aliyunzixun@xxx.com busybox]# mknod dev/null c 1 3

[aliyunzixun@xxx.com busybox]# cat init #!/bin/sh

mount -t proc proc /procmount -t sysfs sysfs /sys

insmod /lib/modules/jbd.koinsmod /lib/modules/ext3.ko

mdev -smount -t ext3 /dev/hda2 /mnt/sysrootexec switch_root /mnt/sysroot /sbin/init

[aliyunzixun@xxx.com busybox]# find . | cpio -H newc –quiet -o | gzip -9 > /opt/boot/initrd.gz

[aliyunzixun@xxx.com busybox]# cp /boot/vmlinuz-2.6.18-308.el5 /opt/boot/vmlinuzcp: overwrite `/opt/boot/vmlinuz’? y

[aliyunzixun@xxx.com busybox]# cat /opt/boot/grub/grub.confdefault=0timeout=3title busybox linux 2.6.18root (hd0,0)kernel /vmlinuz ro root=/dev/hda2initrd /initrd.gz[aliyunzixun@xxx.com busybox]# cd[aliyunzixun@xxx.com ~]# cd busybox-1.20.2[aliyunzixun@xxx.com busybox-1.20.2]# cp _install/* /opt/sysroot/ -a[aliyunzixun@xxx.com busybox-1.20.2]# cd /opt/sysroot/[aliyunzixun@xxx.com sysroot]# lsbin linuxrc lost+found sbin usr[aliyunzixun@xxx.com sysroot]# rm -rf linuxrc [aliyunzixun@xxx.com sysroot]# mkdir -pv proc sys dev tmp var/{log,lock,run} lib/modules root boot mnt media etc/rc.d/init.dmkdir: created directory `proc’mkdir: created directory `sys’mkdir: created directory `dev’mkdir: created directory `tmp’mkdir: created directory `var’mkdir: created directory `var/log’mkdir: created directory `var/lock’mkdir: created directory `var/run’mkdir: created directory `lib’mkdir: created directory `lib/modules’mkdir: created directory `root’mkdir: created directory `boot’mkdir: created directory `mnt’mkdir: created directory `media’mkdir: created directory `etc’mkdir: created directory `etc/rc.d’mkdir: created directory `etc/rc.d/init.d'[aliyunzixun@xxx.com sysroot]# ls sbin/acpid bootchartd findfs halt ifenslave loadkmap man mkfs.minix nameif rmmod start-stop-daemon sysctl watchdogadjtimex depmod freeramdisk hdparm ifup logread mdev mkfs.vfat pivot_root route sulogin syslogd zciparp devmem fsck hwclock init losetup mkdosfs mkswap poweroff runlevel swapoff tunctlblkid fbsplash fsck.minix ifconfig insmod lsmod mke2fs modinfo raidautorun setconsole swapon udhcpcblockdev fdisk getty ifdown klogd makedevs mkfs.ext2 modprobe reboot slattach switch_root vconfig[aliyunzixun@xxx.com sysroot]#

[aliyunzixun@xxx.com sysroot]# vim etc/inittab[aliyunzixun@xxx.com sysroot]# cat etc/inittab::sysinit:/etc/rc.d/rc.sysinitconsole::respawn:-/bin/sh::ctrlaltdel:/sbin/reboot::shutdown:/bin/umount -a -r[aliyunzixun@xxx.com sysroot]# vim etc/fstab[aliyunzixun@xxx.com sysroot]# cat etc/fstabsysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0/dev/hda1 /boot ext3 defaults 0 0/dev/hda2 / ext3 defaults 1 1

rc.sysinit初始除rootfs之外的驱动程序

[aliyunzixun@xxx.com sysroot]# mknod dev/console c 5 1[aliyunzixun@xxx.com sysroot]# mknod dev/null c 1 3

[aliyunzixun@xxx.com sysroot]# vim etc/rc.d/rc.sysinit[aliyunzixun@xxx.com sysroot]# cat etc/rc.d/rc.sysinit#!/bin/shecho -e "/tWelcome to /033[31mbusybox /033[0m Linux"

echo -e "Remounting the root filesystem …"mount -t proc proc /procmount -t sysfs sysfs /sysmount -o remount,rw /

echo -e "Creating the files of device …"mdev -s

echo -e "Mounting the filesystem …"mount -aswapon -a

echo -e "Starting the log daemon …"syslogdklogd

echo -e "Configuring loopback interface …"ifconfig lo 127.0.0.1/24[aliyunzixun@xxx.com sysroot]# chmod +x etc/rc.d/rc.sysinit[aliyunzixun@xxx.com sysroot]#

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved