寻觅生命中的那一片浅草......

文章属于类别 Linux

将阵列卡驱动编辑进initrd.img

CentOS5.4无法识别五舟服务器的阵列卡,每次安装都要手动加载,十分麻烦

今天突发奇想,要把驱动加到安装光盘里,找到这篇文章,太给力了

以下为转载内容

原文见:http://hi.baidu.com/delovery/blog/item/b55c317aa1b329e12e73b33c.html/cmtid/c15bb909a772bc2a6b60fb00

[root@localhost test]# ls
initrd.img rh5.2img.zip
[root@localhost test]# file initrd.img
initrd.img: gzip compressed data, from Unix, last modified: Tue Jun 24 00:53:16 2008, max compression
[root@localhost test]# mv initrd.img initrd.img.gz
[root@localhost test]# ls
initrd.img.gz rh5.2img.zip
[root@localhost test]# gunzip initrd.img.gz
[root@localhost test]# ls
initrd.img rh5.2img.zip
[root@localhost test]# file initrd.img
initrd.img: ASCII cpio archive (SVR4 with no CRC)
[root@localhost test]# mkdir a
[root@localhost test]# ls
a initrd.img rh5.2img.zip
[root@localhost test]# cd a
[root@localhost a]# cpio -dumi < ../initrd.img
14988 blocks
[root@localhost a]# ls
bin dev etc init modules proc sbin selinux sys tmp var
[root@localhost a]# cd modules/
[root@localhost modules]# ls -l
total 4520
-rw-r–r– 1 root root 5791 Jun 24 2008 module-info
-rw-r–r– 1 root root 117885 Jun 24 2008 modules.alias
-rw-r–r– 1 root root 4396775 Jun 24 2008 modules.cgz
-rw-r–r– 1 root root 13152 Jun 24 2008 modules.dep
-rw-r–r– 1 root root 62055 Jun 24 2008 pci.ids
[root@localhost modules]# file modules.cgz
modules.cgz: gzip compressed data, from Unix, last modified: Tue Jun 24 00:53:05 2008, max compression
[root@localhost modules]# cat modules.dep
cciss: scsi_mod
aic94xx: libsas libata scsi_transport_sas scsi_mod
libsas: libata scsi_transport_sas scsi_mod
mptsas: mptscsih mptbase scsi_transport_sas scsi_mod
scsi_transport_sas: scsi_mod
orinoco_plx: orinoco hermes
dm-emc: dm-multipath dm-mod
……………………………..
[root@localhost modules]# mv modules.cgz modules.cgz.gz
[root@localhost modules]# ls
module-info modules.alias modules.cgz.gz modules.dep pci.ids
[root@localhost modules]# gunzip modules.cgz.gz
[root@localhost modules]# ls -lh modules.cgz
-rw-r–r– 1 root root 18M Jun 24 2008 modules.cgz
[root@localhost modules]# cpio -i –verbose –make-directories < modules.cgz
2.6.18-92.el5/x86_64/cciss.ko
2.6.18-92.el5/x86_64/scsi_transport_sas.ko
2.6.18-92.el5/x86_64/orinoco_plx.ko
2.6.18-92.el5/x86_64/dm-multipath.ko
2.6.18-92.el5/x86_64/sundance.ko
2.6.18-92.el5/x86_64/rtl8150.ko
2.6.18-92.el5/x86_64/lock_nolock.ko
2.6.18-92.el5/x86_64/raid1.ko
2.6.18-92.el5/x86_64/vga16fb.ko
……………………………………….
[root@localhost modules]# cd 2.6.18-92.el5/x86_64
[root@localhost x86_64]# ls
3c574_cs.ko dm-zero.ko mptspi.ko sata_via.ko
3c589_cs.ko e1000e.ko msdos.ko sata_vsc.ko
3c59x.ko e1000.ko natsemi.ko scsi_mod.ko
3w-9xxx.ko e100.ko ne2k-pci.ko scsi_transport_fc.ko
3w-xxxx.ko edd.ko netwave_cs.ko scsi_transport_iscsi.ko
8139cp.ko ehci-hcd.ko netxen_nic.ko scsi_tra
……………………….
[root@localhost modules]#cd /test
[root@localhost test]# ls
a initrd.img rh5.2img.zip
[root@localhost test]# unzip rh5.2img.zip
Archive: rh5.2img.zip
creating: rh5.2img/
extracting: rh5.2img/disk-info
inflating: rh5.2img/modinfo
inflating: rh5.2img/modules.alias
inflating: rh5.2img/modules.cgz
extracting: rh5.2img/modules.dep
inflating: rh5.2img/modules.pcimap
inflating: rh5.2img/pci.ids
inflating: rh5.2img/pcitable
inflating: rh5.2img/replace_ahci.sh
inflating: rh5.2img/replace_ahci_readme.txt
extracting: rh5.2img/rhdd
[root@localhost test]# cd rh5.2img
[root@localhost rh5.2img]# ls
disk-info modules.alias modules.dep pci.ids replace_ahci_readme.txt rhdd
modinfo modules.cgz modules.pcimap pcitable replace_ahci.sh
[root@localhost rh5.2img]# more pcitable
0x8086 0x2682 “megasr” “MegaSR|INTEL-ESB2”
0x8086 0x2683 “megasr” “MegaSR|INTEL-ESB2”
0x8086 0x27C3 “megasr” “MegaSR|INTEL-ICH7R”
0x8086 0x2925 “megasr” “MegaSR|LSI-NEC”
0x8086 0x3A25 “megasr” “MegaSR|LSI-ICH10R”
0x1000 0x0055 “megasr” “MegaSR|LSI-1068”
0x1000 0x0057 “megasr” “MegaSR|LSI-1064E”
0x1000 0x0059 “megasr” “MegaSR|LSI-1068E”
[root@localhost rh5.2img]# mv modules.cgz modules.cgz.gz
[root@localhost rh5.2img]# ls
disk-info modules.alias modules.dep pci.ids replace_ahci_readme.txt rhdd
modinfo modules.cgz.gz modules.pcimap pcitable replace_ahci.sh
[root@localhost rh5.2img]# gunzip modules.cgz.gz
[root@localhost rh5.2img]# ls
disk-info modules.alias modules.dep pci.ids replace_ahci_readme.txt rhdd
modinfo modules.cgz modules.pcimap pcitable replace_ahci.sh
[root@localhost rh5.2img]# file modules.cgz
modules.cgz: ASCII cpio archive (SVR4 with CRC)
[root@localhost rh5.2img]# cpio -i –verbose –make-directories < modules.cgz
2.6.18-92.el5xen/x86_64/megasr.ko
2.6.18-92.el5/x86_64/megasr.ko
2.6.18-92.el5xen/i686/megasr.ko
2.6.18-92.el5PAE/i686/megasr.ko
2.6.18-92.el5/i686/megasr.ko
6214 blocks
[root@localhost rh5.2img]# ls
2.6.18-92.el5 modinfo modules.pcimap replace_ahci.sh
2.6.18-92.el5PAE modules.alias pci.ids rhdd
2.6.18-92.el5xen modules.cgz pcitable
disk-info modules.dep replace_ahci_readme.txt
[root@localhost rh5.2img]# cd 2.6.18-92.el5
[root@localhost 2.6.18-92.el5]# ls
i686 x86_64
[root@localhost 2.6.18-92.el5]# cd x86_64/
[root@localhost x86_64]# ls
megasr.ko
[root@localhost x86_64]#cp megasr.ko /test/a/modules/2.6.18-92.el5/x86_64/
下面我们要修改/test/a/modules下的:pci.ids modules.alias modules.info
[root@localhost modules]# vi cpi.ids
[root@localhost modules]#vi modules.alias
在上述文件中加入rh5.2img中cpi.ids和modules.alias modinfo中的内容追加在后面
[root@localhost modules]# ls
2.6.18-92.el5 module-info modules.alias modules.cgz modules.dep pci.ids
[root@localhost modules]# rm -rf modules.cgz
[root@localhost modules]# find 2.6.18-92.el5/ |cpio -H newc -ov |gzip -9 -c – > modules.cgz
[root@localhost modules]# cd ..
[root@localhost a]# ls
bin dev etc init modules proc sbin selinux sys tmp var
[root@localhost a]#find . |cpio -H newc -ov |gzip -9 -c – > /test/b/initrd.img
[root@localhost a]#cd ..
[root@localhost test]# cd b
[root@localhost b]# ls
initrd.img
[root@localhost b]# file initrd.img
initrd.img: gzip compressed data, from Unix, last modified: Sun Sep 13 20:22:37 2009, max compression
到此完成操作,试验结果,待绪

另外有一篇文章也值得一读

http://www.torkwrench.com/2010/01/06/installing-rhel-5-using-the-vmware-paravirtualized-scsi-driver-pvscsi/

用grub4dos制作启动U盘

通过本文制作出来的U盘,实现以下系统的启动
1、 Ubuntu_10.10-x86_64_Live,并可以保存系统修改后的配置
2、 小马PE101010—功能非常齐全
3、 CDlinux社区标准版+无线破解
4、 Ubuntu_10.10_64_fast,能快速启动,但配置不能保存,这里主要演示下grub4dos可以直接挂载iso文件

4GU盘一个,越大越好,我的是:
Verbatim STORE N GO 4G

用到的软件
BOOTICE –用于安装grub4dos

Linux下的操作
为使Ubuntu系统的配置能够保存,我们需要创建一个卷标为casper-rw的分区
登录进Linux系统,对U盘进行分区,这里我创建了一个1G的分区用于保存Ubuntu系统的配置,分区的大小,主要是看你要安装的软件和保存文件的大小,空间越大,能够保存的配置就越多,我主要是安装了中文语言文件和一个浏览器。

这里,我的系统识别到U盘是/dev/sdb

fdisk /dev/sdb
如何分区,可以Google下,有个小提示是,fdisk分区时,是根据柱面来分的,1个柱面约等于8M的空间

格式化/dev/sdb2
mkfs.ext2 /dev/sdb2

设置/dev/sdb2的卷标
e2label /dev/sdb2 casper-rw

Windows下的操作
打开BOOTICE,选择U盘

这里有2种引导记录
主引导记录—针对只有1个分区的U盘或者移动硬盘
分区引导记录—针对有几个分区的U盘或者移动硬盘
由于我们对U盘进行了分区,所以,这里选择“分区引导记录”

选择第一个分区,默认选的就是 GRUB4DOS,点击“安装/配置”
弹出的对话框,直接点击“确定”即可

这时,U盘就是可启动的了
编写启动菜单文件menu.lst, 并放到U盘根目录,注意,kernel哪里都是一行的

timeout 30
default 0
gfxmenu /BOOT/message
title [01] Ubuntu_10.10-x86_64_Live
find –set-root /casper/vmlinuz
kernel /casper/vmlinuz boot=casper persistent file=/preseed/ubuntu.seed looptype=squashfs loop=/casper/filesystem.squashfs
initrd /casper/initrd.lz
title [02] 小马PE
find –set-root /WXPE/SETUPLDR.BIN
chainloader /WXPE/SETUPLDR.BIN (hd0)+1
title [03] 启动CDlinux社区标准版+无线破解
find –set-root /CDlinux/bzImage
kernel /CDlinux/bzImage quiet CDL_LANG=zh_CN.UTF-8 CDL_AMOUNT=yes
initrd /CDlinux/initrd
title [04] Ubuntu_10.10_64_fast
map (hd0,0)/Ubuntu_10.10_64.iso (hd32)
map –hook
root (hd0,0)
kernel (hd32)/casper/vmlinuz boot=casper iso-scan/filename=/Ubuntu_10.10_64.iso
initrd (hd32)/casper/initrd.lz
title [F9] 重启计算机
reboot
title [F10] 关闭计算机
halt

用虚拟光驱加载Ubuntu的镜像,把整个ISO的文件内容拷贝到U盘,这时,Ubuntu就准备好了

xmpe101010介绍
http://bbs.wuyou.com/viewthread.php?tid=168287
下载地址
http://u.115.com/file/t5e0236d5f

同样用虚拟光驱加载小马PE的文件,把minipe的文件拷贝到U盘根目录下,同时把wxpe目录下的ntdetect.exe拷到U盘根目录下,至此,小马PE就准备好了

CDlinux社区标准版+无线破解,我们需要从另外一个镜像里提取

无忧启动.多功能维护工具盘(无线破解).iso
下载地址:
http://u.115.com/file/t21e955d0a

同样用虚拟光驱加载无忧启动.多功能维护工具盘(无线破解).iso,在U盘根目录下建个boot目录,然后把ISO里的BOOT目录下的message拷贝到U盘的boot下,这个主要是用来美化菜单的
把iso里的CDlinux拷贝到U盘根目录下

把Ubuntu 10.10 64位的iso拷贝到U盘根目录下,Ubuntu的快速启动也准备好了,现在可以用U盘启动

扩展阅读
这里顺便说明下,其实用dd命令生成一个虚拟硬盘文件放到U盘,然后对该文件进行格式化也是可以的,但我自己制作的时候,Ubuntu无法启动,所以还是采用分区的方法,写下方法生成虚拟磁盘文件的方法
参考这篇文章
http://hi.baidu.com/cnjowang/blog/item/b58734869d5c6226c65cc3ea.html
dd if=/dev/zero of=casper-rw bs=1M count=1024
mkfs.ext2 -F casper-rw

Ubuntu的配置是否保存,关键看kernel行是否使用了persistent

已知问题:
CDlinux在部分机器无法启动

主要参考文章:
http://forum.ubuntu.org.cn/viewtopic.php?t=172013

Re-reading the partition table failed with error 16 Device or resource busy

I had this situation at office where I was told to re-partition an already existing partition. The situation was to get the below schema

/dev/sdb1 1 3040 24418768+ 83 Linux

/dev/sdb2 3041 6080 24418800 83 Linux
/dev/sdb3 6081 30515 196274137+ 83 Linux

to

/dev/sdb1 1 3040 24418768+ 83 Linux
/dev/sdb2 3041 6080 24418800 83 Linux
/dev/sdb3 6081 30515 196274137+ 5 Extended
/dev/sdb5 6081 18239 97667136 83 Linux
/dev/sdb6 18240 30515 98606938+ 83 Linux

Alright, now the partition /dev/sdb2 was in use and cannot be unmounted. So what happens when you finish the partitioning with fdisk ?

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

This happends, if you are using/mounted any partitions of the HDD which you just re-partitioned. Normally we do reboot the machine to get this right. But this is not always the easy way out, when you have something running on the machine/multiple users are on the machine working etc. So there comes the “parted” for rescue.

The package “parted” provides a tool called “partprobe“. This will do the magic for you, you just type in the command (see the man page for more info on partprobe) and this will give the information needed about your newly created partition to your kernel.

http://blog.csdn.net/xdstone1/archive/2009/02/24/3931191.aspx

定制的CentOS,提示无法挂载根分区

定制的CentOS5.4系统无法启动,应该是去到挂载磁盘的时候,提示
VFS:Cannot open root device “sda2” or unknown block(0,0);
Please append a correct “root=” boot option
kernel panic -not syncing:VFS:Unable to mount root fs on unknown block(0,0)

网上查资料说是因为编译内核的时候,没有把scsi的驱动编译进内核,但用的内核是CentOS5.4自带的,如果用完整光盘安装,则不会有错
初步怀疑安装过程出错,用光盘启动进入修复模式
光盘启动后输入
linux rescue
然后按2次确定吧,系统挂载到/mnt/sysimage
chroot /mnt/sysimage,这时就进入到硬盘上的系统了
首先看下grub.conf
cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/1

再找台可以正常启动的机器看下
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/1
initrd /initrd-2.6.18-164.el5.img

现在看到前面有问题的系统,配置文件里少了一行关于initrd的配置
本来想手动加上去,但
ls /boot/
发现根本没有initrd-2.6.18-164.el5.img
记得上次看刘天斯的<<编译内核及制作RPM包>>
文件见
http://blog.liuts.com/post/180/

里面说到initrd-2.6.18-164.el5.img不是包含在rpm包里的,而是要在安装过程生成的

想到要看下/root目录下的install.log,看安装过程出了什么问题
vi /root/install.log

关键错误
/sbin/mkinitrd:line 1367:mktemp:command not found
Error creating temporaries. Try again
mkinitrd failed

去到正常的系统里
which mktemp
输出:/bin/mktemp
rpm -qf /bin/mktemp
输出:
mktemp-1.5-23.2.2

把mktemp-1.5-23.2.2复制到目录,然后重新生成ISO文件,再安装系统,启动就正常了

需要注意的是,再看下/root/install.log,看报什么错,如果是关键错误,要看如何修复

############################延伸阅读######################
内核引导文件initrd.img简介

http://netbay.bokee.com/3353657.html
作者:coolq 更新日期:2005-08-22
来源:linuxforum.net

什么是initrd?
initrd = init ramdisk,是一个启动时存在于内存的文件系统。 initrd的最初的目的是为了把kernel的启动分成两个阶段:在kernel中保留最少最基本的启动代码,然后把对各种各样硬件设备的支持以模块的 方式放在 initrd中,这样就在启动过程中可以从initrd所mount的根文件系统中装载需要的模块。这样的一个好处就是在保持kernel不变的情况下, 通过修改initrd中的内容就可以灵活的支持不同的硬件。在启动完成的最后阶段,根文件系统可以重新mount到其他设备上。

Linux启动一定要用initrd么?
不必,如果把需要的功能全都编译到内核中(非模块方式),只需要一个内核文件即可,initrd能够减小启动内核的体积并增加灵活性。如果你的内核以模块 方式支持某种文件系统(例如ext3, UFS),而启动阶段的驱动模块(如jbd)放在这些文件系统上,内核是无法读取文件系统的,从而只能通过initrd的虚拟文件系统来装载这些模块。这 里有些人会问: 既然内核此时不能读取文件系统,那内核的文件是怎么装入内存中的呢?答案很简单,Grub是file-system sensitive的,能够识别常见的文件系统。

initrd文件是怎么生成的?
使用mkinitrd命令,这个命令其实是一个Bash脚本
#file `which mkinitrd`
/sbin/mkinitrd: Bourne-Again shell script text executable
该脚本先建立一个8M的空文件,并在此上建立一个文件系统,并拷贝相应的的文件。

查看initrd里面的文件
mkdir /root/initrd
cd /root/initrd
cp /boot/initrd-2.6.18-164.el5.img .
mv initrd-2.6.18-164.el5.img initrd-2.6.18-164.el5.img.gz
gunzip initrd-2.6.18-164.el5.img.gz
file initrd-2.6.18-164.el5.img
输出:initrd-2.6.18-164.el5.img: ASCII cpio archive (SVR4 with no CRC)
cpio -idmv < initrd-2.6.18-164.el5.img
ls
可以看到以下目录和文件
bin dev etc init lib proc sbin sys sysroot

关于Shell的补零,用printf来格式化数字列。

解答论坛一个朋友关于获取01、02…10,而非1、2….10。
因为需要用flashget下载这样一些列的文件。自己了解这个应用,但是以前也没有处理过。还是有需要的。经过g后,测试得到。

[root@kook tmp]# cat for.sh
for ((a=1; a<=10 ; a++))
do
printf “%02d\n” $a
done
[root@kook tmp]# ./for.sh
01
02
03
04
05
06
07
08
09
10

这么写,也可以。

[root@kook tmp]# cat for.sh
for ((a=1; a<=10 ; a++))
do
printf “%.2d\n” $a
done

继续测试。

[root@kook tmp]# printf “%04d\n” -3
-003
[root@kook tmp]# printf “%.4d\n” -3
-0003

转载自:http://cnc.52zhe.cn/read.php/165.htm

2025年九月
« 5月    
1234567
891011121314
15161718192021
22232425262728
2930