Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1581864
  • 博文数量: 92
  • 博客积分: 2002
  • 博客等级: 大尉
  • 技术积分: 4717
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-01 17:09
文章分类

全部博文(92)

文章存档

2013年(1)

2012年(6)

2011年(85)

分类: LINUX

2011-08-09 15:49:44

一、红帽升级内核

1.1 安装内核源码rpm包,搭建源码环境


到 ftp://ftp.redhat.com/ 下载内核源码rpm包,如 kernel-2.6.9-78.0.25.EL.src.rpm#rpm -ivh kernel-2.6.9-78.0.25.EL.src.rpm --force --nodeps
注意现在源码包还没安装上,继续下面操作

#cd /usr/src/redhat/SPECS/
#vi kernel-2.6.spec

 主要修改如下地方:
 define buildsource 1    #默认为0,默认不生成源代码包,改为1
 %define buildhugemem 1  #支持高内存
 %define buildsmp 1      #支持多处理器
 %define buildlargesmp 1 #支持更多处理器
#rpmbuild  -ba --target=`uname -m` ./kernel-2.6.spec

 若只要sourcecode而并非所有rpm包,那在修改spec文件时还要修改如下行:
 %ifarch noarch
 %define builddoc 1
 %define buildsource 0   #这里0修改为1
#rpmbuild -ba --target=noarch ./kernel-2.6.spec



1.2 配置内核
#cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9/
#make mrproper
#make menuconfig

之后配置宏会保存在 .config里,可以与以前内核配置宏比较一下看看


1.3 生成内核rpm安装包
#make rpm
#rpm -ivh /usr/src/redhat/RPMS/i386/kernel-2.6.9prep-1.i386.rpm

1.4 直接安装内核
make
make modules_install #安装模块文件到 /lib/modules/2.6.9-pre/
make install         #安装System.map-2.6.9-pre、vmlinuz-2.6.9-pre、initrd-2.6.9-pre.img到/boot

1.5 修改grub,引导新内核

注意红色部分
[root@study linux-2.6.9]# vi /boot/grub/grub.conf
title Red Hat Enterprise Linux AS(2.6.9-pre)
     root (hd0,0)
     kernel /vmlinuz-2.6.9-custom-2.6.9-pre ro root=/dev/VolGroup00/LogVol00 rhgb quiet
     initrd /initrd-2.6.9-custom-2.6.9-pre.img


------------------------------------ 华丽的分割线 ----------------------------------------

二、红帽配置串口

2.1 编辑/boot/grub/grub.conf

  kernel /vmlinuz-2.4.21-27.0.2.ELsmp ro root=LABEL=/ console=ttyS0,115200 console=tty0
  initrd /initrd-2.4.21-27.0.2.ELsmp.img
  红色为新加部分

2.2 在/etc/inittab添加如下内容

  6:2345:respawn:/sbin/mingetty tty6
  co:2345:respawn:/sbin/agetty ttyS0 115200 vt100 init q

2.3 修改/etc/securetty文件

在该文件最后添加一行,内容为
ttyS0

------------------------------------- 华丽的分割线 -------------------------------------------

三、红帽 GUI/CMD Line 切换

ctrl + alt + f1  红帽切换到命令行模式
ctrl + alt + f7  红帽切换到GUI模式
注意:虚拟机的话,要长按F1和F7才行

若是修改启动模式的话,修改/etc/inittab

# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

------------------------------------ 华丽的分割线 --------------------------------


四、内核模块开发

内核模块编译时,一定要设置好$ARCH 和 $CROSS_COMPILE 两个环境变量
如果在目标机上写模块,最好
unset ARCH
unset CROSS_COMPILE

4.1 自己重新写内核模块

直接在下面目录开发即可
/lib/modules/`uname -r`/build
/lib/modules/`uname -r`/source

或者安装内核源码包
/usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9

4.2 单独
编译内核源码模块
cd /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9   #进入源码包目录 
make mrproper              #清空以前内核配置
make menuconfig            #配置好内核模块
make                       #这一步很重要,2秒后 Ctrl+C
make M=driver/char/ipmi    #编译模块


----------------------------------- 华丽的分割线 -------------------------------------------

五、VMware红帽修改分辨率

(1)在shell里输入system-config-display,在GUI里配置自己的显示器类型和分辨率;
   原理是修改 /etc/X11/xorg.conf,
(2)如果你的分辨率比较怪异(如1360x768),可以直接/etc/X11/xorg.con

Section "Monitor"
    ModeLine "1024x768" 100 1024 1100 1200 1300 768 800 900 1000
    ModeLine "2048x768" 100 2048 2100 2200 2300 768 800 900 1000
    ModeLine "1300x100" 100 1300 1400 1500 1600 100 200 300 400
    #下面这条是我加的
    ModeLine "1360x768" 100 1360 1400 1500 1600 768 800 900 1000
EndSection

Section "Screen"
    # VGA mode: better left untouched 默认不要改
    Subsection "Display"
        Depth       4
        Modes       "640x480"
        ViewPort    0 0
    EndSubsection
    # 下面这个subsection 是我加的
    Subsection "Display"
        Depth       8
        Modes       "1360x768"
        ViewPort    0 0
    EndSubsection

EndSection

------------------------------- 华丽的分割线 ------------------------------------

六、软件安装和卸载

红帽的/bin/rpm 与 Debian的/usr/bin/dpkg是两种系统常用的二进制软件包操作工具,
假设一个叫abc的软件,在Redhat与Debian系统中的软件包的名字叫: abc.rpm 和 abc.deb

软件删除:
#rpm -e  abc
#dpkg -r abc

列出软件包的内容:
#rpm -qvl abc.rpm
#dpkg -c abc.deb

列出所有已安装软件包及简略信息:
#rpm -qvia
#dpkg -l (小写的L)

列出一个特定的软件包的详细信息:
#rpm -qpi abc.rpm
#dpkg -I (大写的 i)abc.deb

软件包完整性检查:
#rpm -Va
#debsums -a

查看一个文件foo归属于哪个软件包:
#rpm -qf foo
#dpkg -S foo

安装软件包:
#rpm -Uvh abc.rpm
#dpkg -i abc.deb

------------------------------- 华丽的分割线 ------------------------------------

七、绕过开机脚本

有些时候,因为启动脚本的bug会导致linux 系统启动时卡在Enabling etc/fstab swap OK
最终系统无法正常启动,这时就需要绕开启动脚本进入系统,把有问题的脚本注释掉
步骤如下:
1.在grub下kernel一行 的末尾添加 init=/bin/sh
2.linux系统启动不会去执行init,而是去执行/bin/sh,但此时root文件系统是只读的
3.在sh下敲# mount -o rw,remount /  重新mount根目录,加上读写权限
4.修改启动脚本,重启,ok

------------------------------------ 华丽的分割线 ---------------------------------------

initrd.img 在系统启动与安装时都会加载到,该文件主要为系统的启动加载需要的模块与驱动程序。那么在initrd.img中到底放置了哪些模块呢,我们将其解压开来瞧一瞧。

1 解开
以/boot/initrd.img 为例,以下为主要的解开步骤:
mkdir -p  /tmp/initrd/boot
cd /tmp/initrd/boot
zcat /boot/initrd-2.6.18-53.el5.img | cpio -i

解压完了以后,看一下到底有什么东西
[root@Palo boot]# ls -R
.:
bin  dev  etc  init  lib  proc  sbin  sys  sysroot
一共有这么多文件和目录
./bin:
dmraid  insmod  kpartx  modprobe  nash
./dev:
console  null  ram   ram1  systty  tty0  tty10  tty12  tty3  tty5  tty7  tty9   ttyS1  ttyS3
mapper   ptmx  ram0  rtc   tty     tty1  tty11  tty2   tty4  tty6  tty8  ttyS0  ttyS2  zero
设备文件
./dev/mapper:
设备映像
./etc:
该目录为空
./lib:
ehci-hcd.ko  ext3.ko  firmware  jbd.ko  ohci-hcd.ko  uhci-hcd.ko
启动加载的模块
ext3.ko jbd.ko 模块没有将导致系统起不来
./lib/firmware:

./proc:

./sys:

./sysroot

2 压回
cd /tmp/initrd/boot
find | cpio -H newc -o > ../initrd.img
cd ..
gzip -9 initrd.img
mv initrd.img.gz /boot/initrd.img

在grub.conf 中添加一个titile ,使用删除ext3.ko,jbd.ko 的initrd.img 来引导系统,查看效果。

bin 下放置的是一些程序
dmraid 用于创建软raid ;insmod 用于将module 加载到内存(不会加载依赖关系);kpartx 多路冗余分区工具;
modprobe 安装module (会加载依赖关系);nash 最精简的shell

-------------------------------------------------------------------------------------



         NOTE 4




可以看到/boot下面多了我们的新内核文件vmlinuz-2.6.9-prep
/lib/modules下面多了文件夹2.6.9-prep/,其中包含了新内核的所有模块。

为我们的新内核制作一个内存盘,确保新内核能够启动
[root@study linux-2.6.9]#  mkinitrd /boot/initrd-2.6.9-prep.img  /lib/modules/2.6.9-prep/

在启动引导器grub的配置文件中添加属于新内核的一段配置
[root@study linux-2.6.9]# vi /boot/grub/grub/conf

default=2 因为我的新内核配置段排在第3位,这样把新内核作为默认启动项
...
title Red Hat Enterprise Linux AS(2.6.9-34custom)
     root (hd0,0)
     kernel /vmlinuz-2.6.9-custom-2.6.9-34 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
     initrd /initrd-2.6.9-custom-2.6.9-34.img

No volume groups found
Unable to find volume group "VolGroup00"
ERROR: /bin/lvm exited abnormally with value 5 ! (pid 362)

Mount: error 6 mounting ext3

-------------------------------------------------------------------------------------------------------


linux中的service命令是从 /etc/init.d/下面去找 脚本,
通过脚本参数,来执行start、stop、restart、status操作


阅读(5976) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~