顯示具有 linux 標籤的文章。 顯示所有文章
顯示具有 linux 標籤的文章。 顯示所有文章

星期三, 2月 19, 2014

perl warning for setting locale failed

Can't set locale; make sure $LC_* and $LANG are correct!
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US:en",
LC_ALL = (unset),
LC_TIME = "zh_TW.utf8",
LC_MONETARY = "zh_TW.utf8",
LC_MEASUREMENT = "zh_TW.utf8",
LC_NUMERIC = "zh_TW.utf8",
LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory
上面這情形發生在透過 ssh 連到遠端機器執行與 perl 相關的程式時所發生的。
古哥說下面這地方有解法
http://stackoverflow.com/questions/2499794/how-can-i-fix-a-locale-warning-from-perl

原因在於 /etc/ssh/sshd_config 中有一行設定
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
這表示 ssh client 可以把它的 locale 環境變數傳給 ssh server。
但若 ssh server 中沒有安裝該 locale,就會出現上面這樣的訊息。

所以解法有幾個:
從 server 端解:
1. 安裝該 locale
$ sudo dpkg-reconfigure locales

2. ssh server 不要接收從 ssh client 傳來的 locale 環境變數
 # Allow client to pass locale environment variables
 # AcceptEnv LANG LC_*
從 client 解:
執行 ssh 時,強制設定 LANG 的環境變數為 C
$ LANG=C ssh user@remote_server

星期二, 2月 28, 2012

如何在 Debian 6.0(Squeeze) 啟用 TRIM

大部份的 SSD 都支援 TRIM 命令。而要讓 TRIM 能夠正常運作,則需要作業系統及檔案系統的支援。在 Linux 的話,至少要 2.6.33 或是更新的版本,並使用 ext4 的檔案系統,並且在掛載檔案系統時以 "discard" 作為掛載參數,告訴 kernel 使用 TRIM。

Debian 6.0 預設安裝的是 2.6.32 的 kernel。要使用較新的 kernel ,我們不用改變到 testing 或 unstable;只要使用 squeeze backports 即可,將下面這行加到 /etc/apt/sources.list

deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

接著以下面指令更新套件清單

$ aptitude update 

要安裝新版的 kernel 只要下
$ sudo aptitude install -t squeeze-backports linux-image-2.6-amd64
(若你還在使用 32bit 的 debian ,則將 amd64 改為 i386 即可)

要啟用 TRIM 則還要將 discard 這個掛載參數加到 /etc/fstab 中,將 "errors=remount-ro" 改為 "errors=remount-ro,discard"。最後,重開機即可。

注意!若你仍使用 ext3 ,千萬不要將 discard 加入掛載參數中,這可能會讓你無法開機!

星期四, 3月 25, 2010

connect a windows network printer on ubuntu

在 Ubuntu 連接 windows 網路印表機

系統 - 管理 - 列印,新增
Network Printer - Windows Printer via SAMBA
smb:// 欄位填入 serverip/ ,瀏覽
點選所找到的印表機,確定
認證 - 現在設定認證詳情,將使用者名稱及密碼都填好,向前
由資料庫選擇印表機 - 廠牌 - 型號,向前
向前
套用
填入你本機 root 的密碼,確定(若你的 root 沒有密碼,就幫它設一個吧)
列印測試頁!
收工!!

星期四, 9月 10, 2009

Study LDD3 on Debian

在 Debian 上建立學習 Linux Device Driver 的環境

aptitude install build-essential
aptitude install linux-headers-2.6.30-1-686
aptitude install linux-headers-2.6.30-1-common
aptitude install linux-kbuild-2.6.30
如此會在 /usr/src 安裝好編繹 kernel module 的環境

接著按照 LLD3 上寫的第一個範例 hello.c
#include
#include
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");
}

module_init(hello_init);
module_exit(hello_exit);
為它編寫一個 Makefile
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR ?= /usr/src/linux
PWD := $(shell pwd)
RM = rm -rf
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
$(RM) *.ko *.o *.mod.c .*.cmd Module.* modules.* .tmp_versions
接著下 make 就可以編出 hello.ko 了 :D

星期一, 9月 08, 2008

How to build kernel module

要將某 driver 編成 kernel module
則其 Makefile 需要下面規則

obj-m += hello-1.o

all:
make -C M=$(shell pwd) modules

clean:
make -C M=$(shell pwd) clean

然後下 make 就可以了。

參考自
http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN121

星期五, 3月 28, 2008

安裝 Wine

以下參考自 WineHQ Howto

安裝 Wine for for Ubuntu, Debian, and Debian-based 的套件

加入 WineHQ APT 檔案庫

首先,加入 WineHQ 檔案庫的 key 到系統,使系統信任來自 WineHQ 的檔案
$ wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | sudo apt-key add -


For Debian Etch (4.0):
$ sudo wget http://wine.budgetdedicated.com/apt/sources.list.d/etch.list -O /etc/apt/sources.list.d/winehq.list


安裝 Wine
$ sudo aptitude update

$ sudo aptitude install wine


設定 wine
$ winecfg



以 wine 執行 win32 程式
$ wine win32app

星期三, 3月 12, 2008

O’Reilly, “Linux Device Drivers” 的讀法

以下摘自 Jollen 的 Howto Learn Linux Device Driver

O’Reilly, “Linux Device Drivers” 的讀法

如果您是Linux驅動程式的初學者,想要以這本書來自學驅動程式,又要在最短時間內掌握整個Linux驅動程式的精神,那麼有幾個方向提供您做參考:
  • 不要依照章節順序來閱讀
  • 不要地毯式的閱讀(即:不要依照章節與段落順序)
這本書的觀念解釋的非常清楚,但是最主要的Linux驅動程式觀念都在字元型驅動程式的章節裡,因此依照字元型驅動程式的主題來閱讀會比較適當。建議順序如下:

  1. Virtual File System (VFS)
  2. 'open' and 'release' system calls
  3. 'open' and 'release' driver function
  4. Wait Queues
  5. Blocking and Nonblocking read/write
  6. kmalloc(), copy_to_user(), copy_from_user()
  7. I/O ports
  8. ioctl()
  9. 'ioctl' driver function
  10. Reentrant codes (function)
  11. Semaphore
  12. Kernel Timer, Asynchronous Notification
  13. Pre-Defined Task Queues
  14. User-Defined Task Queues
  15. Writing an Interrupt Handler
  16. PCI Device Driver
  17. Spinlocks
  18. Bottom-half and Tasklets

此建議順序即是Jollen教育訓練課程所使用的投影片主題順序,自學的朋友,應該參考此建議順序,規劃一套屬於自己的閱讀計畫,如此便能加速學習Linux驅動程式。


結語
我們條列說明Linux驅動程式的核心觀念,以利讀者掌握學習方向:

  1. Device file 是user application與Linux驅動程式溝通的媒介。
  2. Device file 有一個不重覆的識別號碼,稱為major number,並有自己的minor number用來表示自己的子裝置。
  3. 不同的Linux驅動程式,均「支援」一個device file;更精確的說法是,不同的Linux驅動程式,均「對應」一個「major number」。
  4. Device file 即是VFS層。
  5. Linux驅動程式的核心為file operations,此即「Linux 驅動程式物件」。
  6. User application透過system call與device file 來與驅動程式溝通,user application必須先呼叫open system call來「開啟驅動程式」。
  7. 不同的system call C函數,會透過Linux kernel對應,並由Linux kernel callback驅動程式裡相對應的 system call實作函數。
  8. 驅動程式裡個別的system call實作函數,是由file operations所定義的。
  9. File operations 即struct file_operations,struct file_operations定義system call的名稱與實作函數的對應,此對應關係使用「函數指標」來實作。

星期六, 12月 29, 2007

Bridge Host OS and Guest OS network interface

通常 VirtualBox 的 Guest OS 的網卡預設是使用 NAT ,透過 Host OS 的網卡連至 Internat。
這時候兩張網卡是分別在不同網段。在某些情形下,我們會想要它們是在在同一網段下,這時我們可以將兩張網卡做橋接,也就是 bridge 兩張網卡。以 Debian 為Host OS 做例子,做法如下,

建立一個軟體虛擬的網路介面 tap0
# tunctl -t tap0 -u user_will_own_tap0
# chmod 666 /dev/net/tun


讓 eth0, tap0 進入 promisc 模式,使能收到到所有封包。
# ifconfig eth0 0.0.0.0 promisc
# ifconfig tap0 0.0.0.0 promisc


建立一個軟體虛擬的橋接器 br0,並將 eth0 及 tap0 加入其中
# brctl addbr br0
# brctl addif br0 eth0
# brctl addif br0 tap0


設定橋接器的 IP address, routing table, DNS,有兩種做法,一是交由 dhclient,
# dhclient br0


或是手動設定

# ifconfig br0 Static_IP netmask 255.255.255.0 up
# route add default gw Gateway_IP
# cat "nameserver DNS_IP" > /etc/resolv.conf


接下來 VirtualBox 的 Guest OS 的
網路-配接卡0-啟用網路卡-附掛到->主端介面
同頁面的主機介面設定值-介面名稱-> tap0

星期三, 12月 19, 2007

如何看 README.gz

有些說明文件是以 .gz 的型式存在系統上的。除了先以 gunzip 將之解開再看,還可以這樣看:
zcat README.gz | less