一、编译环境:在ubuntu12.04下编译纯内核Linux-2.6.34
二、下载并解压源代码
三、构建编译环境
现在我们得到的只是源代码,只是许许多多的文本文件,要想使这些文件成为可以运行的程序,需要使用编译器进行编译以及链接。编译器有很多,但在里linux下一般都使用gnu的开源编译器套件,这里包括gcc等,现在我们安装基本的编译器套件,如图所示:
四、安装ncurses库
这里使用
Ubuntu
系统,因为系统自带的
ncurses
库在支持
make menuconfig
的时候会出错,所以,依然要安装
ncurses
库,这里我 们从源码安装。首先去
ncurses
官网
http://ftp.gnu.org/pub/gnu/ncurses/
上下载源码。这里我们下载
5.9
版本,并通过简单的安 装方式
.configure
和
make
、
make install
方式安装。
如下图
所示:
sudo make menuconfig
sudo make
sudo make modules
sudo make modules_install
sudo make install
#change directory to /boot
cd /boot
sudo mkinitramfs -o initrd.img-2.6.34 2.6.34 //这一步貌似是多余的
sudo update-grub
#Here We Go!
sudo reboot
sudo make modules
sudo make modules_install
sudo make install
#change directory to /boot
cd /boot
sudo mkinitramfs -o initrd.img-2.6.34 2.6.34 //这一步貌似是多余的
sudo update-grub
#Here We Go!
sudo reboot
PROBLEM:-1
------------------------------------------------------------------------------------------------------
gcc: error: elf_i386: No such file or directory
OBJCOPY arch/x86/vdso/vdso32-int80.so
objcopy: 'arch/x86/vdso/vdso32-int80.so.dbg': No such file
make[2]: *** [arch/x86/vdso/vdso32-int80.so] Error 1
make[1]: *** [arch/x86/vdso] Error 2
make: *** [arch/x86] Error 2
------------------------------------------------------------------------------------------------------
SOLUTION:
----------
The problem is that gcc 4.6 doesn't support anymore linker-style architecture options.
Apply the following changes to solve the problem :
In arch/x86/vdso/Makefile :
replace "-m elf_x86_64" by "-m64" on the line starting with VDSO_LDFLAGS_vdso.lds
replace "-m elf_i386" by "-m32" on the line starting with VDSO_LDFLAGS_vdso32.lds
------------------------------------------------------------------------------------------------------
PROBLEM:-2
------------------------------------------------------------------------------------------------------
In file included from drivers/net/igbvf/ethtool.c:36:0:
drivers/net/igbvf/igbvf.h: At top level:
drivers/net/igbvf/igbvf.h:129:15: error: duplicate member ‘page’
make[3]: *** [drivers/net/igbvf/ethtool.o] Error 1
make[2]: *** [drivers/net/igbvf] Error 2
make[1]: *** [drivers/net] Error 2
make: *** [drivers] Error 2
------------------------------------------------------------------------------------------------------
SOLUTION:
---------
struct igbvf_buffer {
dma_addr_t dma;
struct sk_buff *skb;`enter code here`
union {
/* Tx */
struct {
unsigned long time_stamp;
u16 length;
u16 next_to_watch;
u16 mapped_as_page;
};
/* Rx */
struct {
struct page *page; <--------------- No 1
u64 page_dma;
unsigned int page_offset;
};
};
struct page *page; <------------ No 2
};
Hmm conflict of a member with a transparent union.
Maybe older gccs didn't catch that. But it looks very broken
Comment second pointer.
------------------------------------------------------------------------------------------------------
PROBLEM 3: Similar to Problem-2
-------------------------------------------------------------------------------
In file included from drivers/scsi/pmcraid.c:57:0:
drivers/scsi/pmcraid.h: At top level:
drivers/scsi/pmcraid.h:601:8: error: duplicate member ‘sense_buffer’
drivers/scsi/pmcraid.c: In function ‘pmcraid_abort_cmd’:
drivers/scsi/pmcraid.c:2940:33: warning: variable ‘res’ set but not used [-Wunused-but-set-variable]
drivers/scsi/pmcraid.c: In function ‘pmcraid_ioctl_passthrough’:
drivers/scsi/pmcraid.c:3745:5: warning: variable ‘access’ set but not used [-Wunused-but-set-variable]
drivers/scsi/pmcraid.c: In function ‘pmcraid_check_ioctl_buffer’:
drivers/scsi/pmcraid.c:4052:6: warning: variable ‘access’ set but not used [-Wunused-but-set-variable]
make[3]: *** [drivers/scsi/pmcraid.o] Error 1
make[2]: *** [drivers/scsi] Error 2
make[1]: *** [drivers] Error 2
make[1]: Leaving directory `/home/ashish/litmus-rt'
make: *** [debian/stamp/build/kernel] Error 2
-------------------------------------------------------------------------------
SOLUTION:
----------
Comment drivers/scsi/pmcraid.h:571
-------------------------------------------------------------------------------
问题四:由于分区时/usr 分配空间较小,导致vmlinux:final close failed : no space left on device空间不足的错误出现 。所以以后一定要注意分区问题,现在暂时换一个目录编译。注意,网上很多教程上说应该解压到 /usr/src,纯属以讹传讹,linux掌门人linus说解压到任何目录上都可以。当然,linus的说法是正确的。现在我换到/home目录下。
小技巧:进入内核源码所在目录,然后cp /boot/config-`uname -r` ./.config 用你现在的内核配置设置新内核
tip:make clean、make mrproper、make distclean的区别# make help
Cleaning targets:
clean - Remove most generated files but keep the config and
enough build support to build external modules
mrproper - Remove all generated files + config + various backup files
distclean - mrproper + remove editor backup and patch files看帮助可以发现删除的文件范围从小到大依次为: make clean < make mrproper < make distclean, 查看源码目录树的顶层目录下的Makefile求证, 可以发现:问题五:warning:modpost:found 17 section mismatches To see full details build your kernel with: 'make CONFIG_DEBUG_SECTION_MISMATCH=y'resolution:make CONFIG_DEBUG_SECTION_MISMATCH=y took ~2h here to rebuild the whole kernel and modules, only to mention that some obscure eth and scsi drivers are doing odd things in their initialisation functions.问题六:编译内核模块并安装完后,重启却不出现启动引导菜单,而是直接进了原系统。resolution:原来是修改了 /etc/default/grub 后 要使用命令 update-grub更新一下 /boot/grub/grub.cfg问题七:编译安装完成,且启动菜单有了新内核选项,但是新内核无法启动系统,红屏且没有任何输出信息.找不到问题的源头,可能是配置的问题,没办法,只有重来一次。将原本Linux内核的配置复制过来后(只修改了processor type、scsi、fution MPI这几个),编译安装完成,新内核成功启动。![]()
删除手动编译的内核
ubuntu
代码:
sudo rm -rf /lib/modules/2.6.37.6 sudo rm -rf /usr/src/linux-headers-2.6.37.6 sudo rm /boot/*2.6.37.6* sudo rm /var/lib/dpkg/info/linux-headers-2.6.37.6*
fedora,我的是这个
代码:
sudo rm -rf /lib/modules/2.6.38.6-27.fc15.x86_64 sudo rm -rf /usr/src/kernels/2.6.38.6-27.fc15.x86_64 sudo rm /boot/*2.6.38.6-27*
代码:
update-grub
删除手动编译的内核
ubuntu
代码:
sudo rm -rf /lib/modules/2.6.37.6
sudo rm /boot/*2.6.37.6*
sudo update-grub