Wednesday, November 3, 2010

How to: Compile Linux kernel modules

How to: Compile Linux kernel modules

by LinuxTitli
(Link http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html)

This is one the essential and important task. Many time we upgrade our kernel and some recompiled drivers won't work with Linux. Especially if you have weird hardware; then vendor may send you driver code aka C files to compile. Or even you can write your own Linux kernel driver. Compiling kernel driver is easy. Kernel 2.6.xx makes it even much more easier. Following steps are required to compile driver as module:

1) You need running kernel source code; if you don't have a source code download it from kernel.org. Untar kernel source code (tar ball) in /usr/src using tar command:
$ tar -zxvf kernel* -C /usr/src

To be frank kernel headers are more than sufficient to compile kernel modules / drivers. See how to install kernel headers under Debian / Ubuntu Linux or RHEL / CentOS / Fedora Linux.

2) Next go to your kernel module source code directory and simply create the Makefile file as follows (assuming your kernel module name is foo):
$ vi Makefile

3) Add following text to it:

obj-m = foo.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) Compile module using make command (module build can be done by any user) :
$ make
It will finally creates the foo.ko module in current directory. You can see all actual compile command stored in .foo* files in same directory.

5) Once module compiled successfully, load it using insmod or modprobe command. You need to be root user or privileged user to run insmod:
# insmod foo.ko
Example: hello.c module

1) hello.c C source code. Copy following code and save to hello.c
$ mkdir demo; cd demo
$ vi hello.c

2)Add following c source code to it:

#include /* Needed by all modules */
#include /* Needed for KERN_INFO */
#include /* Needed for the macros */

static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);

This is an example modified from original source for demonstration purpose.

3) Save the file. Create new Makefile as follows:
$ vi Makefile
Append following make commands:

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) Save and close the file.

5) Compile hello.c module:
$ make

6) Become a root user (use su or sudo) and load the module:
$ su -
# insmod hello.ko

Note you can see message on screen if you are logged in as root under run level 3.

7) Verify that module loaded:
# lsmod | less

8) See message in /var/log/message file:
# tail -f /var/log/message

9) Unload the module:
# rmmod hello

10) Load module when Linux system comes up. File /etc/modules use to load kernel boot time. This file should contain the names of kernel modules that are to be loaded at boot time, one per line. First copy your module to /lib/modules/$(uname -r)/kernel/drivers. Following are suggested steps:

(a) Create directory for hello module:
# mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
(b) Copy module:
# cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
(c) Edit /etc/modules file under Debian Linux:
# vi /etc/modules
(d) Add following line to it:
hello
(e) Reboot to see changes. Use lsmod or dmesg command to verify module loaded or not.
# cat /proc/modules
OR
# lsmod | less

Saturday, July 24, 2010

Cài đặt MySQL Server 5 trên Ubuntu



Cài mysql server:

#sudo apt-get install mysql-server

Cài module PHP cho mysql nếu dùng php:

#sudo apt-get install php5-mysql

Kiểm tra thử tạo mới 1 database dùng mysqladmin:

#mysqladmin create < databasename >

Cài đặt Apache web server:

#sudo apt-get install apache2

Cài đặt PHP 5
#sudo apt-get install php5

#sudo apt-get install libapache2-mod-php5

Restart apache server:
sudo /etc/init.d/apache2 restart

MYSQL:

Start MySql server:

#/etc/init.d/mysql start

Stop MySql server:

#/etc/init.d/mysql stop

Restart MySql server:

#/etc/init.d/mysql restart

Kiểm tra trạng thái của MySql server:

#/etc/init.d/mysql status


Sunday, July 4, 2010

Ubuntu Server



1. Install SSH:

Type the following two command to install both ssh client and server:

#sudo apt-get install openssh-server openssh-client

Start SSH Server:
# sudo /etc/init.d/ssh start


Stop SSH Server:
# sudo /etc/init.d/ssh stop


Restart SSH Server:
# sudo /etc/init.d/ssh restart

2. Installing and setting TFTPD in Ubuntu
- Install tftpd and related packages.

$ sudo apt-get install xinetd tftpd tftp

- Create /etc/xinetd.d/tftp and put this entry:

service tftp
{
protocol = udp
port = 69
socket_type = dgram
wait = yes
user = nobody
server = /usr/sbin/in.tftpd
server_args = /tftpboot
disable = no
}

- Make /tftpboot directory

$ sudo mkdir /tftpboot
$ sudo chmod -R 777 /tftpboot
$ sudo chown -R nobody /tftpboot

- Start tftpd through xinetd

$ sudo /etc/init.d/xinetd start

Or

$ sudo /etc/init.d/xinetd restart

3. NFS Server
- In order to set NFS server you need to install the following packages:

=> nfs-kernel-server - Linux NFS Server

=> nfs-common - NFS Common programs

=> portmap - The RPC portmapper

- Use apt-get command to install all required packages:

$ sudo apt-get install nfs-kernel-server portmap nfs-common

- Sharing directory with /etc/exports

$ sudo vi /etc/exports

To export /data directory to 192.168.1.0/24 network enter the following
in /etc/exports file:
/data 192.168.1.0/24(rw,rsync)

To export /sales to hostname tom and jerry, enter:
/sales tom(ro,sync) jerry(ro,sync)

To export /users to 192.168.1.0/24 in read write format, enter:
/users 192.168.1.0/24(ro,sync) jerry(rw,fsid=0,insecure,no_subtree_check,async)

/AMCC/ppc_4xx *(rw,no_root_squash,no_all_squash,sync,no_subtree_check)

Where,

* rw : Allow clients to read as well as write access
* ro : Read only access
* insecure : Tells the NFS server to use unpriveledged ports (ports > 1024).
* no_subtree_check : If the entire volume (/users) is exported, disabling
this check will speed up transfers.
* async : async will speed up transfers.

Save and close the file. Just restart nfs-server:
$ sudo /etc/init.d/nfs-kernel-server restart

Now your NFS sever is sharing /sales and /data directories.


Saturday, July 3, 2010

Ubuntu (TT)



4. Grub2

Cài đặt:
$ sudo apt-get install grub2

Link


5. Phầm mềm chỉnh sửa & ghi CD & DVD:

- Phần mềm chỉnh sửa đĩa ISO: ISO Master. Có thể cài đặt bằng cách vô
Ubuntu Software Center gõ ISO Master or bằng lệnh sau:

sudo apt-get install isomaster

- Phần mềm ghi đĩa: K3B, Brasero, GnomeBaker ... & google :D
Cách cài thì tương tự như trên.


Wednesday, June 30, 2010

Ubuntu ...



1. Dùng alias để tạo lệnh mới trên Ubuntu:

Thêm vào dòng lệnh alias vào file ~/.bashrc.

Ví dụ:

alias ls='ls --color=auto -hF'
alias ll='ls --color=auto -lhF'
alias la='ls --color=auto -lahF'
alias grep='grep --color=auto'
alias diff='diff -rBNup'

Sau đó tắt terminal đi, mở lại. Bây giờ ta có thể dùng lệnh la tương đương
với gõ ls --color=auto -lahF,
or grep thì tương đương với gõ grep --color=auto, ...

2. Tăng tốc cho Ubuntu:
2.1 Disable IPV6 Ubuntu:
Cách 1: Thay đổi nội dung file aliases

sudo vi /etc/modprobe.d/aliases

Tìm dòng alias net-pf-10 ipv6
Sau đó đổi thành alias net-pf-10 off (Or aliases net-pf-10 off ipv6)

Save file and reboot.

Cách 2: Disable trên Firefox

Vào thành address bar: Gõ about:config search từ network.dns.disableIPv6,
sau đó nhấn chuột phải đổi thành TRUE

Cách 3: Thay đổi file /etc/default/grub

sudo vi /etc/default/grub

Tìm
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
Sau đó đổi thành
GRUB_CMDLINE_LINUX_DEFAULT=”ipv6.disable=1 quiet splash”

Save lại.

Sau đó update grub

sudo update-grub

2.2 Tăng tốc quá trình khởi động:
Code:
sudo vi /etc/init.d/rc

Sửa dòng CONCURRENCY=none thành CONCURRENCY=shell là hoàn tất.
Nhớ lưu file lại & reboot

2.3 Đẩy dữ liệu lên RAM
Thủ thuật này đặc biệt hiệu quả khi bạn có nhiều RAM (tầm 512MB trở lên).
Thủ thuật này sẽ giảm số lần ghi dữ liệu tạm lên ổ cứng, thay vì vậy sẽ
ghi dữ liệu tạm vào ram càng nhiều càng tốt.

Bạn chạy lệnh:

Code:

sudo gedit /etc/sysctl.conf


Sau đó thêm dòng vm.swappiness=10 vào cuối file rồi lưu lại.
Từ lần khởi động sau thiệt lập sẽ được thực hiện mặc định.
Khi không có dòng này thì giá trị mặc định là 60, bạn có thể thay
bằng 5 nếu có nhiều hơn 1GB ram, và đặt về 0 nếu thích, khi đặt về 0
thì Linux sẽ giảm thiểu tối đa việc sử dụng đĩa cứng lưu dữ liệu tạm.

3. Cài đặt Ubuntu từ đĩa USB di động:

Link


(Còn nữa).

Các chương trình tiện ích nên cài cho Ubuntu



1. Phần mềm hổ trợ download:
Dùng DownThemAll (1 add-on của Firefox): Vào Tools->Add-ons->
DownThemAll nhấn Enter để search, sau khi tìm thấy thì bấm
Add to Firefox để cài đặt.

(Còn nữa)


Monday, June 28, 2010

Mất biểu tượng ứng dụng ở System Tray Ubuntu

Cách khắc phục lỗi biến mất biểu tượng ở thanh System Tray mặc dù kiểm tra
trong System->Administration->System Monitor->Processes ứng dụng đó vẫn
đang chạy.

Cách đơn giản: Click chuột phải vào thanh System Tray chọn
Add to panel... -> Notification Area -> Click Add để hiển thị vùng
Icon thuộc dạng Notification như Skype, Scim, GodenDict, ...


Sunday, June 27, 2010

Cài đặt bộ gõ tiếng Việt Scim-Unikey cho Ubuntu 10.4

Cài đặt:
sudo apt-get install scim scim-bridge*

Cài đặt:Kích hoạt bộ gõ:

Vào terminal gõ vào lệch sau:

im-switch -s scim-bridge

Có 2 IME hỗ trợ tiếng Việt khá tốt hiện nay là Scim-Unikey và scim-m17n
Sau đó cài đặt Scim-Unikey:

sudo apt-get update
sudo apt-get install scim-unikey


Hoặc cài đặt scim-m17n (Bộ gõ này chưa hổ trợ tốt cho việc gõ cuối từ thuận
tiện như scim-unikey)

sudo apt-get update
sudo apt-get install scim-m17n m17n-db m17n-contrib


Cách dùng Scim-Unikey:
Sau khi cài đặt thì sẽ có biểu tượng Scim ở góc trên phải màn hình (có thể
là góc dưới phải).

Chọn phương thức nhập:
- Click chuột trái vào biểu tượng gõ.
- Phím tắt: Ctrl + Space (default).

Click chuột phải biểu tượng
Show Command Menu để thay đổi cấu hình: Scim
Setup, Unikey Setup, ...


Tham khảo: Link



Install GoldenDict on Ubuntu


Gõ dòng lệnh sau để cài đặt từ điển GoldenDict:

sudo apt-get install goldendict

Truy cập link sau để download các bộ từ điển cho GoldenDict: Link

mtBab-VE-Edition-1.0

WordNet 3.0

mtBab-EV-finalrelease1