ubuntu模塊編譯
A. ubuntu 驅動編譯無法通過 求神來解決
復制代碼
1 #ifndef __KERNEL__
2 # define __KERNEL__
3 #endif
4 #ifndef MODULE
5 # define MODULE
6 #endif
7
8 // 下面的是主要的內容
9 #include <linux/kernel.h>
10 #include <linux/mole.h>
11 #include <linux/init.h>
12
13 MODULE_LICENSE("GPL");
14
15 static int year=2012;
16
17 int hello_init()
18 {
19 printk(KERN_WARNING "Hello kernel, it's %d!\n",year);
20 return 0;
21 }
22
23
24 void hello_exit()
25 {
26 printk("Bye, kernel!\n");
27 }
28
29 // 下面兩個為關鍵的模塊函數
30 mole_init(hello_init);
31 mole_exit(hello_exit);
復制代碼
如果上面的代碼看起來不太熟悉,那麼需要查看以下相關的書籍,比如《Linux設備驅動程序,第三版》,也就是大名鼎鼎的LDD;
2、老式驅動模塊編譯方法:
直接寫出make規則到makefile文件中,引用內核體系的頭文件路徑,舉例如下:
復制代碼
1 # The path of kernel source code
2 INCLUDEDIR = /media/GoldenResources/linux/linux-2.6.30/include
3
4 # Compiler
5 CC = gcc
6
7 # Options
8 CFLAGS = -D__KERNEL__ -DMODULE -O -Wall -I$(INCLUDEDIR)
9
10 # Target
11 OBJS = hello.o
12
13 all: $(OBJS)
14
15 $(OBJS): hello.c
16 $(CC) $(CFLAGS) -c $<
17
18 install:
19 insmod $(OBJS)
20
21 uninstall:
22 rmmod hello
23
24 .PHONY: clean
25 clean:
26 rm -f *.o
復制代碼
這里有我是用的一個linux內核源代碼路徑:/media/GoldenResources/linux/linux-2.6.30/include ,注意設置到正確的源碼路徑。
嘗試這編譯:
復制代碼
$make
gcc -D__KERNEL__ -DMODULE -O -Wall -I/media/GoldenResources/linux/linux-2.6.30/include -c hello.c
In file included from /media/GoldenResources/linux/linux-2.6.30/include/linux/kernel.h:11:0,
from hello.c:8:
/media/GoldenResources/linux/linux-2.6.30/include/linux/linkage.h:5:25: fatal error: asm/linkage.h: No such file or directory
compilation terminated.
make: *** [hello.o] Error 1
復制代碼
B. ubuntu下如何編譯C語言
1、首先打開ubnutu開發環境,直接輸入組合鍵ctrl+alt+t調出命令行界面。
C. 虛擬機中ubuntu12.04下,編譯內核模塊時報錯:make:***無目標. 停止.。。。。Makefile如下:
解除游戲限制一鍵安裝極速版封喉虛擬機下載地址:
D. ubuntu內核編譯需要多長時間
在分析linux內核源碼的過程中,要是能夠修改內核源碼並運行修改後的內核,我想肯定是令人高興的事,哪怕第一次修改僅僅是在啟動時列印一行"Hello, Wang Jiankun!",肯定也是令我高興的。為了能成功編譯修改後的內核,今天先編譯一遍內核。
為了有一個完整的記錄,今天的起點是一台裸機。
1、在裸機上安裝一個最小的debian系統
為了能夠盡可能清晰的顯示編譯一個內核所需要的組件,在安裝系統時,僅僅安裝最小系統,然後需要什麼,就使用apt-get安裝什麼。
使用網路安裝,在安裝過程中出現Software selection界面時不要選擇任何選項,這樣安裝的系統將是最小的系統。
為了使用ssh遠程登錄,最小系統安裝完成後,要安裝ssh伺服器並且要設置靜態ip地址(debian安裝過程中是通過dhcp獲取的ip地址)。
2、安裝ssh伺服器
apt-get install ssh
3、設置靜態ip地址
修改文件/etc/network/interfaces,其中藍色部分是增加的,紅色部分是屏蔽掉的,黑色部分是沒有變化的。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
# Wang Jiankun commented the following line
#iface eth0 inet dhcp
# Wang Jiankun added the the following lines
iface eth0 inet static
address 192.168.1.251
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.1
重啟系統後,修改將生效。
4、通過wget下載linux內核源碼
administrator@wangjk:~/kernel$ wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.tar.bz2
5、解壓文件linux-2.6.19.tar.bz2
administrator@wangjk:~/kernel$ tar jxf linux-2.6.19.tar.bz2
tar: bzip2: Cannot exec: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
administrator@wangjk:~/kernel$
看來是沒有bzip2這個包,那就安裝一個:
apt-get install bzip2
6、安裝debian的kernel-package軟體包
在安裝kernel-package軟體包時,最好使用命令:apt-get build-dep kernel-package,而不要使用命令:
apt-get install kernel-package,後者安裝的軟體包是前者的子集,使用後者安裝kernel-package軟體包後,執行make menuconfig命令會出現頭文件找不到的錯誤,如下所示:
administrator@wangjk:~/kernel/linux-2.6.19$ make menuconfig
HOSTCC scripts/basic/fixdep
scripts/basic/fixdep.c:105:23: error: sys/types.h: No such file or directory
scripts/basic/fixdep.c:106:22: error: sys/stat.h: No such file or directory
scripts/basic/fixdep.c:107:22: error: sys/mman.h: No such file or directory
scripts/basic/fixdep.c:108:20: error: unistd.h: No such file or directory
scripts/basic/fixdep.c:109:19: error: fcntl.h: No such file or directory
scripts/basic/fixdep.c:110:20: error: string.h: No such file or directory
scripts/basic/fixdep.c:111:20: error: stdlib.h: No such file or directory
scripts/basic/fixdep.c:112:19: error: stdio.h: No such file or directory
主要是因為libc6-dev軟體包沒有安裝。所以即使使用了apt-get install kernel-package還得使用apt-get build-dep kernel-package,不如一次使用apt-get build-dep kernel-package完成方便。
7、安裝libncurses5-dev軟體包來支持make menuconfig
通過apt-get build-dep kernel-package安裝完成kernel-package後,執行make menuconfig仍然報錯,如下所示:
administrator@wangjk:~/kernel/linux-2.6.19$ make menuconfig
HOSTCC scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:32:20: error: curses.h: No such file or directory
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:97: error: expected specifier-qualifier-list before 'chtype'
scripts/kconfig/lxdialog/dialog.h:187: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:193: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:195: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:196: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:197: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:198: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:200: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:31: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:59: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:95: error: expected ')' before '*' token
[省略其後部分]
原來是最小系統不支持圖形的原因,安裝libncurses5-dev後即可。
8、將系統的config文件拷貝到內核目錄下
cp /boot/config-2.6.18-6-686 ./.config
9、執行make menuconfig
雖然是將原來系統的config文件拷貝過來的,但是如果所以的配置都採用默認的配置仍然會有問題,在我的系統上在載入文件系統時會死掉,所以還是要做必要的配置,主要是將scsi和sata部分編譯進內核而不要編譯成模塊,如下所示:
Device Drivers --->
Serial ATA (prod) and Parallel ATA (experimental) drivers --->
SCSI device support --->
將藍色兩部分級聯的選項全部編譯進內核(其實沒有必要全部,但為了簡單起見,暫時這樣做)。
10、安裝fakeroot軟體包
11、編譯內核
fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image
12、安裝內核
wangjk:/home/administrator/kernel# dpkg -i linux-image-2.6.19_custom.1.0_i386.deb
Selecting previously deselected package linux-image-2.6.19.
(Reading database ... 17679 files and directories currently installed.)
Unpacking linux-image-2.6.19 (from linux-image-2.6.19_custom.1.0_i386.deb) ...
Done.
Setting up linux-image-2.6.19 (custom.1.0) ...
Running depmod.
Finding valid ramdisk creators.
Using mkinitramfs-kpkg to build the ramdisk.
Running postinst hook script /sbin/update-grub.
You shouldn't call /sbin/update-grub. Please call /usr/sbin/update-grub instead!
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-2.6.19
Found kernel: /boot/vmlinuz-2.6.18-6-686
Updating /boot/grub/menu.lst ... done
13、重啟系統引導新內核後查看版本號
administrator@wangjk:~$ cat /proc/version
Linux version 2.6.19 (root@wangjk) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP Thu May 7 21:52:10 CST 2009
administrator@wangjk:~$
可以看出已經是我編譯的內核了。
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/jiankun_wang/archive/2009/05/04/4147806.aspx
------------------------------------
ubuntu不帶linux內核源碼,需要自己下載安裝。
1,查看自己的內核版本
uname -r
2,查看源內的內核源碼類表
apt-cache search linux-source
3,下載安裝內核源代碼
sudo apt-get install linux-source-2.6.27 //我選的是這一個,自己看著辦吧
4,等待........
下載完成後,在/usr/src下會有一個文件名為linux-source-2.6.xx.tar.bz2的壓縮包
5,解壓縮包
tar jxvf linux-source-2.6.27.tar.bz2 //看清自己的版本
解壓後會生成一個源代碼目錄/usr/src/linux-source-2.6.27
6,進入源碼目錄後,配置文件
make oldconfig
7,生成內核
make
8,瘋狂等待,大約1個多小時
9,編譯模塊
make moles
10,安裝模塊
make moles_install
大功告成!^_^
下面說一下Makefile文件
$(MAKE) -C $(KERNELDIR) M=$(PWD) moles_install #PWD當前工作目錄的變數
obj-m := hello.o
#hello.o是你要生成的驅動,以後可以自己改
KERNELDIR:=/lib/moles/2.6.27-7-generic/build
#這里別抄,寫成你自己的版本,這個目錄執行了內核源碼目錄
PWD:=$(shell pwd) #將當前工作目錄賦值該PWD
moles:
$(MAKE) -C $(KERNELDIR) M=$(PWD) moles
moles_install:
下面是一個經典的Hello,world!例子自己make一下就行了。
#include <linux/init.h>
#include <linux/mole.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT"Goodbye, cruel world!\n");
}
mole_init(hello_init);
mole_exit(hello_exit);
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/unikingest/archive/2009/03/10/3977747.aspx
-----------------------------------------------------------------------------
修改的這篇文章,自己加了幾個注意點
http://blog.theosoft.net/article.asp?id=57
第一次的Linux kernel上機內容是編譯一個內核。我用的是Ubuntu,有很多地方和其它 Linux不一樣,所以就來把我的過程寫下來,以後也好有個參照
首先當然是下載內核源代碼,如果你要最新的內核,可以去ftp.kernel.org。當然,國內速度可能會很慢。如果你是教育網用戶,可以去上海交大的鏡像站下載,地址是http://ftp.sjtu.e.cn/sites/ftp.kernel.org/,缺點就是沒有最新的內核(更新需要一定的時間)。
==================================================備注
如果是就是編譯ubuntu本省自帶的內核,只需要
新立得搜索linux souce,下載帶ubuntupatch的kernel的source code。
sudo apt-get source linux-source-2.6.27
==================================================備注
我下載的是linux-2.6.19.2.tar.gz可以下到的最新版本了。下完之後當然是解壓縮。不過還不能直接編譯,因為Ubuntu的默認安裝里缺少必要的組建。打開終端,輸入一下命令:
sudo -i
apt-get install build-essential kernel-package libncurses5-dev
然後到新立得里把所有以ncurses開頭的軟體包全部裝上,這樣就可以開始編譯內核了。
先運行以下命令,復制當前內核的配置文件。
cp /boot/config-`uname -r` ./.config
然後
make menuconfig
選擇 "Load an Alternate Configuration File",再選擇你剛才拷貝過來的.config文件作為配置文件。然後確定。當結束後,你選擇退出時,會提示問你 "Do you wish to save your new kernel configuration?"選擇yes即可。
接下來就要編譯了。輸入命令:
make
你也可以將編譯任務分成2個線程來執行,只要輸入:
make -j2
編譯一般需要1~1.5小時左右,就看cpu的性能如何
編譯完成後,開始安裝:
make mole_install
make install
然後添加引導信息,不過之前還是要裝一個組件initramfs-tools,裝完以後輸入:
mkinitramfs -o /boot/initrd.img-2.X.XX /lib/moles/2.X.XX
==================================================備注
後面的參數不要忘記了,否則啟動新內核會出現錯誤:
WARNING: Couldn』t open directory /lib/moles/2.6.15.7-ubuntu1: No such file or directory
FATAL: Could not open /lib/moles/2.6.15.7-ubuntu1/moles.dep.temp for writing: No such file or directory
==================================================備注
最後打開 /boot/grub/menu.lst
在 ## ## End Default Options ## 下面添加類似下面的兩段
title Ubuntu, kernel 2.6.19.2
root (hd0,4)
kernel /vmlinuz-2.6.19.2 root=/dev/hdd6
initrd /initrd.img-2.6.19.2
savedefault
boot
title Ubuntu, kernel 2.6.19.2 (recovery mode)
root (hd0,4)
kernel /vmlinuz-2.6.19.2 root=/dev/hdd6 ro single
initrd /initrd.img-2.6.19.2
boot
注意 root和kernel欄位要模仿menu.lst下面已有的內容寫。下面是 (hd0,4),那麼你也寫(hd0,4),下面寫root=/dev/hdd6,你也寫root=/dev/hdd6,只是內核的版本號改為現在編譯的版本號。然後重新啟動計算機,在GRUB中選擇新內核啟動。如果啟動失敗,你可以重啟選擇老內核。
E. ubuntu下安裝virtualbox-3.2_3.2.6-63112_Ubuntu_lucid_amd64.deb,提示內核模塊編譯失敗
出現這種問題是因為內核頭文件包沒有安裝,用apt-get在線安裝這個包就可以了,在錯誤提示信息裡面有說明(log文件裡面的說明會更詳細)。這個包的名字是以linux-headers開頭的,先查詢包的完整名字(因為完整名字不同的內核版本都不一樣),再用apt-get install來安裝。
F. android.mk ubuntu怎麼編譯
一個Android.mk file用來向編譯系統描述你的源代碼。具體來說:該文件是GNU Makefile的一小部分,會被編譯系統解析一次或多次。你可以在每一個Android.mk file中定義一個或多個模塊。每個模塊屬下列類型之一:
1)APK程序,一般的Android程序,編譯打包生成apk文件
2)java庫,java類庫,編譯打包生成jar文件
3) CC++應用程序,可執行的CC++應用程序
4)CC++靜態庫,編譯生成CC++靜態庫,並打包成.a文件
5)CC++共享庫,編譯生成共享庫(動態鏈接庫),並打包成.so, 有且只有共享庫才能被安裝/復制到您的應用軟體(APK)包中。
(1)先看一個簡單的例子:一個簡單的"hello world",比如下面的文件:
sources/helloworld/helloworld.c
sources/helloworld/Android.mk
相應的Android.mk文件會像下面這樣:
---------- cut here ------------------
普通的.mk一樣
=====================================m、mm、mmm編譯命令===========================================
android源碼目錄下的build/envsetup.sh文件,描述編譯的命令
- m: Makes from the top of the tree.
- mm: Builds all of the moles in the current directory.
- mmm: Builds all of the moles in the supplied directories.
所以要想使用這些命令,首先需要在android源碼根目錄執行build/envsetup.sh 腳本設置環境。
m:編譯所有的模塊
mm:編譯當前目錄下的模塊,當前目錄下要有Android.mk文件
mmm:編譯指定路徑下的模塊,指定路徑下要有Android.mk文件
下面舉個例子說明,假設我要編譯android下的hardwarelibhardware_legacypower模塊,當前目錄為源碼根目錄,方法如下:
1、. build/envsetup.sh
2、mmm hardware/libhardware_legacy/power/
或者 :
1、. build/envsetup.sh
2、cd hardware/libhardware_legacy/power/
3、mm
m沒有試過。默認上述兩個編譯命令,只編譯發生變化的文件。如果要編譯模塊的所有文件,需要-b選項,例如mm -b或者mmm -b
make命令,也可以用來編譯。如果是include $(BUILD_PACKAGE),用makeLOCAL_PACKAGE_NAME值;如果是include $(BUILD_EXECUTABLE)或者include $(BUILD_JAVA_LIBRARY),用makeLOCAL_MODULE值(未驗證)。
G. ubuntu怎麼編譯nginx
先解壓nginx的tar包,進入解壓後的文件夾里,如果要安裝到其他路徑的話,修改configure文件里的prefix的值然後執行./configure,或者直接使用./configure --prefix=/xx/xx/xxx來指定,安裝路徑然後make -j2,如果你的處理器核多,可以增大數字,再然後就是make & make install了。
要注意的是./configure後面可以跟隨很多參數配置:
比如,需要的話可以加上--config-path=/xx/xx/xxx/nginx.conf指定nginx的伺服器配置文件路徑;
--add-mole增加模塊,比如luz、pagespeed、upstream等等,這些都可以在官網上查到。
H. ubuntu 環境下怎樣編譯pixhawk px4源碼
Ubuntu環境下Pixhawk原生固件PX4的編譯
分類:無人機ubuntu代碼編譯Pixhawk
(3946) (6)
Ubuntu下Pixhawk原生固件PX4的編譯這個問題困擾了兩天時間,可能是博主腦力不夠,主要是環境搭建不起來,主要原因應該是路徑的原因,最後在大師傅的幫助下還好成功將路徑搭建好,成功編譯。
下面就跟大家分享一下環境搭建的過程。
1.操作環境
每次寫文章,環境一定要介紹的,不同的環境總會出現不同的問題
我的環境是Windows下面安裝虛擬機,虛擬機跑Ubuntu
Windows:win10 64位
虛擬機:VMware Workstation 12 Pro 12.1.0 build-3272444
Ubuntu:Ubuntu15.10
2.編譯環境搭建
(1)許可權設置
官方提示:
Warning Never ever fix permission problems by using 'sudo'. It will create more permission problems in the process and require a system reinstallation to fix them.
意思是你會遇到許可權問題,不要用sudo解決,那樣會帶來更多問題,但是我沒聽他的,我沒用,最後也是實現了
官方提供指令
[plain] view plain
然後注銷,重新登錄生效
(2)安裝
更新包列表,安裝下面編譯PX4的依賴包。PX4主要支持的系列:
NuttX based hardware: Pixhawk, Pixfalcon
Snapdragon Flight hardware: Snapdragon
Raspberry Pi hardware: Raspberry Pi 2
Host simulation: jMAVSim SITL and Gazebo SITL
注意:安裝Ninja Build System可以比make更快進行編譯。如果安裝了它就會自動選擇使用它進行編譯。
[plain] view plain
卸載模式管理器
[plain] view plain
更新包列表和安裝下面的依賴包。務必安裝指定的版本的包
[plain] view plain
上面代碼中紅色部分大家需要一高警惕,gcc-arm-none-eabi版本導致PX4/Firmware編譯錯誤,現在apt-get安裝的gcc-arm-none-eabi基本上是4.9的版本,但是這個固件需要gcc-arm-none-eabi 4.8de 版本,所以最後安裝好以後,查看你的gcc-arm-none-eabi版本,如果是4.9需要手動安裝4.8的版本,安裝gcc-arm-none-eabi 4.8的版本的方法如下:
[plain] view plain
【Warning】上面紅色的路徑一定要添加正確,不然問題很多,我第一次就輸入錯誤,結果結果開不了機了,反復輸入密碼。博主裝的是Ubuntu 64位系統,而上述arm-none-eabi是直接下載的編譯好的32位,還需要安裝一個東西
[plain] view plain
可以檢查arm-none-eabi 4.8.4是否安裝成功,輸入以下指令:
[plain] view plain
如果出現如上信息,交叉編譯環境搭建就搭建成功了
(3)代碼編譯
根據PX4中文維基官網教程。
安裝Git
[plain] view plain
下載代碼
[plain] view plain
初始化
先進入Firmware文件夾,進而進行初始化、更新子模塊操作,耐心的等待……
[plain] view plain
許可權
編譯時會遇到許可權問題,執行指令
[plain] view plain
-R 是對文件下麵包含的子文件許可權問題,* 是對所有文件的許可權問題
編譯
[plain] view plain
注意到「make」是一個字元命令編譯工具,「px4fmu-v2」是硬體版本,「default」是默認配置,所有的PX4編譯目標遵循這個規則。
最後附一張編譯成功的代碼,如果這樣你還有問題,請給我留言。
[plain] view plain
-- nuttx-px4fmu-v2-default
-- The ASM compiler identification is GNU
-- Found assembler: /opt/gcc-arm-none-eabi-4_8-2014q3/bin/arm-none-eabi-gcc
-- Found pythonInterp: /usr/bin/python (found version "2.7.10")
-- Using C++03
-- Release build type: RelWithDebInfo
-- Adding UAVCAN STM32 platform driver
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lihongwei/Documents/Firmware/build_px4fmu-v2_default
#+@Tools/check_submoles.sh
PX4 CONFIG: px4fmu-v2_default
Scanning dependencies of target git_mavlink
Scanning dependencies of target git_uavcan
Scanning dependencies of target git_gencpp
Scanning dependencies of target git_genmsg
[ 0%] Generating git_init_mavlink_include_mavlink_v1.0.stamp
[ 0%] Generating git_init_src_moles_uavcan_libuavcan.stamp
[ 0%] Generating git_init_Tools_genmsg.stamp
[ 0%] Generating git_init_Tools_gencpp.stamp
[ 0%] Built target git_uavcan
[ 0%] Built target git_mavlink
[ 0%] Built target git_genmsg
[ 0%] Built target git_gencpp
I. ubuntu下怎麼編譯linux內核
Ubuntu 系統
1. 准備工作
切換為管理員許可權,sudo –i 輸入用戶密碼 進入root 許可權
apt-get install build-essential kernel-package libncurses5-dev libqt3-headers
build-essential (基本的編程庫(gcc, make 等)
kernel-package (Debian 系統里生成 kernel-image 的一些配置文件和工具)
libncurses5-dev (meke menuconfig 要調用的)
libqt3-headers (make xconfig 要調用的)
2. 下載特定版本的內核源代碼
3. 復制源碼linux-3.2.12.tar.bz2 到/usr/src 目錄,解壓縮
命令.假設源碼存放在/home 目錄下
cp /home/linux-3.2.12.tar.bz2 /usr/src
cd /usr/src
tar xvjf linux-3.2.12.tar.bz2
解壓後生成 linux-3.2.12 目錄
4. cd linux-3.2.12
接下來配置內核選項
make menuconfig 這一步比較復雜,內核選項很多,可以使用當前內核的配置選項,
但編譯內核的時間會比較長,因為裝系統的時候使用的配置是適應大多數系統的,非定
制選項。關於內核配置選項怎麼定製,網上很多。
5. 把正在使用系統中的內核配置文件/usr/src/linux-headers-2.6.38-13-generic/.config 拷到
/usr/src/linux-3.2.12 目錄下
cp /usr/src/ linux-headers-2.6.38-13-generic/.config /usr/src/ linux-3.2.12
執行:
cd /usr/src/ linux-3.2.12
make menuconfig
終端會彈出一個配置界面
注意主菜單最後有兩項:
load a kernel configuration…
save a kernel configuration…
先選第一項load ….,意思是,利用當前的內核配置詳單來設置將要編譯的內核,然後選save 這一項保存,最後退出配置界面
6. 開如編譯安裝新內核
執行:make mrproper (清除以前曾經編譯過的舊文件,如果是第一次編譯,可不執行)
執行:make (編譯,加-j4,必須加,雙核並行編譯,速度快很多,不過使用原先配置
選項)
然後:make install
再:make moles (編譯模塊)
再:make moles_install (安裝模塊)
最後創建initrd 文件:
mkinitramfs -o /boot/initrd.img-linux-3.2.12
7. make install 以後,系統自動更新了啟動項,可以cat /boot/grub/grub.cfg 看下.之前的啟動項不能刪除,如果編譯內核不成功,之前的啟動項又不見了,系統也就跪了
8. reboot
J. Ubuntu虛擬機里怎麼編譯內核
方法/步驟
」Ctrl+Alt+T」進入終端,使用命令 sudo passwd root 啟動root賬號,重啟,使用 su 命令獲得root許可權;
安裝編譯內核所需軟體包
# apt-get update
# apt-get install build-essential kernel-package libncurses5-dev fakeroot 選擇Y
下載3.19.3源碼包並解壓
# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.3.tar.xz
# tar -Jxvf linux-3.19.3.tar.xz
配置內核
# cd linux-3.19.3 (cd命令進入源碼目錄)
# make mrproper (得到源代碼後,將其凈化)
# make menuconfig (對內核選項進行配置,不需要配置,直接enter)
# cp /boot/config-'uname -r'-generic ./.config ('uname -r'-generic指現版本內核)
# make clean (刪除配置時留下的一些不用的文件)
編譯內核(需要很長時間,我用了有兩小時,請耐心等待)
# make bzImage
# make moles (編譯模塊)
安裝新內核
# make moles_install (安裝模塊)
# make install
製作啟動盤
# sudo mkinitramfs 3.19.3 -o /boot/initrd.img-3.19.3
更新grub2
# sudo update-grub2
重啟,使用新內核(不是注銷哦,是重啟)
使用命令# uname -r 查看內核版本