非常好的Linux编译内核详解
https://blog.csdn.net/xringm/article/details/79956220
这篇文档漏了一个关键步骤:mkinitrd
【Linux编译内核】Redhat9(内核版本2.4.20-8)编译内核到版本(2.4.26)
https://blog.csdn.net/coder__cs/article/details/52822007
照着文档做即可,我这里只记录关键步骤和坑。
SCSI硬盘+VMWARE+REDHAT架构
WINDOWS7为宿主机,安装vmware workstation.
redhat 7.2版本
内核版本2.4.7,GCC2.9.6
准备升级到2.4.18
我的环境是grub启动,所以不需要编辑/etc/lilo.conf
REDHAT Linux 7.2下载
ftp://ftp.linuxforum.net/ISO/Redhat7.2/enigma-i386-disc1.iso
ftp://ftp.linuxforum.net/ISO/Redhat7.2/enigma-i386-disc2.iso
下载两个ISO。
磁盘空间4g即可,但是如果要在里面安装更高版本的GCC,则4G不够。
2.4.7升级到2.4.18无需升级GCC
方法一:http://ftp.scientificlinux.org/linux/redhat/7.2/i386/RedHat/RPMS/
方法二:直接从ISO中获取
enigma-i386-disc1.iso
enigma-i386-disc2.iso
umount /mnt/cdrom
mount -t iso9660 /dev/cdrom /mnt/cdrom
找到并安装opensshxxx.rpm
[root@localhost cdrom]# service sshd status
sshd (pid 1111 1103 1095 1086 1078 1065 793) is running...
redhat缺省没有安装gcc,所以需要自己手工从RPM包安装。幸运的是这些包在两个光盘文件中能够找到:
/mnt/cdrom/RedHat/RPMS/
rpm -ivh kernel-headers-2.4.7-10.i386.rpm
rpm -ivh glibc-devel-2.2.4-13.i386.rpm
rpm -ivh binutils-2.11.90.0.8-9.i386.rpm
rpm -ivh gcc-2.96-98.i386.rpm
ncurses-devel-5.2-2.i386.rpm
否则后面配置内核会报错
[root@localhost linux]# make menuconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/docproc
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/kxgettext.o
HOSTCC scripts/kconfig/mconf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/lex.zconf.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/mconf
HOSTCC scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:31:20: curses.h: No such file or directory
make[2]: *** [scripts/kconfig/lxdialog/checklist.o] Error 1
make[1]: *** [menuconfig] Error 2
make: *** [menuconfig] Error 2
[root@localhost linux]#
#make config(基于文本的最为传统的配置界面,不推荐使用)
#make menuconfig(基于文本选单的配置界面,字符终端下推荐使用)
#make xconfig(基于图形窗口模式的配置界面,Xwindow下推荐使用)
#make oldconfig(如果只想在原来内核配置的基础上修改一些小地方,会省去不少麻烦)
make oldconfig 这个方法不行,我试过了。
make menuconfig 这个不错
Code maturity level options --->
Loadable module support --->
Processor type and features --->
General setup --->
Memory Technology Devices (MTD) --->
Parallel port support --->
Plug and Play configuration --->
Block devices --->
Multi-device support (RAID and LVM) --->
Networking options --->
Telephony Support --->
ATA/IDE/MFM/RLL support --->
SCSI support --->
Fusion MPT device support --->
I2O device support --->
Network device support --->
Amateur Radio support --->
IrDA (infrared) support --->
ISDN subsystem --->
Old CD-ROM drivers (not SCSI, not IDE) --->
Input core support --->
Character devices --->
Multimedia devices --->
File systems --->
Console drivers --->
Sound --->
USB support --->
Kernel hacking --->
---
Load an Alternate Configuration File
Save Configuration to an Alternate File
Device Drivers --->SCSI device support ---><*> SCSI disk support Device Drivers --->SCSI device support --->SCSI low-level
drivers ---> <*> BusLogic SCSI support
配置完后,在/usr/src/linux/.config中必须要有
#
# SCSI support
#
CONFIG_SCSI=y
必须要选择EXT3
配置完后,在/usr/src/linux/.config中必须要有:
CONFIG_EXT3_FS=y
否则,会起不来。
如果只是CONFIG_EXT3_FS=m 也不行。
网上有人说很慢,在我机器上只有几分钟就编译完了。
不要用make install原因是有很多错误。就用mkinitrd制作initrd即可。
mkinitrd /boot/initrd-2.4.18.img 2.4.18
No module BusLogic found for kernel 2.4.12
mkinitrd failed
此问题一般只出现在SCSI硬盘+VMWARE+REDHAT架构中,因为BusLogic被编译进了内核而不是一个module的形式(2.4内核的Buslogic模块即使静态编译进内核也不行)。解决方式是直接将BusLogic.o文件复制过去:
mkdir /lib/modules/2.4.18/kernel/drivers/scsi 要先创建目录
cp /usr/src/linux/drivers/scsi/BusLogic.o /lib/modules/2.4.18/kernel/drivers/scsi
备注:如果在配置内核时没有选择正确,那么就不能编译出BusLogic.o出来。
# 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=10 splashimage=(hd0,0)/grub/splash.xpm.gz title Red Hat Linux (2.4.7-10) root (hd0,0) kernel /vmlinuz-2.4.7-10 ro root=/dev/sda2 hda=ide-scsi hdc=ide-scsi initrd /initrd-2.4.7-10.img title Red Hat Linux (2.4.18) root (hd0,0) kernel /vmlinuz-2.4.18 ro root=/dev/sda2 hda=ide-scsi hdc=ide-scsi initrd /initrd-2.4.18.img |
[root@localhost root]# uname -a
Linux localhost.localdomain 2.4.18 #3 SMP Sat Sep 14 10:33:39 EDT 2019 i686 unknown
[root@localhost boot]# ll
total 5222
-rw-r--r-- 1 root root 5824 Jun 24 2001 boot.b
-rw-r--r-- 1 root root 612 Jun 24 2001 chain.b
-rw-r--r-- 1 root root 19369 Sep 14 09:48 config-2.4.18
drwxr-xr-x 2 root root 1024 Sep 14 10:01 grub
-rw-r--r-- 1 root root 306477 Sep 14 10:42 initrd-2.4.18.img
-rw-r--r-- 1 root root 438273 Sep 13 17:27 initrd-2.4.7-10.img
lrwxrwxrwx 1 root root 14 Sep 13 21:42 kernel.h -> kernel.h-2.4.7
-rw-r--r-- 1 root root 405 Sep 13 21:42 kernel.h-2.4.7
drwxr-xr-x 2 root root 12288 Sep 13 17:27 lost+found
-rw-r--r-- 1 root root 23108 Jun 24 2001 message
lrwxrwxrwx 1 root root 20 Sep 13 17:27 module-info -> module-info-2.4.7-10
-rw-r--r-- 1 root root 13598 Sep 6 2001 module-info-2.4.7-10
-rw-r--r-- 1 root root 640 Jun 24 2001 os2_d.b
lrwxrwxrwx 1 root root 17 Sep 14 10:44 System.map -> System.map-2.4.18
-rw-r--r-- 1 root root 519897 Sep 14 10:40 System.map-2.4.18
-rw-r--r-- 1 root root 435039 Sep 6 2001 System.map-2.4.7-10
lrwxrwxrwx 1 root root 14 Sep 14 10:41 vmlinuz -> vmlinuz-2.4.18
-rw-r--r-- 1 root root 1130215 Sep 14 10:40 vmlinuz-2.4.18
-rw-r--r-- 1 root root 802068 Sep 6 2001 vmlinuz-2.4.7-10
ds: no socket drivers loaded!
ext2-fs: sd(8,2): couldn't mount because of unsupported option features
原因:前面配置有误
ext2或者ext3没有编译进内核里面,.config文件最后应该要存在:
CONFIG_EXT2_FS=y
CONFIG_EXT3_FS=y
make install
/etc/lilo.conf: No such file or directory
这个是因为 make install 本来就有很多问题,我机器上用的是grub,不是 lilo
所以,不要用 make install 改为 mkinitrd
include/linux/compiler.h:46:3: #error Sorry, your compiler is too old/not recognized.
这个是尝试升级到2.6.18出现的,原因是gcc version 2.96编译2.6.18的内核不行。
解决办法:不用升级到那么高的内核,升级到2.4.18不会遇到此问题。
如果要升级到2.6之后的内核,那么需要升级GCC版本,还比较麻烦。