Liuw’s Thinkpad

想要赢就先学会输,想要成功就先学会失败

Archive for the ‘linux’ tag

Building modules against installed kernel

without comments

I’ve been reading Linux Device Drivers 3rd for quite a long time, and once built a sacrifice system in VMWare. After I upgraded VMWare, the sacrifice kernel hangs, unable to discover root filesystem. It seems to be a driver issue. No matter how I compile my kernel, it hangs at the same place.

I finally give up, I don’t want to waste my time any more. Maybe I should just dump that 2.6.10 and try new ones. No need to

I have a Debian system working as my development system. I just need to install kernel header to get a module building environment.


# apt-get install linux-headers-`uname -r`

When it’s done, build directory should be found in


# ls -d /lib/modules/`uname -r`/build

Here is a handy Makefile for modules.


obj-m += hello.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Written by liuw

七月 16th, 2010 at 11:49 下午

Posted in UNIX-like

Tagged with , , , ,

Cheet sheet for locking

without comments

Pete Zaitcev gives the following summary:

  • If you are in a process context (any syscall) and want to lock other process out, use a semaphore. You can take a semaphore and sleep ( copy_from_user* or kmalloc(x,GFP_KERNEL) ).
  • Otherwise (== data can be touched in an interrupt), use spin_lock_irqsave() and spin_unlock_irqrestore().
  • Avoid holding spinlock for more than 5 lines of code and across any function call (except accessors like readb).

Read the rest of this entry »

Written by liuw

七月 14th, 2010 at 2:04 下午

Fix `apt-get update’ GPG Error

without comments

This is quite common when you add some non-official sources to ’source.list’.


gpg --keyserver hkp://wwwkeys.eu.pgp.net --no-default-keyring --primary-keyring /etc/apt/trusted.gpg --recv KEYID

Choose key server as you wish. The critical part is that we specify apt’s keyring, rather than creating our own. If we miss those key ring options, gpg(1) will create a folder .gnupg in home directory, which comes out to be our personal settings, not apt(8)’s.

Written by liuw

二月 8th, 2010 at 7:37 下午

Posted in UNIX-like

Tagged with , , , ,

Fix `apt-get update' GPG Error

without comments

This is quite common when you add some non-official sources to ’source.list’.


gpg --keyserver hkp://wwwkeys.eu.pgp.net --no-default-keyring --primary-keyring /etc/apt/trusted.gpg --recv KEYID

Choose key server as you wish. The critical part is that we specify apt’s keyring, rather than creating our own. If we miss those key ring options, gpg(1) will create a folder .gnupg in home directory, which comes out to be our personal settings, not apt(8)’s.

Written by liuw

二月 8th, 2010 at 7:37 下午

Posted in UNIX-like

Tagged with , , , ,

container_of

with 3 comments


#define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))

再来看看Linux Kernel中的实现。


#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define container_of(ptr, type, member) ({                      \
           const typeof( ((type *)0)->member ) *__mptr = (ptr); \
           (type *)( (char *)__mptr - offsetof(type,member) );})

Written by liuw

十二月 1st, 2009 at 10:47 下午

Posted in Programming

Tagged with , , ,

Linux Kernel Indent Style

without comments


$ indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl 

Written by liuw

十一月 17th, 2009 at 3:29 下午

Posted in Programming, 分享

Tagged with , , ,

選擇一個Linux發行版

without comments

很久都沒有用Linux了,近來搞Erlang覺得還是用Linux方便點。

考慮如下的發行版:

  • 省心的:Ubuntu
  • 好玩的:Gentoo,Arch
  • 實用的:CentOS
  • 早就沒有慢慢配置的時間和耐心了,所以很大可能還是在Ubuntu和CentOS里面選。

    Written by liuw

    七月 7th, 2009 at 9:34 上午

    Posted in UNIX-like

    Tagged with , , , ,

    为什么国产的 Linux 发行版不流行

    without comments

    按照道理来说,国产的 Linux 本地化支持更好,也更了解当地用户的习惯,这样的产品理应比较受欢迎。但是国产的红旗 Linux 等一些发行版本,在国内的流行程度却总不如 Fedora、Ubuntu、SuSE 这样的发行版。为何?

    个人认为,有以下的原因:

    1. 国产 Linux 推广力度不够,服务支持不够好。Fedora、Ubuntu 这样的发行版,背后都有一个很大的社区支撑。国内的发行版这个方面做得很不够。
    2. 国内的 Linux 发行版“自由”的味道淡了。由于中国不怎么尊重版权,所以对于 GPL 这样的协议,都没有得到应有的强调。很多 Linux 的爱好者,还是很看重“自由”的味道的。
    3. 偏见使然。很多人对国产 Linux 的认识还很片面。他们还停留在以前的一些不好的印象上面。我也犯了这个错误。近来我才发现,原来红旗也一直在进步,它的本地化真的已经是非常完美了。

    Written by liuw

    四月 26th, 2008 at 1:10 上午

    Posted in UNIX-like, 戏言

    Tagged with

    OpenSpirit 讲座的总结

    with one comment

    事情起因参见《被邀去介绍 Linux

    2008 年 4 月 19 日,武汉大学计算机学院网络部举办 OpenSpirit 讲座,向计算机学院的学生介绍 Linux 及开源相关的信息。鄙人不才,被邀为演讲者。活动结束后,让我就今天这次 OpenSpirit 讲座谈一下自己的几点感受和感想。

    先简要介绍一下今天活动的内容。活动分为两部分,一部分是讲座交流,一部分是现场体验。讲座部分有两个主题,一个是介绍 Linux 发展简史,另外一部分就是介绍 Linux 的应用、前景、对 CS 学生的好处以及一些学习建议。

    下面是我对于这些活动的一些感想和总结。

    Read the rest of this entry »

    Written by liuw

    四月 19th, 2008 at 9:54 下午

    Posted in UNIX-like, 生活

    Tagged with ,

    被邀去介绍 Linux

    with 4 comments

    昨天晚上,Martian 和我说他打算在院内搞一个介绍 Linux 讲座,同时还有体验 Linux 的活动,想找我去讲一下。面向对象主要是大一的学生。他的意思是至少让他们知道这个世界上还有这样的一个操作系统,而不是只有 Microsoft 一家独大。

    Read the rest of this entry »

    Written by liuw

    四月 14th, 2008 at 5:44 下午

    Posted in UNIX-like, 生活

    Tagged with , ,