欢迎各位兄弟 发布技术文章
这里的技术是共享的
内核由两部分组成
核心: /boot/vmlinuz-version (# uname -r (r release)查看版本号)
内核模块(ko): /lib/modules/version/
内核设计风格:
单内核
模块化设计,内核很小,必须用命令装载某模块到内核中去
微内核
装载模块的命令:
insmod (insert mode )
modprobe (mode probe)
www.kernel.org: 内核版本与发行版的版本不是同一回事
用户空间访问,监控内核的方式:
/proc, /sys
伪文件系统
/proc/sys: /proc里面文件大多数是指是只读的,只有/proc/sys目录里的文件很多是可读写的,用户可以通过修改某些内容来修改内核的运行特性的
/sys/: 某些文件可写的 可以修改硬件的工作属性
设定内核参数值的方法
1) echo VALUE > /proc/sys/TO/SOME_FILE (不要用vim,因为它是伪文件)
2) sysctl:专门用来控制/proc/sys目录下某一个参数的值 (sysctl system control)
sysctl -w kernel.hostname= ( /proc/sys/TO/SOME_FILE 中 /proc/sys/不用写 后面的路径正斜线/改成. 有几个路径/就改成几个点) (-w write 写入)
上面两种方法一重启系统都会失效的,因为内核本身是在内存当中的,修改后是保存到内存中的,它能够立即生效,但是不能够永久有效
永久有效 (但无法立即生效): 编辑 /etc/sysctl.conf
/etc/rc.d/rc.sysinit 这个脚本是通过/etc/sysctl.conf文件来设定内核参数的
是通过sysctl -w kernel.hostname= 来写的 (当然是没有sysctl -w 的 )
(要想立即生效,先编辑/etc/rc.d/rc.sysinit,再使用上面的两个命令中的一个跟进一下
(不需要上面两个命令 只要 # sysctl -p 就可以了) )
(# sysctl -p 会通知内核重读这个文件,或者说重新设置内核参数)
( -p (-p相当于process) Load in sysctl settings from the file specified or
/etc/sysctl.conf if none given. Specifying - as filename means
reading data from standard input.)
sysctl -a : (-a all 吧)显示所有内核参数及其值
内核模块管理:
lsmod:查看 (能够列出内核中装载的每一个模块 名称 大小 及被使用了几次,被调用了几次,被谁调用了)
modprobe MOD_NAME (mode probe 模块探测) 装载某模块 (不需要指定模块路径,只需要指定模块名称)
modprobe -r MOD_NAME (-r remove) 卸载某模块 (不需要指定模块路径,只需要指定模块名称)
modinfo MOD_NAME : 查看模块的具体信息
insmod /PATH/TO/MODULE_FILE : (insert mode) 装载模块 (必须要指定模块路径才行)
rmmod MODULE_NAME : (remove mode) 移除模块 (不要指定模块路径,只需要指定名称)
depmod /PATH/TO/MODULES_DIR : (depends mode)(依赖模块) 可以帮助我们生成模块依赖关系
生成后保存在这个模块当中 (这个命令用得不多)
2.6.32-1 内核模块都是ko文件
2.6.32-2 (比如把2.6.32-1的内核模块驱动源程序(未必是2.6.32-1的吧,可能是2.6.32-2)在2.6.32-2上编译,编译生成ko后拿到内核为2.6.32-1上运行,是不行的
) 内核与内核模块版本号必须要完全统一
内核中的功能,除了核心功能之外,在编译的时候,大多功能(特性)都有三种选择
1,)不使用此功能
2,)编译成内核模块
3,)编译进内核的一部分
如何手动编译内核
图形界面配置
make gconfig:Gnome桌面环境使用 还需要装图形开发工具组 (GNOME Software Development 是不是还要 GNOME Desktop Environment? )
make kconfig:KDE桌面环境使用 还需要装图形开发工具组 (KDE Software Development 是不是还要 KDE (K Desktop Environment)? )
上面这两个依赖于桌面,所以用得不是特别多
之前需要下载解压到 /usr/src 目录下,在这个目录下把linux源文件改名为 linux
1)make menuconfig (它能够打开一个文本菜单,文本环境下的图形窗口)
2)make 编译
3)make modules_install 先安装模块
4)make install 再安装内核
重启操作系统 选择新内核,,,重启(安装)的时候,会自动在grub.conf中增加title的
假如编译到一半,不小心终止了
所以编译的时候不要使用远程连接,万一远程连接中断了,编译就中止了,
还要重新从头开始编译
如果非要使用远程连接,装个工具 screen
screen命令:
screen -ls:显示已经建立的屏幕
screen:直接打开一个新的屏幕
Ctrl+a,松手d:拆除屏幕
screen -r ID:还原回某屏幕 (恢复)
exit:退出本屏幕
第二次编译的时候,应该是删除了,重新解压一下再编译,或者是清理此前的编译
二次编译的时清理,清理前,如果有需要,请备份配置文件.config:
make clean:(它好像不会清理掉.config,但最好也备份一下)清理此前编译好的二进制模块
make mrproper:(它会清理掉.config)会清理之前编译所常用的任何操作,会清理掉.config
可以只编译内核中的某一个模块,或者只编译某一个目录,编译后我们可以把编译好的文件放在另一个位置
grub-->kernel-->ROOTFS(/sbin/init,/bin/bash)
mkinitrd initrd文件路径 内核版本号
mkinitrd /boot/initrd-`uname -r`.img `uname -r`
字符串截取
${parameter#*word} /usr/local/src 这个word就是分隔符
${parameter##*word}
The word is expanded(扩展) to produce a pattern just as in pathname
expansion (膨胀). If the pattern matches the beginning of the value of
parameter, then the result of the expansion is the expanded
value of parameter with the shortest matching pattern (the ‘‘#’’
case) or the longest matching pattern (the ‘‘##’’ case) deleted.
If parameter is @ or *, the pattern removal operation is applied
to each positional parameter in turn, and the expansion is the
resultant list. If parameter is an array variable subscripted
with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant
list.
FILE=/usr/local/src
${FILE#*/}: usr/local/src
${FILE##*/}: src
${FILE%/*}: /usr/local
${FILE%%/*}: 为空,没了
${parameter%word*}
${parameter%%word*}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches a trailing portion of the
expanded value of parameter, then the result of the expansion is
the expanded value of parameter with the shortest matching pat-
tern (the ‘‘%’’ case) or the longest matching pattern (the
‘‘%%’’ case) deleted. If parameter is @ or *, the pattern
removal operation is applied to each positional parameter in
turn, and the expansion is the resultant list. If parameter is
an array variable subscripted with @ or *, the pattern removal
operation is applied to each member of the array in turn, and
the expansion is the resultant list.
2.4是稳定版
2.5是开发版(测试版)
rc是测试版,没有rc的是稳定版
[root@localhost yum.repos.d]# ls /proc
[root@localhost yum.repos.d]# ls -la /proc
[root@localhost yum.repos.d]# cd /proc/sys
[root@localhost sys]# ls -l
[root@localhost sys]# ls -l vm
swappiness 是否在多大程度上使用交换内存的伪文件
drop_caches 删除缓存的伪文件
[root@localhost sys]# free -m
[root@localhost sys]# echo 1 > /proc/sys/vm/drop_caches (drop_caches可接受0,1,2等?三个值)
就清空了缓冲和缓存 不要使用vim打开这个文件,因为它根本就不是一个文件
直接通过这种方式让内核中的某个参数,修改它的值,能够用于实现修改参数内核
[root@localhost sys]# free -m 此时一看就清掉了
[root@localhost sys]# pwd
/proc/sys
[root@localhost sys]# ls kernel/
[root@localhost sys]# cat /proc/sys/kernel/hostname (保存的是当前主机的主机名)
localhost.localdomain
[root@localhost sys]# hostname
localhost.localdomain
[root@localhost sys]# echo www.magedu.com > /proc/sys/kernel/hostname
[root@localhost sys]# hostname 此时可以看出改了
[root@localhost sys]#
[root@localhost sys]# sysctl -w kernel.hostname="mylab.magedu.com" (这种方式也可以修改)
kernel.hostname = mylab.magedu.com
[root@localhost sys]#
[root@localhost sys]# sysctl -w vm.drop_caches=1 这个同样可以改
vm.drop_caches = 1
[root@localhost sys]#
这表示是否把本地网卡作为路由器来使用的,0表示不启用,1表示启用
[root@localhost rc.d]# cat /proc/sys/net/ipv4/ip_forward
0
[root@localhost rc.d]# vim /etc/sysctl.conf
但是并没有立即生效
[root@localhost rc.d]# cat /proc/sys/net/ipv4/ip_forward
0
[root@localhost rc.d]# sysctl -p (-p会通知内核重读这个文件,或者说重新设置内核参数)
此时看到立即生效了 为 1 了
[root@localhost rc.d]# cat /proc/sys/net/ipv4/ip_forward
1
[root@localhost rc.d]#
(sysctl -a : -a 就是 all 所有)
[root@localhost rc.d]# sysctl -a | wc -l (600多个内核参数,并非每个都可以改) (不同参数所能够接受的值,类型和值的范围都是不一样的)
676
[root@localhost rc.d]#
系统调优的时候,大多数的时候都是利用这个sysctl接口来完成内核参数设定的
[root@mylab ~]# cd
[root@mylab ~]# lsmod (能够列出内核中装载的每一个模块 名称 大小 及被使用了几次,被调用了几次,被谁调用了)
dm 开头的 是与 device mapper 相关的
网卡是 pcnet32 (是vmware虚拟出来的网卡)不过我没看到 可能 64位的机器不使用pcnet32来作为网卡的模块吧
我安装了一个32的虚拟机是可以看到了 pcnet32了
# lsmod | grep pcnet32
lsmod ,modprobe ,根据模块名找模块(在/lib/module/内核版本/下面找相应的模块,或者是根据依赖文件,模块信息表查找的)
[root@mylab ~]# lsmod | grep floppy
floppy 95465 0
[root@mylab ~]# modprobe -r floppy
[root@mylab ~]# lsmod | grep floppy (卸载后,此时没有了)
[root@mylab ~]#
[root@mylab ~]# modprobe floppy
[root@mylab ~]# lsmod | grep floppy (装载进来,又看到了)
floppy 95465 0
[root@mylab ~]#
[root@mylab ~]# modinfo floppy
[root@mylab ~]# modinfo pcnet32
filename: /lib/modules/2.6.18-398.el5/kernel/drivers/net/pcnet32.ko
license: GPL
description: Driver for PCnet32 and PCnetPCI based ethercards
author: Thomas Bogendoerfer
srcversion: F81443556AAE169CBF80F55
alias: pci:v00001023d00002000sv*sd*bc02sc00i*
alias: pci:v00001022d00002000sv*sd*bc*sc*i*
alias: pci:v00001022d00002001sv*sd*bc*sc*i*
depends: mii
vermagic: 2.6.18-398.el5 SMP mod_unload gcc-4.1
parm: debug:pcnet32 debug level (int)
parm: max_interrupt_work:pcnet32 maximum events handled per interrupt (int)
parm: rx_copybreak:pcnet32 copy breakpoint for copy-only-tiny-frames (int)
parm: tx_start_pt:pcnet32 transmit start point (0-3) (int)
parm: pcnet32vlb:pcnet32 Vesa local bus (VLB) support (0/1) (int)
parm: options:pcnet32 initial option setting(s) (0-15) (array of int)
parm: full_duplex:pcnet32 full duplex setting(s) (1) (array of int)
parm: homepna:pcnet32 mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet (array of int)
module_sig: 883f35053e9eca55b93ee8bfdff79941124b109e287e123e7a8136e4ade13212fda26655a9f4e909e2a4cd35e632e2741c84ee573d5a64105619db
depends 依赖关系
[root@mylab ~]# modinfo mii
filename: /lib/modules/2.6.18-398.el5/kernel/drivers/net/mii.ko
license: GPL
description: MII hardware support library
author: Jeff Garzik <jgarzik@pobox.com>
srcversion: 16DCEDEE4B5629C222C352D
depends:
vermagic: 2.6.18-398.el5 SMP mod_unload gcc-4.1
module_sig: 883f35053e9eca65b93ee8bfdff7994112c73b09f6dd861ecccbd97a9859f9bcb7e897445a643ca0a0b1b624d9a3fb698c501735d3c0e14d7b407d9ba
mii 这里它不依赖别人
[root@mylab ~]# modprobe floppy
[root@mylab ~]# modprobe -r floppy
[root@mylab ~]# insmod floppy (insmod 不能模块名,只能文件)
insmod: can't read 'floppy': No such file or directory
[root@mylab ~]# modinfo floppy
filename: /lib/modules/2.6.18-398.el5/kernel/drivers/block/floppy.ko
alias: block-major-2-*
license: GPL
author: Alain L. Knaff
srcversion: FD25DFF73AF3AE93EB5B627
depends:
vermagic: 2.6.18-398.el5 SMP mod_unload gcc-4.1
parm: floppy:charp
parm: FLOPPY_IRQ:int
parm: FLOPPY_DMA:int
module_sig: 883f35053e9ecab5b93ee8bfdff7994112142209f5ab91061a4929ca1d578be489bc9b04014116209f6c628b523bcd470991172be30b8b54e3ccde79e
[root@mylab ~]# insmod /lib/modules/2.6.18-398.el5/kernel/drivers/block/floppy.ko
[root@mylab ~]# lsmod | grep floppy
floppy 95465 0
[root@mylab ~]# rmmod floppy
[root@mylab ~]# lsmod | grep floppy (移除模块后,模块又没有了)
[root@mylab ~]#
红帽5系列版本 不管是5.1,5.9 内核版本仍然是2.6.18
红帽6系列版本2.6.32 不管红帽6.几,它的主流版本仍然是2.6.32
目的是为了稳定和兼容
[root@mylab ~]# uname -r (-r release 释)
2.6.18-398.el5
[root@mylab ~]#
编译工具和编译环境给它装上
Development Libraries
Development Tools
看这两个组有没有装好
[root@mylab ~]# export
[root@mylab ~]# yum grouplist
马哥通过挂载本光驱来安装
下载内核
到 https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/ 下载吧
一般内核源码放在 /usr/src (src source)
[root@localhost ~]# iptables -P OUTPUT ACCEPT
[root@localhost ~]# iptables -P INPUT ACCEPT
[root@localhost ~]# wget https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/linux-2.6.28.10.tar.gz
[root@localhost ~]# tar xf linux-2.6.28.10.tar.gz -C /usr/src (-大C -C 指定解压目录(目标))
[root@localhost ~]# cd /usr/src
[root@localhost src]# ls
debug kernels linux-2.6.28.10 redhat
[root@localhost src]# ln -sv linux-2.6.28.10 linux
创建指向“linux-2.6.28.10”的符号链接“linux”
[root@localhost src]# cd linux
[root@localhost linux]# pwd
/usr/src/linux
[root@localhost linux]#
[root@localhost linux]# ls
arch crypto fs Kbuild Makefile REPORTING-BUGS sound
block Documentation include kernel mm samples usr
COPYING drivers init lib net scripts virt
CREDITS firmware ipc MAINTAINERS README security
[root@localhost linux]# ls arch/ (arch跟平台相关的,cpu架构)
alpha blackfin h8300 m32r mips powerpc sparc x86
arm cris ia64 m68k mn10300 s390 sparc64 xtensa
avr32 frv Kconfig m68knommu parisc sh um
[root@localhost linux]# pwd
/usr/src/linux
[root@localhost linux]# ls
arch crypto fs Kbuild Makefile REPORTING-BUGS sound
block Documentation include kernel mm samples usr
COPYING drivers init lib net scripts virt
CREDITS firmware ipc MAINTAINERS README security
[root@localhost linux]#
[root@localhost linux]# ls fs (文件系统)
9p compat.c freevxfs mbcache.c readdir.c
adfs compat_ioctl.c fs-writeback.c minix read_write.c
affs configfs fuse mpage.c read_write.h
afs cramfs generic_acl.c namei.c reiserfs
aio.c dcache.c gfs2 namespace.c romfs
anon_inodes.c dcookies.c hfs ncpfs select.c
attr.c debugfs hfsplus nfs seq_file.c
autofs devpts hostfs nfs_common signalfd.c
autofs4 direct-io.c hpfs nfsctl.c smbfs
bad_inode.c dlm hppfs nfsd splice.c
befs dnotify.c hugetlbfs nls stack.c
bfs dquot.c inode.c no-block.c stat.c
binfmt_aout.c drop_caches.c inotify.c ntfs super.c
binfmt_elf.c ecryptfs inotify_user.c ocfs2 sync.c
binfmt_elf_fdpic.c efs internal.h omfs sysfs
binfmt_em86.c eventfd.c ioctl.c open.c sysv
binfmt_flat.c eventpoll.c ioprio.c openpromfs timerfd.c
binfmt_misc.c exec.c isofs partitions ubifs
binfmt_script.c exportfs jbd pipe.c udf
binfmt_som.c ext2 jbd2 pnode.c ufs
bio.c ext3 jffs2 pnode.h utimes.c
bio-integrity.c ext4 jfs posix_acl.c xattr_acl.c
block_dev.c fat Kconfig proc xattr.c
buffer.c fcntl.c Kconfig.binfmt qnx4 xfs
char_dev.c fifo.c libfs.c quota.c
cifs file.c lockd quota_v1.c
coda filesystems.c locks.c quota_v2.c
compat_binfmt_elf.c file_table.c Makefile ramfs
默认红帽是不支持ntfs的,可以编译的时候加进来;可以双系统,linux此时才可以访问nfp文件
[root@localhost linux]#
[root@localhost linux]# echo $LANG
zh_CN.UTF-8
[root@localhost linux]# export LANG=en
[root@localhost linux]# yum grouplist
Failed to set locale, defaulting to C
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use su bscription-manager to register.
Setting up Group Process
file:///media/cdrom/Server/repodata/repomd.xml: [Errno 5] OSError: [Errno 2] No such file or directory: '/media/cdrom/Server/repodata/repomd.xml'
Trying other mirror.
Installed Groups:
Development Libraries
Development Tools
Editors
FTP Server
GNOME Software Development
Legacy Network Server
Legacy Software Development
Legacy Software Support
Mail Server
MySQL Database
Network Servers
Printing Support
Server Configuration Tools
System Tools
Text-based Internet
Web Server
X Software Development
Available Groups:
Administration Tools
Authoring and Publishing
DNS Name Server
Engineering and Scientific
GNOME Desktop Environment
Games and Entertainment
Graphical Internet
Graphics
Java Development
KDE (K Desktop Environment)
KDE Software Development
News Server
Office/Productivity
OpenFabrics Enterprise Distribution
PostgreSQL Database
Sound and Video
Windows File Server
X Window System
Done
一定要在内核目录下编译
[root@localhost linux]# pwd
/usr/src/linux
[root@localhost linux]# make menuconfig (窗口缩小,它就报错了)
[root@localhost ~]# uname -r (398.el5是本地版本号)
2.6.18-398.el5
[root@localhost ~]#
ESC (敲一下,还是两下) 回车上一个界面
敲空格格可以选择,多种选择进行变化
连续敲几个ESC,到最后这儿,问你是否需要保存
在内核的编译目录下,(源码目录下)此时可以看到 生成的.config文件,它是一个隐藏文件
[root@localhost linux]# pwd
/usr/src/linux
[root@localhost linux]# ls -a
. .mailmap Kbuild REPORTING-BUGS drivers init mm security
.. COPYING MAINTAINERS arch firmware ipc net sound
.config CREDITS Makefile block fs kernel samples usr
.gitignore Documentation README crypto include lib scripts virt
[root@localhost linux]#
接下来make编译 (根据上面选择的不同,大约半小时到5小时不等)
(编译到最后,启动不起来,需要某个配置,还需要重新编译)
[root@localhost linux]# make (这里ctrl+C没敢执行)
[root@localhost linux]# ls /boot/ (config-2.6.18-398.el5 这表示红帽在编译它的内核时所使用的配置)
(所以以它为模板,进行修改,出错的可能性小很多) (我们先把它复制过去为.config,然后在这个基础上进行修改)
System.map-2.6.18-398.el5 grub lost+found vmlinuz-2.6.18-398.el5
config-2.6.18-398.el5 initrd-2.6.18-398.el5.img symvers-2.6.18-398.el5.gz
[root@localhost linux]#
[root@localhost linux]# cp /boot/config-2.6.18-398.el5 /usr/src/linux/.config
cp: overwrite `/usr/src/linux/.config'? y
[root@localhost linux]# make menuconfig (这样在红帽的基础上进行修改,出错的可能性小)
红帽有些硬件驱动导致编译慢,我们可以去掉
马哥的 酷睿 Core 2/newer Xeon
如果是 AMD的 一般选择K7吧 (K6或K7) (我这连没有 K6 K7等)
我选的是跟马哥一样 酷睿 Core 2/newer Xeon
(我的64位是 e1000.ko,是不是要把 Ethernet (1000 Mbit) 选上)
最后 按几次ESC ESC (与最底部
Exit 的效果是一样的 )然后保存退出
[root@localhost linux]# mount /dev/cdrom /media/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost linux]# yum install screen
screen 能够在当前窗口中模拟好几个远程桌面,就算远程窗口它也可以模拟好几个窗口
打开一个窗口
[root@localhost ~]# screen
按住 ctrl a (add的意思)松手 d (delete detached的意思) 拆掉窗口 又回来原窗口
[root@localhost ~]# screen (再来一次)
按住 ctrl a 松手 d 拆掉窗口 又回来原窗口
[root@localhost ~]# screen (再来一次)
再拆掉
我们在第一个screen执行了 # logout
重新登录一个窗口
[root@localhost ~]# screen -ls (可以列出此前打开的 screen窗口)
[root@localhost ~]# screen -r 13080 ( -r restore 还原)
ctrl+a, 松手d 拆掉窗口 (exit是退出窗口,窗口就没有了)
[root@localhost ~]# screen -r 13122
[root@localhost ~]# exit (exit是退出窗口,窗口就没有了)(在分屏 screen 上 ctrl+s是终止,好像是终止了所有)
13122 就没有了
[root@localhost ~]# screen -r 13100 (ctrl+s是终止,窗口还在,但是无法敲字执行命令了)
创建 20M (为了boot)和512M(为了根)的分区
分区
[root@localhost ~]# fdisk /dev/hda
[root@localhost ~]# partprobe /dev/hda
[root@localhost ~]#
[root@localhost ~]# mke2fs -j /dev/hda1
[root@localhost ~]# mkdir /mnt/{boot,sysroot}
挂载
[root@localhost ~]# mount
/dev/mapper/VolGroup00-LogVol00 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)
.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/cdrom type iso9660 (ro)
/dev/hda1 on /mnt/boot type ext3 (rw)
/dev/hda2 on /mnt/sysroot type ext3 (rw)
装grub --root-directory指定boot的父目录 /dev/hda指定装在哪个磁盘上
[root@localhost ~]# grub-install --root-directory=/mnt /dev/hda
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mnt/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/sda
(hd2) /dev/sdb
[root@localhost ~]#
grub lost+found
[root@localhost ~]# cp /boot/vmlinuz-2.6.18-398.el5 /mnt/boot/vmlinuz
其实不能拿来用,因为根不一样 我们的根在 /dev/hda2上 ,所以不能拿来直接用,需要改一改
[root@localhost ~]# mount
/dev/mapper/VolGroup00-LogVol00 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)
.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/cdrom type iso9660 (ro)
/dev/hda1 on /mnt/boot type ext3 (rw)
/dev/hda2 on /mnt/sysroot type ext3 (rw)
[root@localhost ~]#
[root@localhost ~]# mkdir test
[root@localhost ~]# cd test
[root@localhost test]# pwd
/root/test
[root@localhost test]#
下面的命令表示 把 cpio文件展开到当前的目录下
cpio -i, --extract 进入 copy-in 模式,也就是 解压。解压进来
-o, --create 进入 copy-out 模式。压缩 , 归档出去
-d, --make-directories 在需要的地方创建开始目录。
[root@localhost test]#
另一种方法
[root@localhost ~]# mkdir iso
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd iso
[root@localhost iso]# pwd
/root/iso
[root@localhost iso]#
通过 zcat 压缩文件 通过管道 送给cpio -id 到当前目录下 (所以要创建空目录,然后展开进来)
18539 blocks
[root@localhost iso]# ls
bin dev etc init lib proc sbin sys sysroot
[root@localhost iso]#
[root@localhost iso]# vim init (如果有swap还是注释掉,因为我们这里没有swap
)
[root@localhost iso]# ls
bin dev etc init lib proc sbin sys sysroot
(find . 后面没有东西,表示所有文件 )
cpio -H newc 表示类型 --quiet 表示静默模式(--quiet 不显示复制的块数。 ) -o (--create 进入 copy-out 模式。)表示归档出去
gzip -9 是一种高度压缩模式
> 表示输出重定向
[root@localhost iso]# find . | cpio -H newc --quiet -o | gzip -9 > /mnt/boot/initrd.gz
[root@localhost iso]# cd /mnt/boot/
[root@localhost boot]# ls -lh
总计 5.6M
drwxr-xr-x 2 root root 1.0K 11-09 08:51 grub
-rw-r--r-- 1 root root 3.5M 11-09 09:46 initrd.gz (3.几M,可以精简到1M左右)
drwx------ 2 root root 12K 11-09 08:50 lost+found
-rw-r--r-- 1 root root 2.1M 11-09 09:58 vmlinuz
[root@localhost boot]#
内核有了 initrd 有了 还差grub.conf
[root@localhost boot]# vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title Test Linux (Magedu Team)
root (hd0,0)
kernel /vmlinuz
initrd /initrd.gz
现在到真正的根文件系统
[root@localhost boot]# cd /mnt/sysroot/
[root@localhost sysroot]# ls
lost+found
[root@localhost sysroot]#
[root@localhost sysroot]#
这里应该 复制一下下面两个命令吧
[root@localhost sysroot]# cp /bin/bash /mnt/sysroot/bin/
[root@localhost sysroot]# cp /sbin/init /mnt/sysroot/sbin/
看 /sbin/init依赖哪些库
[root@localhost sysroot]# ldd /sbin/init
linux-vdso.so.1 => (0x00007fff52762000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x00000034e0200000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00000034e0600000)
libc.so.6 => /lib64/libc.so.6 (0x00000034dea00000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000034dee00000)
/lib64/ld-linux-x86-64.so.2 (0x00000034de600000)
[root@localhost sysroot]#
复制下 /sbin/init 依赖的库 文件
再看/bin/bash依赖的库 ldd:List dynamic dependencies 列出动态依赖
[root@localhost sysroot]# ldd /bin/bash
linux-vdso.so.1 => (0x00007fffcc3fc000)
libtermcap.so.2 => /lib64/libtermcap.so.2 (0x0000003a3b800000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000034dee00000)
libc.so.6 => /lib64/libc.so.6 (0x00000034dea00000)
/lib64/ld-linux-x86-64.so.2 (0x00000034de600000)
[root@localhost sysroot]#
还剩下 libtermcap.so.2 => /lib64/libtermcap.so.2 (0x0000003a3b800000) 没复制
[root@localhost sysroot]# cp /lib64/libtermcap.so.2 /mnt/sysroot/lib64/
[root@localhost sysroot]# cd
[root@localhost ~]# pwd
/root
没有问题了就sync
[root@localhost ~]# sync
[root@localhost ~]# cd /mnt/sysroot/
[root@localhost sysroot]#
init 要执行,就必须要使用 /etc/inittab文件
[root@localhost sysroot]# pwd
/mnt/sysroot
[root@localhost sysroot]# ls
bin dev home lib64 proc sbin tmp var
boot etc lib lost+found root sys usr
[root@localhost sysroot]# tree etc
etc
`-- rc.d
1 directory, 0 files
[root@localhost sysroot]#
[root@localhost sysroot]# ls
bin dev home lib64 proc sbin tmp var
boot etc lib lost+found root sys usr
[root@localhost sysroot]#
rc.sysinit 脚本还没有
[root@localhost sysroot]# vim etc/rc.d/rc.sysinit
#!/bin/bash
#
echo -e "\tWelcome to \033[31mMageEdu Team\033[0m Linux"
/bin/bash
~
[root@localhost sysroot]# chmod +x etc/rc.d/rc.sysinit
一定要做一下sync
[root@localhost sysroot]# sync
[root@localhost sysroot]# sync
[root@localhost sysroot]# sync
[root@localhost sysroot]# cd
创建一个新的虚拟机
启动这个刚创建的虚拟机
红帽初始化的时候有一大堆信息
是 bootloader 完成内核装载并实现内核初始化的信息
这些信息是 initrd的信息? (是的,还是不是的 ,听不清马哥的话)
你只需要 加个 quiet , 就没有了
关闭这个新的自己创建的虚拟机
启动原虚拟机
[root@localhost ~]# ls
100.sh linux-2.6.28.10.tar.gz
aaa.txt nano-1.3.12-1.1.x86_64.rpm
aa.txt php-mysql-5.1.6-44.el5_10.x86_64.rpm
account set nu
anaconda-ks.cfg test
bb.txt test1.txt
cdr test2.txt
checkhadoop2.sh test3.txt
checkhadoop.sh testequatl.sh
et: test.sh
httpd-devel-2.2.3-91.el5.x86_64.rpm test.txt
initrd-2.6.18-398.el5.img text.txt
install.log util.sh
install.log.syslog while.sh
iso zsh-4.2.6-9.el5.x86_64.rpm
[root@localhost ~]#
假如 复制的目的地目录不存在,怎么办
比如
[root@localhost ~]# which vim
/usr/bin/vim
[root@localhost ~]#
还有 命令别名
[root@localhost ~]# which ls
alias ls='ls --color=tty'
/bin/ls
[root@localhost ~]#
[root@localhost ~]# man bash
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches the beginning of the value of
parameter, then the result of the expansion is the expanded
value of parameter with the shortest matching pattern (the ‘‘#’’
case) or the longest matching pattern (the ‘‘##’’ case) deleted.
If parameter is @ or *, the pattern removal operation is applied
to each positional parameter in turn, and the expansion is the
resultant list. If parameter is an array variable subscripted
with @ or *, the pattern removal operation is applied to each
member of the array in turn, and the expansion is the resultant
list.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches a trailing portion of the
expanded value of parameter, then the result of the expansion is
the expanded value of parameter with the shortest matching pat-
tern (the ‘‘%’’ case) or the longest matching pattern (the
‘‘%%’’ case) deleted. If parameter is @ or *, the pattern
removal operation is applied to each positional parameter in
turn, and the expansion is the resultant list. If parameter is
an array variable subscripted with @ or *, the pattern removal
operation is applied to each member of the array in turn, and
the expansion is the resultant list.
[root@localhost ~]# FILE=/usr/local/src
[root@localhost ~]# echo ${FILE#/}
usr/local/src
[root@localhost ~]# echo ${FILE##/}
usr/local/src
[root@localhost ~]# echo ${FILE##*/}
src
[root@localhost ~]# echo ${FILE#*/}
usr/local/src
[root@localhost ~]#
如果使用一个井号 # ,从左向右, 第一个分隔符 */左边的内容都去掉
如果使用两个井号 ##,从左向右, 最后一个分隔符 */左边的内容都去掉
[root@localhost ~]# echo ${FILE%/*}
/usr/local
[root@localhost ~]# echo ${FILE%%/*}
[root@localhost ~]#
[root@localhost ~]# FILE=hello/usr/local/src
[root@localhost ~]# echo ${FILE%%/*}
hello
[root@localhost ~]#
如果使用一个百分号 % ,从右向左, 第一个分隔符 /*右边的内容都去掉
如果使用两个百分 %,从右向左, 最后一个分隔符 /*右边的内容都去掉
[root@localhost ~]# FILE=/usr/local/src
[root@localhost ~]# echo ${FILE%/*} (取得一个路径的目录)
/usr/local
[root@localhost ~]#
如果 没有/mnt/sysroot/usr/lib/这个目录,就创建它
[root@localhost ~]# cp /usr/lib/a.so /mnt/sysroot/usr/lib/a.so
[root@localhost ~]# ldd /bin/ls
linux-vdso.so.1 => (0x00007fff3b1fd000)
librt.so.1 => /lib64/librt.so.1 (0x00000034dfe00000)
libacl.so.1 => /lib64/libacl.so.1 (0x00000034e0a00000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00000034e0600000)
libc.so.6 => /lib64/libc.so.6 (0x00000034dea00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000034df600000)
/lib64/ld-linux-x86-64.so.2 (0x00000034de600000)
libattr.so.1 => /lib64/libattr.so.1 (0x00000034dfa00000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000034dee00000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x00000034e0200000)
[root@localhost ~]#
[root@localhost ~]# vim bincopy.sh
#!/bin/bash
#
DEST=/mnt/sysroot
libcp() {
LIBPATH=${1%/*}
[ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH
cp $1 $DEST$LIBPATH
}
libcp /lib64/librt.so.1
[root@localhost ~]# chmod +x bincopy.sh (用bash来执行的话,这一步执不执行无所谓了)
[root@localhost ~]# bash -x bincopy.sh
+ DEST=/mnt/sysroot
+ libcp /lib64/librt.so.1
+ LIBPATH=/lib64
+ '[' '!' -d /mnt/sysroot/lib64 ']'
+ cp /lib64/librt.so.1 /mnt/sysroot/lib64
[root@localhost ~]# ldd /usr/bin/vim
linux-vdso.so.1 => (0x00007fffc7bfd000)
libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x00000034e1200000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00000034e0600000)
libacl.so.1 => /lib64/libacl.so.1 (0x00000034e0a00000)
libgpm.so.1 => /usr/lib64/libgpm.so.1 (0x00000034dfe00000)
libperl.so => /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so (0x00000034e0e00000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00000034e3e00000)
libutil.so.1 => /lib64/libutil.so.1 (0x00000034e8e00000)
libc.so.6 => /lib64/libc.so.6 (0x00000034dea00000)
libm.so.6 => /lib64/libm.so.6 (0x00000034df200000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000034dee00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000034df600000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x00000034e0200000)
/lib64/ld-linux-x86-64.so.2 (0x00000034de600000)
libattr.so.1 => /lib64/libattr.so.1 (0x00000034dfa00000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00000034e1a00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000034e2600000)
[root@localhost ~]#
[root@localhost ~]# vim bincopy.sh
#!/bin/bash
#
DEST=/mnt/sysroot
libcp() {
LIBPATH=${1%/*}
[ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH
cp $1 $DEST$LIBPATH
}
#libcp /lib64/librt.so.1
libcp /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so
[root@localhost ~]# bash -x bincopy.sh
+ DEST=/mnt/sysroot
+ libcp /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so
+ LIBPATH=/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE
+ '[' '!' -d /mnt/sysroot/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE ']'
+ mkdir -p /mnt/sysroot/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE
+ cp /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so /mnt/sysroot/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE
[root@localhost ~]#
[root@localhost ~]# vim bincopy.sh
[root@localhost ~]# ldd /bin/ls (看看库文件要复制的是哪一段)
linux-vdso.so.1 => (0x00007ffffaf8d000)
librt.so.1 => /lib64/librt.so.1 (0x00000034dfe00000)
libacl.so.1 => /lib64/libacl.so.1 (0x00000034e0a00000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00000034e0600000)
libc.so.6 => /lib64/libc.so.6 (0x00000034dea00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000034df600000)
/lib64/ld-linux-x86-64.so.2 (0x00000034de600000)
libattr.so.1 => /lib64/libattr.so.1 (0x00000034dfa00000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000034dee00000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x00000034e0200000)
[root@localhost ~]#
[root@localhost ~]# ldd /usr/bin/vim
linux-vdso.so.1 => (0x00007fff71ffd000)
libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x00000034e1200000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00000034e0600000)
libacl.so.1 => /lib64/libacl.so.1 (0x00000034e0a00000)
libgpm.so.1 => /usr/lib64/libgpm.so.1 (0x00000034dfe00000)
libperl.so => /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so (0x00000034e0e00000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00000034e3e00000)
libutil.so.1 => /lib64/libutil.so.1 (0x00000034e8e00000)
libc.so.6 => /lib64/libc.so.6 (0x00000034dea00000)
libm.so.6 => /lib64/libm.so.6 (0x00000034df200000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000034dee00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000034df600000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x00000034e0200000)
/lib64/ld-linux-x86-64.so.2 (0x00000034de600000)
libattr.so.1 => /lib64/libattr.so.1 (0x00000034dfa00000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00000034e1a00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00000034e2600000)
[root@localhost ~]#
grep -o (-o only)只显示匹配到的内容,不显示整行内容
{ 大括号花括号前面要加反斜杠 正则要使用引号(单引号或双引号)引起来
[:space:] 表示空格
{0,1}表示0个或一个, {0,}表示0个或多个
[root@localhost ~]# ldd /usr/bin/vim | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{0,\}"
/usr/lib64/libncurses.so.5
/lib64/libselinux.so.1
/lib64/libacl.so.1
/usr/lib64/libgpm.so.1
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so
/lib64/libresolv.so.2
/lib64/libutil.so.1
/lib64/libc.so.6
/lib64/libm.so.6
/lib64/libdl.so.2
/lib64/libpthread.so.0
/lib64/libsepol.so.1
/lib64/ld-linux-x86-64.so.2
/lib64/libattr.so.1
/lib64/libnsl.so.1
/lib64/libcrypt.so.1
[root@localhost ~]#
把这个列表保存下来用for对它循环,每循环一次调用函数就可以了
[root@localhost ~]# vim bincopy.sh
#!/bin/bash
#
DEST=/mnt/sysroot
libcp() {
LIBPATH=${1%/*}
[ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH
[ ! -e $DEST${1} ] && cp $1 $DEST$LIBPATH
}
bincp() {
CMDPATH=${1%/*}
[ ! -d $DEST$CMDPATH ] && mkdir -p $DEST$CMDPATH
[ ! -e $DEST${1} ] && cp $1 $DEST$CMDPATH
for LIB in `ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{0,\}"`; do
libcp $LIB
done
}
bincp /bin/ls
[root@localhost ~]# bash -x bincopy.sh
可以执行的
测试一下 看ls命令到底能不能执行
[root@localhost ~]# chroot /mnt/sysroot/
bash-3.2# ls
bin dev home lib64 proc sbin tmp var
boot etc lib lost+found root sys usr
bash-3.2# exit
exit
[root@localhost ~]#
命令别名的情况处理一下
[root@localhost ~]# which ls
alias ls='ls --color=tty'
/bin/ls
[root@localhost ~]#
[root@localhost ~]# which ls | grep -v "^alias"
/bin/ls
[root@localhost ~]#
[root@localhost ~]# which ls | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"
/bin/ls
[root@localhost ~]#
[root@localhost ~]# which rm | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"
/bin/rm
[root@localhost ~]# vim bincopy.sh
#!/bin/bash
#
DEST=/mnt/sysroot
libcp() {
LIBPATH=${1%/*}
[ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH
[ ! -e $DEST${1} ] && cp $1 $DEST$LIBPATH
}
bincp() {
CMDPATH=${1%/*}
[ ! -d $DEST$CMDPATH ] && mkdir -p $DEST$CMDPATH
[ ! -e $DEST${1} ] && cp $1 $DEST$CMDPATH
for LIB in `ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{0,\}"`; do
libcp $LIB
done
}
read -p "Your command:" CMD
until [ $CMD == 'q' ];do
! which $CMD && echo "Wrong command" && read -p "Input again:" CMD && continue
COMMAND=`which $CMD | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"`
bincp $COMMAND
echo "copy $COMMAND finished."
read -p "Continue:" CMD
done
[root@localhost ~]# chmod +x bincopy.sh
[root@localhost ~]# ./bincopy.sh
Your command:mkdir
/bin/mkdir
copy /bin/mkdir finished.
Continue:rm
/bin/rm
copy /bin/rm finished.
Continue:mount
/bin/mount
copy /bin/mount finished.
Continue:q
[root@localhost ~]#
[root@localhost ~]# vim bincopy.sh
#!/bin/bash
#
DEST=/mnt/sysroot
libcp() {
LIBPATH=${1%/*}
[ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH
[ ! -e $DEST${1} ] && cp $1 $DEST$LIBPATH && echo "copy lib $1 finished."
}
bincp() {
CMDPATH=${1%/*}
[ ! -d $DEST$CMDPATH ] && mkdir -p $DEST$CMDPATH
[ ! -e $DEST${1} ] && cp $1 $DEST$CMDPATH
for LIB in `ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{0,\}"`; do
libcp $LIB
done
}
read -p "Your command:" CMD
until [ $CMD == 'q' ];do
! which $CMD && echo "Wrong command" && read -p "Input again:" CMD && continue
COMMAND=`which $CMD | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"`
bincp $COMMAND
echo "copy $COMMAND finished."
read -p "Continue:" CMD
done
[root@localhost ~]# ./bincopy.sh
Your command:runlevel
/sbin/runlevel
copy /sbin/runlevel finished.
Continue:vim
/usr/bin/vim
copy lib /usr/lib64/libncurses.so.5 finished.
copy lib /usr/lib64/libgpm.so.1 finished.
copy lib /lib64/libresolv.so.2 finished.
copy lib /lib64/libutil.so.1 finished.
copy lib /lib64/libm.so.6 finished.
copy lib /lib64/libnsl.so.1 finished.
copy lib /lib64/libcrypt.so.1 finished.
copy /usr/bin/vim finished.
Continue:q
[root@localhost ~]#
把 ping ifconfig insmod rmmod modprobe halt reboot rm mv chmod chown sync 这些命令复制一下吧
(马哥好像说 halt reboot 加上去也不起作用,还需要做其它的事才能起作用)
为什么马哥老是执行几个sync呢 (在约是为了在两个虚拟机之间切换吧 防止数据没有写到硬盘上)
[root@localhost ~]# sync
[root@localhost ~]# sync
[root@localhost ~]# sync
[root@localhost ~]# sync
[root@localhost ~]#
[root@localhost ~]# chroot /mnt/sysroot/
bash-3.2# ls
bin dev home lib64 proc sbin tmp var
boot etc lib lost+found root sys usr
bash-3.2# cd /etc
bash-3.2# pwd
/etc
bash-3.2# ls
inittab rc.d
bash-3.2# cd rc.d
bash-3.2# chmod +x rc.sysinit
bash-3.2# ls
rc.sysinit
bash-3.2# ls -la
total 3
drwxr-xr-x 2 0 0 1024 Nov 9 02:56 .
drwxr-xr-x 3 0 0 1024 Nov 9 02:44 ..
-rwxr-xr-x 1 0 0 81 Nov 9 02:56 rc.sysinit
bash-3.2# exit
exit
[root@localhost ~]#
[root@localhost ~]# mkdir /mnt/sysroot/lib/modules
[root@localhost ~]# mkdir /mnt/sysroot/lib64/modules
[root@localhost ~]#
红帽5 32位为了上网,需要pcnet32.ko模块,pcnet32.ko又依赖于mii.ko
红帽5 64位上网仅仅是需要e1000.ko
[root@localhost ~]# cat /etc/modprobe.conf (看看这个文件吧)
alias eth0 e1000
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix
alias snd-card-0 snd-ens1371
options snd-card-0 index=0
options snd-ens1371 index=0
remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-ens1371
[root@localhost ~]#
[root@localhost ~]# modinfo mii
filename: /lib/modules/2.6.18-398.el5/kernel/drivers/net/mii.ko
license: GPL
description: MII hardware support library
author: Jeff Garzik <jgarzik@pobox.com>
srcversion: 16DCEDEE4B5629C222C352D
depends:
vermagic: 2.6.18-398.el5 SMP mod_unload gcc-4.1
module_sig: 883f35053e9eca65b93ee8bfdff7994112c73b09f6dd861ecccbd97a9859f9bcb7e897445a643ca0a0b1b624d9a3fb698c501735d3c0e14d7b407d9ba
[root@localhost ~]# modinfo pcnet32
filename: /lib/modules/2.6.18-398.el5/kernel/drivers/net/pcnet32.ko
license: GPL
description: Driver for PCnet32 and PCnetPCI based ethercards
author: Thomas Bogendoerfer
srcversion: F81443556AAE169CBF80F55
alias: pci:v00001023d00002000sv*sd*bc02sc00i*
alias: pci:v00001022d00002000sv*sd*bc*sc*i*
alias: pci:v00001022d00002001sv*sd*bc*sc*i*
depends: mii
vermagic: 2.6.18-398.el5 SMP mod_unload gcc-4.1
parm: debug:pcnet32 debug level (int)
parm: max_interrupt_work:pcnet32 maximum events handled per interrupt (int)
parm: rx_copybreak:pcnet32 copy breakpoint for copy-only-tiny-frames (int)
parm: tx_start_pt:pcnet32 transmit start point (0-3) (int)
parm: pcnet32vlb:pcnet32 Vesa local bus (VLB) support (0/1) (int)
parm: options:pcnet32 initial option setting(s) (0-15) (array of int)
parm: full_duplex:pcnet32 full duplex setting(s) (1) (array of int)
parm: homepna:pcnet32 mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet (array of int)
module_sig: 883f35053e9eca55b93ee8bfdff79941124b109e287e123e7a8136e4ade13212fda26655a9f4e909e2a4cd35e632e2741c84ee573d5a64105619db
[root@localhost ~]#
[root@localhost ~]# cp /lib/modules/2.6.18-398.el5/kernel/drivers/net/mii.ko /mnt/sysroot/lib/modules/
[root@localhost ~]# cp /lib/modules/2.6.18-398.el5/kernel/drivers/net/pcnet32.ko /mnt/sysroot/lib/modules/
[root@localhost ~]#
我的需要复制到 lib64的modules目录下吗?复制一下吧
[root@localhost ~]# cp /lib64/modules/2.6.18-398.el5/kernel/drivers/net/mii.ko /mnt/sysroot/lib64/modules/
[root@localhost ~]# cp /lib64/modules/2.6.18-398.el5/kernel/drivers/net/pcnet32.ko /mnt/sysroot/lib64/modules/
[root@localhost ~]#
我的64位,其网卡模块是e1000.ko 不是 pcnet32.ko (只有32位才是pcnet32.ko)
因为上面mii.ko和pcne32.ko不需要复制,只需要复制 /lib/modules/2.6.18-398.el5/kernel/drivers/net/e1000/e1000.ko
即
[root@mylab ~]# cp /lib/modules/2.6.18-398.el5/kernel/drivers/net/e1000/e1000.ko /mnt/sysroot/lib/modules/
我们期望系统开机时 能自动装载这两个模块,装载完后还能够给系统配置ip地址,我们启动时有ip地址,还能ping通别人
[root@localhost ~]# ./bincopy.sh
Your command:lsmod
/sbin/lsmod
copy /sbin/lsmod finished.
Continue:q
[root@localhost ~]# cd /mnt/sysroot/
32位红帽5的 rc.sysinit
[root@localhost sysroot]# vim etc/rc.d/rc.sysinit
#!/bin/bash
#
echo -e "\tWelcome to \033[31mMageEdu Team\033[0m Linux"
insmod /lib/modules/mii.ko
insmod /lib/modules/pcnet32.ko # pcnet32.ko 应该是依赖于mii.ko
ifconfig eth0 192.168.1.19/24
ifconfig lo 127.0.0.1/8
/bin/bash
64位红帽5的 rc.sysinit
[root@localhost sysroot]# vim etc/rc.d/rc.sysinit
#!/bin/bash
#
echo -e "\tWelcome to \033[31mMageEdu Team\033[0m Linux"
insmod /lib/modules/e1000.ko #e1000.ko,应该是不依赖于mii.ko
ifconfig eth0 192.168.1.19/24
ifconfig lo 127.0.0.1/8
/bin/bash
[root@localhost sysroot]# sync
[root@localhost sysroot]# sync
[root@localhost sysroot]# cd
[root@localhost ~]#
然后,挂起本linux,打开新的自己创建的linux
下面几个图是马哥的
下面的图是我的 64位 (如果使用了 32位的mii.ko 和 pcnet32.ko会报下面的错)
我的 64位 使用了 e1000.ko这个网卡,就会正常了,ifconfig可以看到eth0,ping 可以ping通 如下面几个图所示