原帖参见这里。
假设你编写的模块文件是mod.c
,编译会生成mod.o
文件。kernel
编译系统还会自动生成一个mod_kmod.c
文件(包含需要的kernel
数据结构),编译这个文件生成另一个object
文件。把mod_kmod.c
所新生成的object
文件和之前的mod.o
文件链接生成最后的mod.ko
文件。也就是可以被kernel
加载运行的模块文件。
原帖参见这里。
假设你编写的模块文件是mod.c
,编译会生成mod.o
文件。kernel
编译系统还会自动生成一个mod_kmod.c
文件(包含需要的kernel
数据结构),编译这个文件生成另一个object
文件。把mod_kmod.c
所新生成的object
文件和之前的mod.o
文件链接生成最后的mod.ko
文件。也就是可以被kernel
加载运行的模块文件。
原帖参见这里。
获得当前运行kernel
的配置信息的文件:
a)/proc/config.gz
(CONFIG_IKCONFIG_PROC
需要置成Y
)
b)/boot/config
c)/boot/config-$(uname -r)
对于每一种体系结构,都有一个kernel
主配置文件:arch/<arch>/Kconfig
。当执行make config/menuconfig/xconfig
命令时,如果当前kernel
根目录下没有.config
文件,则会读取Kconfig
文件。
Sometimes, you’ll change things so much that make can’t figure out how to recompile the files correctly. make clean will remove all the object and kernel object files (ending in .o and .ko) and a few other things. make mrproper will do everything make clean does, plus remove your config file, the dependency files, and everything else that make config creates. Be sure to save your config file in another file before running make mrproper. Afterwards, copy the config file back to .config and start over, beginning at make menuconfig. A make mrproper will often fix strange kernel crashes that make no sense and strange compilation errors that make no sense.
make clean
删除object
和kernel object
文件,还有其它一些文件。make mrproper
是make clean
的超集,它还会删除config
文件,依赖文件,以及其它make config
生成的文件。
首先看一下-j
选项在make
命令中的含义:
-j [jobs], --jobs[=jobs]
Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j
option, the last one is effective. If the -j option is given without an argument, make will not
limit the number of jobs that can run simultaneously.
也就是-j
指定并行工作的job
数量,例如make -j4
。如果-j
选项后面没有参数,则不会限制job
数。
再参考《Linux kernel development》:
By default, make spawns only a single job because Makefiles all too often have incorrect dependency information.With incorrect dependencies, multiple jobs can step on each other’s toes, resulting in errors in the build process.The kernel’s Makefiles have correct dependency information, so spawning multiple jobs does not result in failures.To build the kernel with multiple make jobs, use
$ make -jn
Here, n is the number of jobs to spawn. Usual practice is to spawn one or two jobs per processor. For example, on a 16-core machine, you might do
$ make -j32 > /dev/null
可以看到指定job
数是系统core
数量2
倍是一种推荐的做法。
kernel.org提供的就是vanilla kernel
,而不同的发行版可能会在这个原始的vanilla kernel
上做一些改动。例如,改个bug
,增加对新设备的支持,等等。
参考资料:
What is vanilla kernel
先介绍两个术语:
a)Standard(production)kernel
:正常使用的kernel
;
b)Crash(capture)kernel
:用来收集crash dump
的kernel
。
Kdump
有两个重要的组件:Kdump
和Kexec
:
a)Kexec
:
是一种fastboot mechanism
。Kexec
允许不通过BIOS
,而是从运行的kernel
中启动另一个kernel
,这样做速度很快,可以节省大量时间。
b)Kdump
:
是一种新的,可靠的crash dumping mechanism
。Crash dump
是从新启动的kernel
中去捕获,而不是从已经crashed kernel
中。当系统crash
后,Kdump
使用Kexec
启动第二个kernel
(Crash kernel
),而第一个kernel
(Standard kernel
)会保留一部分内存供第二个kernel
使用。由于Kexec
没有通过BIOS
启动第二个kernel
,因此第一个kernel
的内存得到保护,也就是最终的kernel crash dump
。
参考资料:
Linux Kernel Crash Book。
在这篇帖子中,提到pairs
和ipairs
的区别:
pairs() returns an iterator that will return the key and value of every key in the table, in no particular order. Usually, k and v are used to hold the key and value it returns. This is used to perform actions on each item in a table in turn, like when printing the contents of each value in the table.
ipairs() is very similar to pairs(), except that it will start at table[1] and iterate through all numerically indexed entries until the first nil value. It does this in order, which can be useful when you’re looking for the first item in a list that meets certain criterion.
pairs
遍历任意table
,返回的key
和value
没有什么顺序。而ipairs
只会返回key
是数字的元素。ipairs
通常用在访问数组上。
参考下面这个程序:
t = {hello = 100, 200, 300}
print("k, v in pairs:")
for k, v in pairs(t) do
print(k, v)
end
print("k, v in ipairs:")
for k, v in ipairs(t) do
print(k, v)
end
执行结果如下:
k, v in pairs:
1 200
2 300
hello 100
k, v in ipairs:
1 200
2 300
可以看到,pairs
可以遍历所有的key-value
对,而ipairs
只会访问key
是数字的元素。
这篇笔记来自于stackoverflow
的一篇帖子,答案如下:
From the documentation(http://www.kernel.org/doc/Documentation/devices.txt):
/dev/tty Current TTY device
/dev/console System console
/dev/tty0 Current virtual console
In the good old days /dev/console was System Administrator console. And TTYs were users' serial devices attached to a server.
Now /dev/console and /dev/tty0 represent current display and usually are the same. You can override it for example by adding console=ttyS0 to grub.conf. After that your /dev/tty0 is a monitor and /dev/console is /dev/ttyS0.
An exercise to show the difference between /dev/tty and /dev/tty0:
Switch to the 2nd console by pressing Ctrl+Alt+F2. Login as root. Type "sleep 5; echo tty0 > /dev/tty0". Press Enter and switch to the 3rd console by pressing Alt+F3.
Now switch back to the 2nd console by pressing Alt+F2. Type "sleep 5; echo tty > /dev/tty", press Enter and switch to the 3rd console.
You can see that "tty" is the console where process starts, and "tty0" is a always current console.
早些时候,/dev/console
是系统管理员控制台,而TTYs
则代表用户连接服务器的串行设备。而现在,/dev/console
和/dev/tty0
均指当前的显示设备,并且通常情况下是一样的。你可以修改/dev/console
所关联的设备。举个例子,在grub.conf
中加入console=ttyS0
。则现在,/dev/tty0
所关联的是显示器,而dev/console
则关联/dev/ttyS0
。
/dev/tty
是当前进程控制的tty
设备,而tty0
则是当前的控制台。当你在一个终端执行“sleep 5; echo tty0 > /dev/tty0
”命令后,切换到其它终端,则tty0
会在你切换后的终端显示。而执行“sleep 5; echo tty > /dev/tty
”命令后,无论切换到那个终端,tty
始终会在输入命令的终端显示。