1. 程式人生 > >初次編譯Linux—2.6.34核心

初次編譯Linux—2.6.34核心

       一、編譯環境:在ubuntu12.04下編譯純核心Linux-2.6.34

二、下載並解壓原始碼

三、構建編譯環境     現在我們得到的只是原始碼,只是許許多多的文字檔案,要想使這些檔案成為可以執行的程式,需要使用編譯器進行編譯以及連結。編譯器有很多,但在裡linux下一般都使用gnu的開源編譯器套件,這裡包括gcc等,現在我們安裝基本的編譯器套件,如圖所示: 四、安裝ncurses庫     這裡使用Ubuntu系統,因為系統自帶的ncurses庫在支援make menuconfig的時候會出錯,所以,依然要安裝ncurses庫,這裡我 們從原始碼安裝。首先去
ncurses官網上下載原始碼。這裡我們下載5.9版本,並通過簡單的安 裝方式.configure   makemake 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

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