Gentoo Linux on T43 (17) VGA输出

接口 VGA 的输出可以利用xrandr 命令控制,这个软件包应该已经跟随xorg-x11安装好了。 通过xrandr 命令的输出,知道T43支持以下视频接口: VGA DVI LVDS S-video VGA接口在笔记本右侧,可外接显示器、投影仪等VGA 设备。 DVI接口在产品的spec中并没有声称支持,机身也找不到借口,但可以被检测到,猜测笔记本内可能存在相关的硬件。 LVDS就是内置的液晶屏接口。 S-video在USB接口旁边,我从未测试过。 xrandr...

接口

VGA 的输出可以利用xrandr 命令控制,这个软件包应该已经跟随xorg-x11安装好了。

通过xrandr 命令的输出,知道T43支持以下视频接口:

  • VGA
  • DVI
  • LVDS
  • S-video

VGA接口在笔记本右侧,可外接显示器、投影仪等VGA 设备。

DVI接口在产品的spec中并没有声称支持,机身也找不到借口,但可以被检测到,猜测笔记本内可能存在相关的硬件。

LVDS就是内置的液晶屏接口。

S-video在USB接口旁边,我从未测试过。

xrandr

不带参数的xrandr 命令会列出系统支持的视频接口名称和设备连接情况。

$ xrandr
Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 1400 x 1200
VGA-0 disconnected (normal left inverted right x axis y axis)
DVI-0 disconnected (normal left inverted right x axis y axis)
LVDS connected 1400x1050+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
1400x1050      50.0*+
1280x1024      59.9  
1024x768       60.0     59.9  
800x600        60.3     59.9  
640x480        59.9  
S-video disconnected (normal left inverted right x axis y axis)

用以下命令将视频输出发送到某个接口设备。

 $ xrandr --output VGA-0 --auto

用以下命令关闭某个接口设备的视频输出。

 $ xrandr --output VGA-0 --off

Fn+keys

下面的脚本用于Fn+F7 控制VGA 输出的转换,脚本会自动搜索connected 到VGA输出的设备(包含内置液晶屏LVDS;S-video可能会支持,但未做测试),并顺序将显示输出到每一个设备,同时关闭所有其它设备的输出,这其中还包含一个将所有设备打开的步骤,整个过程循环。

00001007)
# Fn + F7 (Switch VGA/DVI/LVDS/S-video)
default=LVDS
# 1: connected and online
# 0: connected but not online
# N: disconnected
# i.e. "VGA-0 0 DVI-0 N LVDS 1 S-video N"
#screen=$(/usr/bin/xrandr |awk '/connected| \+|\*\+/ { \
#            if (match($2, /^connected$/) > 0) {printf $1 FS; next} \
#            else if (match($2, /^disconnected$/) > 0) {print $1, "N"; next} \
#            else if (match($0,/\ \+/) > 0) {print "0"} \
#            else if (match($0,/\*\+/) > 0) {print "1"} }')
screen=$(/usr/bin/xrandr |awk '/connected| \+|\*\+/ { if (match($2, /^connected$/) > 0) {printf $1 FS; next} else if (match($2, /^disconnected$/) > 0) {print $1, "N"; next} else if (match($0,/\ \+/) > 0) {print "0"} else if (match($0,/\*\+/) > 0) {print "1"} }')
#screen="VGA-0 0 DVI-0 N LVDS 1 S-video N"
arr_output=($(echo $screen |xargs -n2 |awk '{print $2 == "N"?"":$1}')) # connected screens
arr_status=($(echo $screen |xargs -n2 |awk '{print $2 == "N"?"":$2}')) # 1: online; 0: offline
logger -t "$0" "Supported Output: $(echo $screen |xargs -n2 |cut -d' ' -f1 |xargs)"
logger -t "$0" "Connected Output: $(echo $screen |xargs -n2 |awk '{ if ($2 == 1) print $1"*"; else if ($2 == 0) print $1 }' |xargs)"
[[ $(echo ${arr_status[@]} |xargs -n1 |awk /1/ |wc -l) -eq ${#arr_status[@]} ]] && all_online=1
[[ $(echo ${arr_status[@]} |xargs -n1 |awk /0/ |wc -l) -eq ${#arr_status[@]} ]] && all_offline=1
if [[ $all_offline -eq 1 ]] ; then
xrandr --output $default --auto
return
fi
[[ ${#arr_output[@]} -ne ${#arr_status[@]} ]] && return 1
[[ ${#arr_output[@]} -le 1 ]] && return
i=0
while [[ $i -le ${#arr_output[@]} ]]
do
next=$((i + 1))
[[ $next -ge ${#arr_output[@]} ]] && next=0
if [[ ${arr_status[$i]} -eq 1 ]] ; then
if [[ ${arr_status[$i]} -eq 0 && $all_online -ne 1 ]] ; then
logger -t "$0" "Switching all outputs on: ${arr_output[@]}"
for output in ${arr_output[@]}
do
xrandr --output $output --auto
done
break
fi
logger -t "$0" "Switching ${arr_output[$next]} off"
xrandr --output ${arr_output[$next]} --auto
logger -t "$0" "Switching ${arr_output[$i]} on"
xrandr --output ${arr_output[$i]} --off
break
fi
i=$((i + 1))
done
;;
 

上面这段脚本用于acpi的事件处理,这部分内容请查看Fn + Keys

下载

以上脚本包含在/etc/acpi/default.sh ,请根据自己的情况提取使用。

参考资料

 

Gentoo Linux on T43 (16) 蓝牙传输文件

通过蓝牙,可方便的实现与其它设备交换文件,接驳蓝牙耳机,组建局域网,甚至利用蓝牙连接移动设备进行拨号。我的需求不多,仅实现了与其它蓝牙设备双向传输文件,下面是我用到的应用程序、方法以及资源。 配置内核 内核的配置参考了Thinkwiki。 应用程序 我用到了以下软件包: net-wireless/bluez-libs-3.36  (库文件) net-wireless/bluez-utils-3.36 (基础配置工具,蓝牙系统服务) dev-libs/openobex-1.3 (库文件) app-mobilephone/obex-data-server-0.3.2 (bluez-gnome依赖它) gnome-extra/gnome-vfs-obexftp-0.4 (bluez-gnome依赖它) ...

通过蓝牙,可方便的实现与其它设备交换文件,接驳蓝牙耳机,组建局域网,甚至利用蓝牙连接移动设备进行拨号。我的需求不多,仅实现了与其它蓝牙设备双向传输文件,下面是我用到的应用程序、方法以及资源。

配置内核

内核的配置参考了Thinkwiki。

应用程序

我用到了以下软件包:

  • net-wireless/bluez-libs-3.36  (库文件)
  • net-wireless/bluez-utils-3.36 (基础配置工具,蓝牙系统服务)
  • dev-libs/openobex-1.3 (库文件)
  • app-mobilephone/obex-data-server-0.3.2 (bluez-gnome依赖它)
  • gnome-extra/gnome-vfs-obexftp-0.4 (bluez-gnome依赖它) 
  • net-wireless/bluez-gnome-0.28 (Bluetooth applet, 文件传输gui)
  • net-wireless/gnome-bluetooth-0.11.0 (文件接收Daemon: gnome-obex-server)
  • app-mobilephone/obexftp-0.22 (命令行文件传输工具) 

Bluetooth applet 可以在蓝牙设备打开时自动运行,可以浏览附近的蓝牙设备,提供文件发送与接收的操作,并进行基础的蓝牙属性配置。

但Bluetooth applet的文件接收功能在我的电脑上遇到问题,无法收到其它设备的发送文件请求。为此需要安装 gnome-bluetooth,这事另外一个文件接收服务器(仅接收)。

obexftp 是一个命令行ftp工具,可选安装。

将以上软件包merge到系统,然会添加蓝牙的系统服务

# rc-update add bluetooth default 

gnome-obex-server 不会跟随蓝牙设备的开启自动运行,可以将其加入Gnome的启动session,令其跟随系统启动运行。

再进行接下来的配置。

配置文件

编辑修改/etc/bluetooth/hcid.conf ,对照修改黄底色的部分,密码88888改成自己的。

 options {
# Automatically initialize new devices
autoinit yes;
# Security Manager mode
#   none - Security manager disabled
#   auto - Use local PIN for incoming connections
#   user - Always ask user for a PIN
#
security auto;
# Pairing mode
#   none  - Pairing disabled
#   multi - Allow pairing with already paired devices
#   once  - Pair once and deny successive attempts
pairing multi;
	# Default PIN code for incoming connections
passkey "88888";
}
# Default settings for HCI devices
device {
# Local device name
#   %d - device id
#   %h - host name
name "BlueZ (%d)";
# Local device class
class 0x000100;
# Default packet type
#pkt_type DH1,DM1,HV1;
# Inquiry and Page scan
iscan enable; pscan enable;
# Default link mode
#   none   - no specific policy 
#   accept - always accept incoming connections
#   master - become master on incoming connections,
#            deny role switch on outgoing connections
lm accept;
# Default link policy
#   none    - no specific policy
#   rswitch - allow role switch
#   hold    - allow hold mode
#   sniff   - allow sniff mode
#   park    - allow park mode
lp rswitch,hold,sniff,park;
}

测试

配置完成之后,启动蓝牙系统服务。

# /etc/init.d/bluetooth start 

此时应该可以看到Bluetooth applet出现在托盘,右键选择发送文件,选择浏览到的目标设备,应该可以测试成功。

然后测试接收文件,从系统工具中运行Bluetooth File Sharing (即bluetooth-obex-server),托盘会出现另外一个图标。此时从其它蓝牙设备选择向这部电脑发送文件,应该可以收到确认请求。

Toggle 蓝牙开关

为了方便的开启/关闭蓝牙,我将以下脚本添加到acpi的事件处理当中,可以利用Thinkpad 的Fn+F5 toggle 蓝牙的开关。

/etc/acpi/default.sh

00001005)
# Fn + F5 (Bluetooth on/off)
# 2006-03-07 <pille@struction.de>
#
# acpi called script to toogle bluetooth
#
# get current bluetooth state
cat /proc/acpi/ibm/bluetooth |grep "^status:.*enabled" > /dev/null
if [ $? == 0 ] ; then
logger -t "$0" "bluetooth is on. switching it off."
logger -t "$0" "disabling bluetooth."
echo disable >/proc/acpi/ibm/bluetooth
else
logger -t "$0" "bluetooth is off. switching it on."
logger -t "$0" "enabling bluetooth."
echo enable >/proc/acpi/ibm/bluetooth
fi
;;

有关acp事件处理,请参考Fn + Keys获得详细信息。

有关命令行工具

以下几个是比较常用的命令行工具。

hcitool

hcitool 可用于蓝牙设备扫描,连接,认证等操作。

$ hcitool scan

如果输出扫描到的蓝牙设备名是乱码,可能是蓝牙设备与电脑环境编码不一致,可尝试将UTF-8 编码转换到GBK:

$ hcitool scan |iconv -f utf-8 -t gbk 

hciconfig

类似于ifconfig,可用于配置蓝牙设备,一般设备名为hci0。

# hciconfig hci0 

下载

以上脚本包含在/etc/acpi/default.sh ,请根据自己的情况提取使用。  

参考资料

 

升级到openoffice 2.3.1 宋体显示为方块

搜索了一下,不少朋友都遇到了类似的问题,2.4.0似乎也有同样的问题。经测试,上面的问题仅仅出现在我加入字体别名替换的配置下,问题可能是openoffice 以上版本不识别宋体(等遇到问题的字体)的英文字体名称。很多朋友的字体配置文件中指定了别名替换,比如将宋体替换为SimSun,这也包含在我推荐的字体配置文件中,而openoffice 无法识别替换后的字体名称SimSun,原因未知。 我的临时修补方法是注释掉相应的字体别名替换,openoffice中宋体显示恢复正常。 <!-- <match target="pattern"> <test name="family"> <string>宋体</string> </test> <edit name="family" mode="assign"> <string>SimSun</string>...

搜索了一下,不少朋友都遇到了类似的问题,2.4.0似乎也有同样的问题。经测试,上面的问题仅仅出现在我加入字体别名替换的配置下,问题可能是openoffice 以上版本不识别宋体(等遇到问题的字体)的英文字体名称。很多朋友的字体配置文件中指定了别名替换,比如将宋体替换为SimSun,这也包含在我推荐的字体配置文件中,而openoffice 无法识别替换后的字体名称SimSun,原因未知。

我的临时修补方法是注释掉相应的字体别名替换,openoffice中宋体显示恢复正常。

<!--
<match target="pattern">
<test name="family">
<string>宋体</string>
</test>
<edit name="family" mode="assign">
<string>SimSun</string>
</edit>
</match>
-->

另外的一个方法可尝试升级到openoffice 3.0。

vmware: 利用已有Windows 安装创建虚拟机

如果已有安装配置好的Windows 系统分区,将其转化为虚拟机文件,或者直接将虚拟机运行在其上,都是可能的,vmware 与另一个虚拟机软件VirtualBox 均支持此功能。 NOTE:VirtualBox 的开源版本 VirtualBox OSE 不支持直接在物理分区的系统上运行虚拟机,仅仅二进制分发版本支持此功能,当前版本:1.5.7。 无论如何,通过虚拟机启动物理分区上的操作系统,并同时希望某个时候还可以像平常那样直接从物理分区启动,实现这一目标的过程,以及使用的过程,都是带有一定的危险性,可能会导致无法修复的数据损失,这在两个软件的文档中都有提及。同时,因为软硬件环境的多样性,也可能无法成功实现从虚拟机的启动。 我选择克隆一份已有的Windows分区来创建虚拟机。下面介绍一下我的步骤以及使用的辅助工具。 所需软件 vmware-workstation 6.0.4 for...

如果已有安装配置好的Windows 系统分区,将其转化为虚拟机文件,或者直接将虚拟机运行在其上,都是可能的,vmware 与另一个虚拟机软件VirtualBox 均支持此功能。

NOTE:VirtualBox 的开源版本 VirtualBox OSE 不支持直接在物理分区的系统上运行虚拟机,仅仅二进制分发版本支持此功能,当前版本:1.5.7。

无论如何,通过虚拟机启动物理分区上的操作系统,并同时希望某个时候还可以像平常那样直接从物理分区启动,实现这一目标的过程,以及使用的过程,都是带有一定的危险性,可能会导致无法修复的数据损失,这在两个软件的文档中都有提及。同时,因为软硬件环境的多样性,也可能无法成功实现从虚拟机的启动。

我选择克隆一份已有的Windows分区来创建虚拟机。下面介绍一下我的步骤以及使用的辅助工具。

所需软件

  • vmware-workstation 6.0.4 for linux 安装文件
  • vmware-workstation 6.0.4 for linux Serial Number(30天评估
  • windows 98 启动盘,或者相应的.img 或者.iso 文件
  • windows 安装光盘,或者.iso 文件
  • ghost .img或者.iso文件

安装步骤

1. 安装vmware

# emerge -av1 vmware-workstation

NOTE: 安装完成之后,应该先读本地文档 ,尤其是Using Disks 一章,事实上,如vmware 这样,如行云流水一般组织的文档,非常少见。这些文档位于:

/opt/vmware/workstation/lib/help-manual/index.html

2. 选择运行虚拟机的用户(不要用root),将其加入vmware 组

# usermod -aG vmware yourusername 

3. 运行软件,输入Serial Number。

NOTE:如果运行软件遇到错误,可能需要重新emerge以下两个packages:

x11-libs/libview
x11-libs/libsexy

4. 按通常步骤创建一个Windows 虚拟机A。使用Windows 98 启动盘启动虚拟机。

5. 启动后,首先用fdisk 命令安需要分区虚拟机的磁盘,要求分区与想要克隆的物理分区在数量上相对应,并且至少要分别大于物理分区的已占用空间。

6. 重启虚拟机,格式化分区,Power Off 虚拟机。

7. 回到Linux 系统,接下来需要临时更改Windows 分区所在的磁盘的权限,将所有者由root 改为运行vmware 软件的用户。假设你的磁盘设备名为/dev/sda:

# chown yourusername /dev/sda*

在Linux 系统,确认Windows 所在分区当前没有在Linux 下挂载(mount),否则必须要umount 掉!才能进行接下来的步骤!

NOTE:如果使用udev,在Linux 系统重启后,修改的磁盘所有者会自动复原,也可以在下面克隆的步骤(10)完成之后,手工修改回来,以减少可能的风险。

# chown root /dev/sda*

8. 回到vmware,使用定制方式创建一个新的虚拟机B,选择使用物理磁盘以及单独的分区,并选择Windows 所在分区。保存退出,不必启动此虚拟机。

9. 回到前面创建的第一个虚拟机A的设定,在虚拟机中添加一个磁盘,选择已有的文件,并指向到虚拟机B 的vmdk 文件。保存,并使用windows 启动盘启动虚拟机A。

10. 配置虚拟机访问ghost 工具,在DOS 下运行ghost,进行分区到分区的克隆,源分区选择新添加的磁盘(来自于虚拟机B 的vmdk文件)中的分区,目标分区是前面使用fdisk 创建的相对应分区。一一克隆完毕。

在虚拟机A的设定中删除第9步新添加的磁盘,此时可以删除虚拟机B,并恢复/dev/sda* 的所有者为root。

NOTE: 如果使用DOS 的xcopy 命令代替ghost可能会遇到长文件名截短的问题,同时速度也更慢。

11. 配置虚拟机访问windows 安装文件,在DOS 下进入i386目录,运行winnt.exe启动系统安装程序,目标安装分区选择前面克隆的目标系统分区,待文件复制完毕,Power Off虚拟机。这步的目的是在目标系统分区写入Windows 引导记录。

12. 使用Windows 98 启动盘再次启动虚拟机,在DOS 下进入到系统分区根目录,一般会是C盘,需要编辑boot.ini,首先去除其系统/隐藏/只读 属性:

C:\> attrib -s -h -r boot.ini

编辑此文件:

C:\> edit boot.ini

13. 根据实际情况修改启动条目中的分区编号,使其符合虚拟机环境中的磁盘配置。修改默认启动条目,并删除windows 安装的启动条目,保存退出。

重启虚拟机,选择从硬盘启动。

如果顺利应该可以进入windows 启动界面,并启动成功。

14. 如果启动失败,可尝试进入安全模式。如果依然失败,可尝试重启Linux 系统,进入物理分区上的windows 系统,创建一个新的硬件profile作为backup,并在当前硬件profile 中,删去一些在虚拟机中不需要,或者认为可能引起问题的硬件,然后重启回到Linux 系统,从第7步重新做起,最后在虚拟机中使用修改后的硬件profile 尝试进行启动。

NOTE:当然,这一步也可以在第8步之前就准备好。

15. 启动成功后,可以在系统分区删除前面安装windows 导致的临时文件,比如:

C:\$win_nt$.~bt
C:\$win_nt$.~ls
...

 

Gentoo Linux: 我安装的软件

经过一段时间的磨合,Gentoo Linux使用起来已经很顺手,下面是我对一些常用软件的选择,采用与Windows 平台对照的方式列出。每一种软件Linux 下可能都有很多种选择,有的我进行过对比,有的直接就采用了我认为最合适的。 我的评论可能会比较主观,欢迎讨论! 用途/Windows 软件 Linux 软件 支持情况 MSN, Gtalk, Netmeeting, QQ, ICQ...

经过一段时间的磨合,Gentoo Linux使用起来已经很顺手,下面是我对一些常用软件的选择,采用与Windows 平台对照的方式列出。每一种软件Linux 下可能都有很多种选择,有的我进行过对比,有的直接就采用了我认为最合适的。 我的评论可能会比较主观,欢迎讨论!

用途/Windows 软件
Linux 软件 支持情况
MSN, Gtalk, Netmeeting, QQ, ICQ Pidgin-2.4.0 (old Gaim)

不支持语音、视频、群聊、Netmeeting

Gtalk: check SSL option in advanced tab page, mail notification works!

Kopete
功能丰富,支持视频、群聊、Netmeeting,但在我的环境经常crash,基本不用。
浏览器
Firefox
 
Skype
Linux 版
官方二进制代码发布
图片浏览
Gpicview 比gThumb更轻量化,用于不想启动Picasa 时
Picasa
Linux 版 通过Google 内部优化版wine支持
GoogleEarth
Linux 版
T43 上速度很慢,可能是我配置的问题(Windows 版很快)
MS Office
OpenOffice
 
Lotus Notes

Linux 版

T43 的配置运行Notes 7比较合适,版本8界面响应迟钝
光盘刻录
Brasero
Brasero 比Gnomebaker 更成熟易用
TotalCommander
Krusader
配合diff、打包压缩等工具
文本编辑器(开发)UltraEdit Emacs
emacs 学习笔记
文本编辑器(普通)   
gedit
 
P2P
aMule
 
金山词霸 StarDict
单词朗读可通过任何语音合成软件支持,比如:festival, WyabdcRealPeopleTTS
中文输入法
Scim
Gentoo Linux on T43 (6) 中文环境
Adobe Reader(PDF)
kpdf
       
Windows 远程桌面
grdesktop
Howto: linux远程连接windows | 品可的blog 
MS AcitveSync (PDA)
 
 
BeyondCompare(文本比较)

Meld

 
wine + BeyondCompare 用过的最好的文本比较工具
分区魔法师 PQ Magic

GParted

不支持系统分区调整,支持Windows 扩展分区resize
QTParted 
未测试
fdisk 手工修改分区表
 
股票
Gnome Invest Applet
使用Yahoo 数据,支持国外以及国内股票查询,可查看均线图
wine 0.9.60 + 招商证券全能版 v6.27(已升级至v6.33) (通信达软件)

行情与交易,除菜单条与右键菜单中文乱码,其它正常。

如果旧的wine 版本需要打补丁: Wine安装一些Windows软件的错误以及处理

HDAPS
tp_smapi, hdapsd, gnome_hdaps_applet
支持一块硬盘
Gentoo Linux on T43 (9) HDAPS 硬盘动态保护系统
RamDisk
tmpfs
Gentoo Linux on T43 (14) 内存虚拟盘加速系统
TTS 语音合成
festival 语音合成
WyabdcRealPeopleTTS 真人发声
蓝牙

bluez-utils
bluez-gnome
gnome-bluetooth

GUI文件发送/接收
Gentoo Linux on T43 (16) 蓝牙传输文件
VGA 输出 xrandr Gentoo Linux on T43 (17) VGA输出
红外
   
网上银行
Firefox
上海浦发银行动态密码网银(支持Firefox)
淘宝/支付宝
Firefox + alipay安全控件
淘宝、支付宝支持Firefox,但支付宝不支持数字证书(2008-11-06更新)
支付宝针对 Linux 下 Firefox 的安全控件
Thinkpad 指纹识别
thinkfinger-0.3
Gentoo Linux on T43 (10) Fingerprint Reader 指纹认证 
Intel CPU StepSpeed
acpi-cpufreq (kernel) 在我的T43 上当温度上升到60度左右,便强制降频到800MHz,目前已禁用
Web Java applet
USE: nsplugin
java
Gentoo Linux on T43 (12) Java 环境 
数据恢复/FinalData TestDisk
TestDisk 找回丢失的硬盘分区表
Thinkpad 热键
thinkpad-acpi (kernel) + acpid
Gentoo Linux on T43 (15) Fn + Keys
鼠标键盘即插即用
hal-0.5.10
xf86-input-evdev-1.2.0
xorg-server-1.4.0
Gentoo Forums :: 阅读主题 - x11-drivers/xf86-input-evdev-1.2.0 keyboard problem 
Linux 支持鼠标、键盘即插即用

虚拟机VMWare
VirtualBox
VMWare

VirtualBox 是开源项目,可以在物理Windows 安装之上直接建立vmdk虚拟机(Portage 版本不支持vmdk,到VirtualBox 项目主页自行下载)。

PowerDesigner 15 Beta 2
wine 1.1.0 + PowerDesigner 15 Beta 2 在linux 下运行PowerDesigner 15 Beta 2 

参考资源

Gentoo Linux on T43 (15) Fn + Keys

对于Linux 对Thinkpad Fn 组合键的支持的了解一直比较模糊,有很多内核中的支持以及软件包,不太清楚具体的分工以及关系,今天查阅了一些资料,试图清理一下自己的思路,也把自己的配置共享一下。 下面给一些包及内核Module加一些注释: 内核Thinkpad ACPI 在2.6.20 中叫做IBM ACPI,这里是它的项目主页。如果编译为module,名字为thinkpad_acpi,它的功能是把Fn 组合按键的事件export 到/proc/acpi(在kernel-2.6.24 中应该选择此项:[*] Deprecated /proc/acpi/event...

对于Linux 对Thinkpad Fn 组合键的支持的了解一直比较模糊,有很多内核中的支持以及软件包,不太清楚具体的分工以及关系,今天查阅了一些资料,试图清理一下自己的思路,也把自己的配置共享一下。

下面给一些包及内核Module加一些注释:

内核Thinkpad ACPI

在2.6.20 中叫做IBM ACPI,这里是它的项目主页。如果编译为module,名字为thinkpad_acpi,它的功能是把Fn 组合按键的事件export 到/proc/acpi(在kernel-2.6.24 中应该选择此项:[*] Deprecated /proc/acpi/event support ),但其并不负责处理事件,需要其它userspace 程序来处理。

app-laptop/tp_smapi

来自Tpctl 项目 ,将thinkpad 硬件的信息export 到sysfs,供其它程序使用,目前主要实现了电池管理和HDAPS的功能。Fn keys应该不需要这个软件包,但我一直使用patched kernel + tp_smapi 来驱动HDAPS。

包含moduels:

hdaps
thinkpad_ec
tp_smapi

app-laptop/thinkpad

也来自Tpctl 项目 ,但目前已经被上面的tp_smapi 所取代,除非使用很古老的笔记本(before 2001),应该不需要这个软件包。

sys-power/acpid

acpid需要配合thinkpad-acpi使用,它默认读取/proc/acpi/event 中的条目,并将其传递给事件处理脚本,作出相应动作,比如关闭屏幕、待机等。 这些条目由/etc/acpi/events/default 捕获,并传递给/etc/acpi/default.sh 处理,但默认的/etc/acpi/default.sh 功能十分有限,必须自己修改。

配置Fn+Keys

这里已经有人写好了一些常用脚本,我根据他的内容整理了一份default.sh,目前可以处理Fn+F3(关屏), Fn+F4(Suspend to ram), Fn+F5(开关蓝牙), Fn+F6(开关wifi),Fn+F7(Toggle VGA-out),Fn+F12(Suspend to disk) 。这个脚本会用到radeontool,如果系统没有这么命令,merge它(也可以使用xset,但需要自己更改default.sh)。

# emerge -av1 radeontool

另外,我注释了脚本中的xosd 命令,如果你有GUI 程序需要显示Fn控制程序的状态,那么可以去掉注释(需要merge xosd)

调试

共享一下调试Fn 组合键的方法,thinkpad_acpi 会将按键事件写入/proc/acpi/event,但acpid 运行时我们无法读取这个文件,先停掉服务:

# /etc/init.d/acpid stop

然后cat这个文件(确保module thinkpad_acpi 已经装载,或者内建在内核)

# cat /proc/acpi/event

接着按Fn 组合键,console 中会打印出事件条目,括号中是我的注释。default.sh 将解析这些条目,并调用不同的命令进行处理。

ibm/hotkey HKEY 00000080 00001001 (Fn+F1)
ibm/hotkey HKEY 00000080 00001002 (Fn+..)
ibm/hotkey HKEY 00000080 00001003
ibm/hotkey HKEY 00000080 00001004
ibm/hotkey HKEY 00000080 00001005
ibm/hotkey HKEY 00000080 00001006
ibm/hotkey HKEY 00000080 00001007
ibm/hotkey HKEY 00000080 00001008
ibm/hotkey HKEY 00000080 00001009
ibm/hotkey HKEY 00000080 0000100a
ibm/hotkey HKEY 00000080 0000100b
ibm/hotkey HKEY 00000080 0000100c (Fn+F12)
ibm/hotkey HKEY 00000080 00001018 (Access IBM)
ibm/hotkey HKEY 00000080 00001014 (Fn+Space)

在我这里,调整屏幕亮度、屏幕灯、音量几个按键thinkpad_acpi 似乎是捕获不到的,event 没有输出,但功能正常,是不是xmodmap 处理了?

另外,内核中还有一个ACPI Button 支持,如果编译为module,在rmmod thinkpad_acpi之后,并且已经装在button,诸如Fn+F4 的事件会被其捕获,同样写入/proc/acpi/event:

button/sleep SLPB 00000080 00000001
button/sleep SLPB 00000080 00000002

下载

使用default.sh 覆盖acpid 默认的文件/etc/acpi/default.sh 即可,/etc/acpi/events/default 不用更改。

更新了default.sh,加入了toggleVGA-out 的脚本。(2008-11-06)

更新 2008-04-09 

今天偶然发现hal (0.5.10)中已经包含全系列thinkpad 型号hotkey的policy 配置文件,包括最新的T/X 6系列,这个文件位于:/usr/share/hal/fdi/information/10freedesktop/30-keymap-module-thinkpad-acpi.fdi,对于T4  系列,有如下定义:

<match key="/org/freedesktop/Hal/devices/computer:system.hardware.version" contains="T4">
<append key="input.keymap.data" type="strlist">0x02:screenlock</append> <!-- Fn+F3 lock -->
<append key="input.keymap.data" type="strlist">0x03:sleep</append> <!-- Fn+F4 suspend -->
<append key="input.keymap.data" type="strlist">0x04:radio</append> <!-- Fn+F5 switch radio -->
<append key="input.keymap.data" type="strlist">0x06:switchvideomode</append> <!-- Fn+F7 switch video output device -->
<append key="input.keymap.data" type="strlist">0x0b:suspend</append> <!-- Fn+F12 hibernate -->
<append key="input.keymap.data" type="strlist">0x0f:brightnessup</append> <!-- Fn+Home -->
<append key="input.keymap.data" type="strlist">0x10:brightnessdown</append> <!-- Fn+End -->
<append key="input.keymap.data" type="strlist">0x13:zoom</append> <!-- Fn+Space -->
<append key="input.keymap.data" type="strlist">0x17:vendor</append> <!-- ThinkPad/ThinkVantage button -->
<append key="info.capabilities" type="strlist">input.keymap</append>
</match> 

我猜想如果使用这个配置文件,应该可以免去上面手工配置Fn keys的步骤,或者不再使用/proc/acpi/event 这个interface,代之使用经由hal 提供的事件绑定?

尝试将其copy 至/etc/hal/fdi/policy 或者/usr/share/hal/fdi/policy/10osvendor,然后重启/etc/init.d/hald 服务,同时关闭了可能与其冲突的acpid 服务,但并没有预期的作用。查看lshal,似乎也都符合配置文件:

$ lshal |grep input.product 
  input.product = 'ThinkPad Extra Buttons'  (string)
...
$ lshal |grep system.hardware.vendor
  system.hardware.vendor = 'IBM'  (string)
$ lshal |grep system.hardware.version
  system.hardware.version = 'ThinkPad T43'  (string)

继续关注这个问题。

下面添加了一篇Gentoo 配置的参考文章。

延展阅读

Linux 支持鼠标、键盘即插即用

xorg-server-1.4 发布了有一段时间,配合hal-0.5.10 以及evdev-1.2 可以支持鼠标、键盘的即插即用(hotplug)。 上一次的evdev 升级允许在xorg.conf 中仅仅指定Device 名称即可,不需要指定Driver,xorg 会自动搜索合适的驱动程序,这一此更彻底,在xorg.conf 中不需要进行任何InputDevice 有关的设置。 如果升级到了以上版本,可以修改xorg.conf 来使用hotplug 功能,修改非常简单,移除所有的InputDevice Section...

xorg-server-1.4 发布了有一段时间,配合hal-0.5.10 以及evdev-1.2 可以支持鼠标、键盘的即插即用(hotplug)。

上一次的evdev 升级允许在xorg.conf 中仅仅指定Device 名称即可,不需要指定Driver,xorg 会自动搜索合适的驱动程序,这一此更彻底,在xorg.conf 中不需要进行任何InputDevice 有关的设置。

如果升级到了以上版本,可以修改xorg.conf 来使用hotplug 功能,修改非常简单,移除所有的InputDevice Section 和相关行即可。

Section "InputDevice"
...
EndSection
Section "ServerLayout"
...
InputDevice	"Trackpoint" "CorePointer"
InputDevice "Logitech MX1000" "SendCoreEvents"
InputDevice	"Externel USB Mouse" "SendCoreEvents"
InputDevice	"Generic Keyboard" "CoreKeyboard"
EndSection

移除之后,重启X,我的trackpoint、无线鼠标都工作得很好,甚至罗技的四向滚轮也可以正常驱动(仅仅横滚的方向弄反了:) )。

Xake 在这个讨论中对这次升级做了一些更详细的描述,同时也澄清了一些问题。在升级到这些版本之后,有些人遇到了Up键与PrintScreen键混在一起的情况,也包括我,尝试了Xake 的清空所有自定义属性 的方法,但不奏效。最终Disable 了PrintScreen 键,Up键恢复正常,等待fix。

一点题外话,在升级后,很多人遇到了类似的问题,并且抱怨xorg, evdev, 或是hal,Xake 很乐于帮助人们解决问题,但一再强调:

HAL is not the problem. DBUS is not the problem. xf86-input-evdev is not the problem. You configuration is the problem.

的确,如果希望使用最易用的linux,那么应该选择Ubuntu,而不是Gentoo,而遇到了以上问题,也是因为指定了允许升级不稳定版的关键字 ~arch:

ACCEPT_KEYWORDS="~x86"

每一次emerge --sync,看到成百上千的包更新,心里都会莫名的感动,理解Xake,想起几篇老文章,翻出来:

 

TestDisk 找回丢失的硬盘分区表

分区表丢失 早晨启动笔记本,被告知未找到操作系统,有点心惊,用Linux 启动U盘引导系统,查看我的主硬盘设备:fdisk -l /dev/sda ,找不到任何分区,应该是分区表丢了,原因不知道。 从前使用Windows 软件FinalData 恢复过被快速格式化甚至重新分过区的硬盘数据,于是把硬盘拆下,装在第二块硬盘托架内,借了台thinkpad,装了FanalData,但发现它只能恢复文件,不能恢复分区表,而且对Linux 分区数据也无能为力。 恢复分区表 在尝试易我分区表医生未果之后,Google到这篇文章: 介绍一个 GPL 的分区表修复工具 TestDisk...

分区表丢失

早晨启动笔记本,被告知未找到操作系统,有点心惊,用Linux 启动U盘引导系统,查看我的主硬盘设备:fdisk -l /dev/sda ,找不到任何分区,应该是分区表丢了,原因不知道。

从前使用Windows 软件FinalData 恢复过被快速格式化甚至重新分过区的硬盘数据,于是把硬盘拆下,装在第二块硬盘托架内,借了台thinkpad,装了FanalData,但发现它只能恢复文件,不能恢复分区表,而且对Linux 分区数据也无能为力。

恢复分区表

在尝试易我分区表医生未果之后,Google到这篇文章: 介绍一个 GPL 的分区表修复工具 TestDisk | BT的花,找到TestDisk,下载了Windows 版,先读了一遍Using TestDisk 下面的文档,然后开始对故障硬盘进行Analyse ,但经过Deeper Search 之后,仅仅找前三个主分区,位于Windows 扩展分区内的两个对我而言最重要的逻辑分区未找到。记起帮助文档中介绍 Geometry下面可以调整柱面(C)、磁道(H)、扇区(S)、扇区size(SS)等参数,目前设定为:9730、255、63、512,将Head修改为240 (柱面数没有进行修改,TestDisk会自动读取剩余的柱面,如果需要计算的话,SS 不变,应该满足:new_C=9730*255/240),再次执行Analyse,TestDisk读出了所有的分区信息!

使用p 命令可以列出每个分区上的文件,经过仔细确认,分区信息无误之后,执行写入分区表。

修复MBR grub

装回硬盘,启动,屏幕左上角出现了几个字母后停住,估计是MBR grub 损坏,从U盘引导,mount 主硬盘的/boot 分区,进入/boot/grub 目录,执行grub,重新写入主硬盘MBR:

# grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit 

 

再次硬盘启动成功,进入系统,所有分区数据访问正常。

后记

如果有分区表备份,在这种情况下,可以使用Linux fdisk 按照原来的起止柱面,直接建立原类型分区,数据也同样可以找到。

看来备份分区表很重要,可以添加这样一条命令到crontab,来备份最近7天的分区表信息(还应该有机制自动将备份文件mail 出去或者同步到移动存储器,也可以scp 到本地硬盘以外的主机):

00 12 * * * fdisk -l > ~/.pt_backup_$(date '+%Y%m%d'); find ~ -name ".pt_backup_*" -mtime +7 -exec rm -f {} \;

TestDisk Windows 版本在系统安装有cygwin 的情况下,启动出错,大概是因为系统中的cygwin1.dll 版本更新,删除了TestDisk 解压目录中的cygwin1.dll 之后可正常启动TestDisk。

为软件作者实现了一个在Amazon的wish: The Engines of God,为了省运费,使用了amazon.fr,不过还好有Google 语言工具

延展阅读

Gentoo Linux: /var/db/pkg 这个文件夹很重要!

前段时间折腾tmpfs 文件系统,不小心弄丢了/var/db/pkg 下面所有的文件,在查资料的过程中,才了解这个文件夹的重要。 这个文件夹对于Gentoo 的作用,相当于Windows 应用程序的Uninstall 文件,所有通过Portage 安装的程序包信息都保存在这,每个程序包包含哪些文件,以及文件的路径信息是最重要的,缺少这些信息,将无法正常的卸载程序包,其他一些重要的信息丢失也导致Portage 系统混乱。 这个文件夹丢失,虽然系统中的应用程序可以照常运行,但却是最大的灾难,除非不再打算通过Portage 对包进行任何维护工作,比如升级,安装新的软件等。解决方法只有一个:重新merge 所有软件包,重新生成这部分信息。一般来说,系统中软件包的规模在几百,甚至上千个,里面还有一些重磅角色,全部重新编译一遍,可能需要几十个小时(OpenOffice 在我的T43 上花去10个小时进行编译)。 文件夹丢失后,我最初找到了这个讨论(en),参考hielvc...

前段时间折腾tmpfs 文件系统,不小心弄丢了/var/db/pkg 下面所有的文件,在查资料的过程中,才了解这个文件夹的重要。

这个文件夹对于Gentoo 的作用,相当于Windows 应用程序的Uninstall 文件,所有通过Portage 安装的程序包信息都保存在这,每个程序包包含哪些文件,以及文件的路径信息是最重要的,缺少这些信息,将无法正常的卸载程序包,其他一些重要的信息丢失也导致Portage 系统混乱。

这个文件夹丢失,虽然系统中的应用程序可以照常运行,但却是最大的灾难,除非不再打算通过Portage 对包进行任何维护工作,比如升级,安装新的软件等。解决方法只有一个:重新merge 所有软件包,重新生成这部分信息。一般来说,系统中软件包的规模在几百,甚至上千个,里面还有一些重磅角色,全部重新编译一遍,可能需要几十个小时(OpenOffice 在我的T43 上花去10个小时进行编译)。

文件夹丢失后,我最初找到了这个讨论(en),参考hielvc 写的脚本,希望通过读取/var/log/emerge.log 恢复丢失的信息,但这个方法只能恢复出系统中所有已安装软件包名称和版本信息,无法找回已安装文件的列表,能不能通过某个Gentoo 工具得到每个软件包默认的文件列表呢,答案应该是不可以,因为Gentoo 是一个定制性的系统,大部分文件都是编译后生成的,并没有一个默认的库能够告诉这些文件的具体信息。换句话说,我的/var/db/pkg 是唯一的,如果没有备份,只能重新编译一遍系统来生成它们,下面这个讨论中,didymos很清楚的解释了这个问题,也证实了我的想法:PANIC! I deleted /var/db/pkg

所幸,在把我的/var/db/pkg 放入内存之前,我留下一个备份,但随后,我merge了约50个软件包,这些信息被写入内存中的/var/db/pkg ,随后就在一次重启后彻底丢失了。

在具有备份的情况下,我使用以下步骤重建了/var/db/pkg,时间成本主要花费在重新merge 约50个软件包。

步骤

恢复备份的/var/db/pkg 文件夹

恢复之后,/var/db/pkg 代表了merge 50个包之前我的系统的状况,但我的系统实际多出了一些包,或者一些已存在包的升级。

找出/var/db/pkg 与实际系统的不一致

前面提到的hielvc 写的脚本可以派上用场,但hielvc 忽略了一些情况(emerge -> unmerge -> emerge again),结果可能并不准确,我重写了一个脚本rebuildpkgdb,用法:

# ./rebuildpkgdb -p
This is a dry-run, Nothing really changed.Done! Please check package.lst

这将得到系统中实际安装的所有包列表(包含版本),再使用下面命令获取/var/db/pkg 记录的列表。

#  find /var/db/pkg/ -type d |cut -d/ -f 5- |awk -F/ 'NF > 1' |sort > package.db

然后比较两个文件,找到以下包:

  1. 存在于package.lst,但不存在于package.db
  2. 存在于package.db,但不存在于package.lst
  3. 都存在,但版本不同(取 package.lst)

对于第一种情况,是因为我在/var/db/pkg 丢失之后,unmerge 了一些包,虽然emerge.log 显示unmerge 成功,但因为丢失/var/db/pkg,实际文件并没有从文件系统真正删除。

而后两种情况是我备份/var/db/pkg 之后,丢失的信息。

因此对于上面三种情况,都执行一次merge 即可。

remerge

将上个步骤取得的包列表格式化成类似下面的命令,重新merge一遍,这个过程将重建正确的/var/db/pkg。

# sudo emerge -av =app-admin/eselect-ctags-1.3 =app-admin/eselect-wxwidgets-0.8 \
=app-admin/sudo-1.6.9_p14 =app-editors/emacs-22.1-r3 ...
These are the packages that would be merged, in order:Calculating dependencies... done![ebuild  N    ] sys-fs/mtools-3.9.10  USE="X" 0 kB [ebuild     U ] kde-base/kpdf-3.5.9 [3.5.8] USE="xinerama -arts -debug -kdeenablefinal" 0 kB [ebuild     U ] kde-misc/krusader-1.80.0-r1 [1.80.0] USE="xinerama -arts -debug -javascript -kde" 0 kB [ebuild  N    ] sys-boot/syslinux-3.52  0 kB  ...Total: 49 packages (42 upgrades, 6 new, 1 in new slot), Size of downloads: 3 kBWould you like to merge these packages? [Yes/No] 
检查系统

列出那些在/usr/lib/portage/world,但不在/var/db/pkg 中的软件包:

# emaint --check world 

如果上面命令找到了任何包,那么应该先merge 它们,如果事实不需要它们,再进行unmerge ,这样可以保证world, /var/db/pkg/, 以及文件系统三者的一致性。

revdep-rebuild

最后执行revdep-rebuild 查找系统中的任何共享库以及依赖关系的缺失,如果需要,会自动merge 需要的软件包。这个命令可能需要运行多次,直到没有任何问题发现为止。

# revdep-rebuild 

如果没有/var/db/pkg 备份

这是个很不幸的状况,如果真正希望world, /var/db/pkg/, 以及文件系统这三者具有一致性,那么似乎没有别的选择,找个空闲时间依次执行下面的命令,来重建/var/db/pkg

# emaint --check world# emerge -e system# emerge -e world# revdep-rebuild 

这个过程可能很漫长,视机器的速度,如果有其他Gentoo 系统可以利用,那么可以尝试分布式编译来节省时间。 

延展阅读

Gentoo Linux: Subversion

安装 添加需要的USE 标记:(如果愿意加入到/etc/make.conf 中作为全局配置也可以) # echo 'dev-util/subversion svnserve apache2' >> /etc/portage/package.use emerge subversion 服务器与客户端程序: # emerge...

安装

添加需要的USE 标记:(如果愿意加入到/etc/make.conf 中作为全局配置也可以)

# echo 'dev-util/subversion svnserve apache2' >> /etc/portage/package.use

emerge subversion 服务器与客户端程序:

# emerge subversion
[ebuild   R   ] dev-util/subversion-1.4.6-r1  USE="apache2 berkdb emacs java nls perl python ruby svnserve* -bash-completion -debug -doc -extras -nowebdav -vim-syntax" 0 kB  

注意:subversion 依赖于apache 服务,如果系统中没有apache,会自动添加入emerge 列表。

安装好后产生以下主要的文件:

/usr/bin/svnadmin   		用于建立一个repository,也就是一个svn版本库服务
/usr/bin/svn   			svn客户端命令行程序
/etc/init.d/svnserve		svn后台服务程序
/etc/conf.d/svnserve    	svn服务配置文件

配置

默认的配置文件使用/var/svn 作为repository 的根目录,不做修改。

使用root 建立/var/svn 目录,然后建立独立的repository目录: prj。

# mkdir /var/svn
# mkdir /var/svn/prj

现在使用前面创建的路径建立一个repository。

# svnadmin create /var/svn/prj 

这会生成一些目录结构与文件在/var/svn/prj 下面,编辑配置文件/var/svn/prj/conf/passwd,加入svn 授权连接用户与密码。

myusername - mypassword 

接下来编辑repository配置文件/var/svn/prj/conf/svnserve.conf,去除掉以下行的注释:

anon-access = read
auth-access = write
password-db = passwd

注意:行首不要留有空格。 

下面还需要给svn root 目录/var/svn 以及下面的repository 正确的授权,以使以apache用户运行的svnserver 能够正确的存取它们。执行以下命令:
# chown -R apache:root /var/svn 

 现在repository 已经准备好了,可以启动svn 服务,并设置为跟随系统自动启动。

# /etc/init.d/svnserve start
# rc-update add svnserve default 

至此,svn server已经在运行,并且为一个叫做prj的项目建立了一个repository,同时为这个repository设置了连接用户。

下面我们选择一个路径作为保存working copy 的目录,比如位于$HOME ,进入此目录,并首先将prj 项目check out,执行以下命令:

$ cd $HOME
$ svn checkout svn://localhost/prj

第一次执行此命令,svn会提示输入用户名与密码,然后保存在$HOME/.subversion 目录中。以上会在HOME 中目录建立目录$HOME/prj ,并包含$HOME/prj/.svn 用于保存版本控制的文件。

现在可以向$HOME/prj 中copy 项目文件。使用svn add PATH 命令加入版本控制信息,svn -m "message" commit PATH 命令进行提交。

参考信息

Gentoo Linux on T43 总结:环境与配置文件

这篇笔记将集中给出一些系统中的环境设置与配置文件,有些配置文件在前面可能有所提及,有些并未涉及到,算作对前面内容的总结和补充。 环境  $ emerge --info  Portage 2.1.3.18 (default-linux/x86/2007.0, gcc-4.2.2, glibc-2.6.1-r0, 2.6.23-gentoo i686) ================================================================= System uname:...

这篇笔记将集中给出一些系统中的环境设置与配置文件,有些配置文件在前面可能有所提及,有些并未涉及到,算作对前面内容的总结和补充。

环境 

$ emerge --info 
Portage 2.1.3.18 (default-linux/x86/2007.0, gcc-4.2.2, glibc-2.6.1-r0, 2.6.23-gentoo i686)
=================================================================
System uname: 2.6.23-gentoo i686 Intel(R) Pentium(R) M processor 2.00GHz
Timestamp of tree: Mon, 05 Nov 2007 13:20:01 +0000
app-shells/bash:     3.2_p17-r1
dev-java/java-config: 1.3.7, 2.1.2-r1
dev-lang/python:     2.5.1-r3
sys-apps/baselayout: 1.12.10-r5
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.9.6-r2, 1.10
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.4.0-r1
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.23
ACCEPT_KEYWORDS="x86 ~x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-Os -march=pentium-m -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/gconf /etc/revdep-rebuild /etc/splash /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-Os -march=pentium-m -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks metadata-transfer sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://ftp.ncnu.edu.tw/Linux/Gentoo/     http://distro.ibiblio.org/pub/linux/distributions/gentoo/     http://ftp.ucsb.edu/pub/mirrors/linux/gentoo/"
LANG="en_US"
LINGUAS="en zh zh_CN"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.asia.gentoo.org/gentoo-portage"
USE="X a52 aac aalib acl acpi alsa apache2 asf avahi avi berkdb bitmap-fonts bluetooth bzip2 cdparanoia cdr cjk cli console cracklib crypt cups dbus divx4linux dri dv dvd dvdr dvdread emacs encode esd exif ffmpeg firefox flac foomatic fortran gdbm gif glitz gnome gphoto2 gpm gstreamer gtk hal hdaps iconv immqt-bc irda isdnlog java jpeg lame live mad madwifi midi mjpeg mmx mp3 mp4 mpeg msn mudflap mysql ncurses nls nptl nptlonly nsplugin ogg opengl openmp oss pam pcre pda pdf perl png ppds pppd python qq quicktime rar readline real reflection ruby session sound spell spl sse sse2 ssl svg symlink tcpd tiff truetype truetype-fonts type1 type1-fonts unicode usb userlocales vcd vidix vorbis wav win32codecs wmv x86 xcb xine xinerama xml xorg xv xvid zip zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" ELIBC="glibc" INPUT_DEVICES="keyboard evdev mouse synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en zh zh_CN" USERLAND="GNU" VIDEO_CARDS="radeon vesa"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LDFLAGS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS 
$ set 
ANT_HOME=/usr/share/ant-core
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="17" [3]="1" [4]="release" [5]="i686-pc-linux-gnu")
BASH_VERSION='3.2.17(1)-release'
CLASSPATH=/home/db2amor/sqllib/java/db2java.zip:/home/db2amor/sqllib/java/db2jcc.jar:/home/db2amor/sqllib/java/sqlj.zip:/home/db2amor/sqllib/function:/home/db2amor/sqllib/java/db2jcc_license_cisuz.jar:/home/db2amor/sqllib/java/db2jcc_license_cu.jar:.
COLORTERM=gnome-terminal
COLUMNS=152
CONFIG_PROTECT='/usr/share/X11/xkb /usr/kde/3.5/share/config /usr/kde/3.5/env /usr/kde/3.5/shutdown /usr/share/config'
CONFIG_PROTECT_MASK='/etc/env.d/java/ /etc/udev/rules.d /etc/gconf /etc/terminfo /etc/revdep-rebuild /etc/splash'
CVS_RSH=ssh
DB2INSTANCE=db2amor
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-S9K8WiCEnf,guid=d7447ddfa94cec100759df0047da3397
DIRSTACK=()
DISPLAY=:0.0
EDITOR=/usr/bin/emacs
EUID=1000
FLTK_DOCDIR=/usr/share/doc/fltk-1.1.7-r2/html
GCC_SPECS=
GDK_USE_XFT=1
GENERATION=2
GNOME_DESKTOP_SESSION_ID=Default
GNOME_KEYRING_SOCKET=/tmp/keyring-HarWwA/socket
GROUPS=()
GTK_IM_MODULE=scim
GTK_RC_FILES=/etc/gtk/gtkrc:/home/alex/.gtkrc-1.2-gnome2
G_BROKEN_FILENAMES=1
HISTFILE=/home/alex/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/home/alex
HOSTTYPE=i686
HUSHLOGIN=FALSE
IFS=$' \t\n'
INFOPATH=/usr/share/info:/usr/share/binutils-data/i686-pc-linux-gnu/2.18/info:/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2/info:/usr/share/info/emacs-22
JAVAC=/home/alex/.gentoo/java-config-2/current-user-vm/bin/javac
JAVA_HOME=/home/alex/.gentoo/java-config-2/current-user-vm
JDK_HOME=/home/alex/.gentoo/java-config-2/current-user-vm
KDEDIRS=/usr:/usr/local:/usr/kde/3.5
LANG=en_US
LC_CTYPE=zh_CN
LD_LIBRARY_PATH=/opt/ibm-jdk-bin-1.4.2.9/bin:/opt/ibm-jdk-bin-1.4.2.9/jre/bin:/home/db2amor/sqllib/lib
LESS='-R -M --shift 5'
LESSOPEN='|lesspipe.sh %s'
LIBPATH=/home/db2amor/sqllib/lib
LINES=51
LOGNAME=alex
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.patch=00;32:*.diff=00;32:*.log=00;32:*.tex=00;32:*.doc=00;32:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:'
MACHTYPE=i686-pc-linux-gnu
MAIL=/var/mail/alex
MAILCHECK=60
MANPATH=/home/alex/.gentoo/java-config-2/current-user-vm/man:/usr/local/share/man:/usr/share/man:/usr/share/binutils-data/i686-pc-linux-gnu/2.18/man:/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2/man:/etc/java-config/system-vm/man/:/usr/kde/3.5/share/man:/usr/qt/3/doc/man
OPENGL_PROFILE=xorg-x11
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PAGER=/usr/bin/less
PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.2.2:/opt/mts-client:/opt/mts:/opt/ibm-jdk-bin-1.4.2.9/bin:/opt/ibm-jdk-bin-1.4.2.9/jre/bin:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin:/home/alex/bin:/home/alex/foo:/home/alex/foo/order:/home/db2amor/sqllib/bin:/home/db2amor/sqllib/adm:/home/db2amor/sqllib/misc:/home/alex/bin:/home/alex/foo:/home/alex/foo/order
PIPESTATUS=([0]="2")
PKG_CONFIG_PATH=/usr/qt/3/lib/pkgconfig
PPID=7553
PRELINK_PATH_MASK=/usr/lib/gstreamer-0.10:/usr/lib/klibc
PYTHONPATH=/usr/lib/portage/pym
QMAKESPEC=linux-g++
QTDIR=/usr/qt/3
QT_IM_MODULE=scim
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=3
SSH_AGENT_PID=7403
SSH_AUTH_SOCK=/tmp/ssh-VHqDnq7373/agent.7373
TERM=xterm
USER=alex
VMHANDLE=ibm-jdk-bin-1.4
VWSPATH=/home/db2amor/sqllib
VWS_LOGGING=/home/db2amor/sqllib/logging
VWS_TEMPLATES=/home/db2amor/sqllib/templates
WINDOWID=20980933
WINDOWPATH=7
XAUTHORITY=/home/alex/.Xauthority
XDG_DATA_DIRS=/usr/share:/usr/kde/3.5/share:/usr/local/share
XDG_SESSION_COOKIE=
XMODIFIERS=@im=SCIM

配置文件

后记

这篇笔记不会是这个系列的最后一篇,因为有些部分自己还没有整理清楚,待合适的时候,将继续更新。

延展阅读

IBM DB2 信息中心 v8.2 在Gentoo Linux 上安装的一些问题

Gentoo 支持 IBM DB2 信息中心 并不提供对Gentoo Linux 的额外支持,如果使用Gentoo,在以下几个地方,需要额外的工作。 rpm DB2 信息中心安装文件内部使用rpm 包,Gentoo 默认没有rpm 引擎,需要先emerge rpm,否则安装无法继续。 #...

Gentoo 支持

IBM DB2 信息中心 并不提供对Gentoo Linux 的额外支持,如果使用Gentoo,在以下几个地方,需要额外的工作。

rpm

DB2 信息中心安装文件内部使用rpm 包,Gentoo 默认没有rpm 引擎,需要先emerge rpm,否则安装无法继续。

# emerge -av rpm 

信息中心自v9.1 版本,使用tar包,不再需求rpm。

服务daemon 不会自动启动

安装脚本使用Redhat Linux 发布的chkconfig 命令来为Linux 环境设置自动启动daemon,Gentoo 不支持,需要手工配置。

# rc-update add db2icd default 
安装中文帮助文档包

命令行安装仅仅安装基本的英文版本,如果需要中文,手工运行:

# rpm -ivh --nodeps db2/linux/IBM_db2decn81-8.1.0-64.i386.rpm 

繁体中文:IBM_db2detw81-8.1.0-64.i386.rpm 

Truableshooting

GUI安装:Installing DB2 file sets:.......Failure

图形安装方式运行:

# ./db2setup

启动了图形安装界面,services name 和端口使用默认值:db2icserver, 51000,最后一步安装失败,/tmp/db2setup.log 如下:

DB2 Setup log file started at: Sat 01 Mar 2008 01:43:06 AM CST CST
============================================================
Operating system information: Linux 2.6.23-gentoo.#7 PREEMPT Tue Nov 6 17:01:35 CST 2007 i686
Product to install:                        IBM DB2 Information Center
Installation type:                         Custom
Previously Installed Components:        
Selected Components:                    
Languages:                              
Target directory:                          /opt/IBM/db2/V8.1
Space required:                            0 MB
DB2 Information Center Server settings: 
Service Name:                          db2icserver
Port number:                           51000
Checking license agreement acceptance:.......Success
Installing DB2 file sets:.......Failure
ERROR:A major error occurred while installing "IBM DB2 Information Center" on 
this computer. The installation can not continue. If the problem persists 
please contact your technical service representative.
DB2 Setup log file finished at: Sat 01 Mar 2008 01:47:33 AM CST CST
============================================================ 

尚不知如何解决。

命令行安装:error: Failed dependencies:       /opt/IBM/db2/V8.1 is needed by IBM_db2deen81-8.1.0-64.i386

执行命令行安装:

# cd ./261_DOCE_LNX_3264_NLV
# ./db2_install -p DB2.DOCE

提示错误:

   IBM_db2deen81...
error: Failed dependencies:
        /opt/IBM/db2/V8.1 is needed by IBM_db2deen81-8.1.0-64.i386
The installation logfile can be found in /tmp/db2_install_log.16033.
db2_install program terminated prematurely.

这是rpm 包的依赖问题,具体原因不清楚。

临时解决方法:

修改安装目录的文件 261_DOCE_LNX_3264_NLV/db2/linux/db2_install ,573行,为rpm 命令增加参数--nodeps。
573              ( rpm -ivh --nodeps ${INSTDEV?}/${pkg?}${RPMEXTN?} 2>&1; echo $? > ${TMPRC?} ) | tee -a ${DB2INSTLOG?}
服务端口冲突

如果在系统中安装了多个版本的信息中心,比如同时安装了v8 与v9,那么可能需要考虑以下问题。

信息中心v8 版本的命令行安装脚本不能自动配置服务端口,总是使用默认值51000,可能会与其它版本的信息中心引起冲突(比如在安装v8版本之前安装了v9),需要手工修改 /var/db2/v81/db2icd.conf,挑选一个未被占用的端口,这里使用51002。

## TCP/IP port for DB2 Information Center
DB2_ECLIPSEIC_PORT=51002
## Temporary workspace file location for DB2 Information Center
## Default location is DB2 install location (<DB2DIR>/doc/eclipse)
DB2_ECLIPSEIC_DATA=
## Suggested alternate location 
#DB2_ECLIPSEIC_DATA=/tmp/db2icd/workspace
DB2HELP_DIR=/opt/IBM/db2/V8.1/bin/../doc/eclipse

注意,/opt/IBM/db2/V8.1/cfg/db2ic.conf  是个类似的配置文件,但/etc/init.d/db2icd 并没有使用它,使用的是/var/db2/v81/db2icd.conf。

启动服务失败:su: error while loading shared libraries: libcrypt.so.1: cannot open shared object file: No such file or directory

启动服务,输出大量的错误信息,100秒超时后,启动失败。

# /etc/init.d/db2icd start
Initializing startup.
su: error while loading shared libraries: libcrypt.so.1: cannot open shared object file: No such file or directory
ps: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
grep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
awk: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
grep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
ps: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
awk: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
sleep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
expr: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
./db2icd: line 204: [: : integer expression expected
... 

此问题由daemon脚本使用的Java 虚拟机版本和内核环境参数引起。

/etc/init.d/db2icd 使用安装程序自带的Java虚拟机,版本为1.3.1。

# /opt/IBM/db2/V8.1/doc/eclipse/jre/bin/java -version
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1)
Classic VM (build 1.3.1, J2RE 1.3.1 IBM build cxia32131-20031021 (JIT enabled: jitc))

/etc/init.d/db2icd 为Linux 环境设置了内核环境参数。

LD_ASSUME_KERNEL=2.4.19
export LD_ASSUME_KERNEL 

完成下面2个步骤可以解决问题:

  1. 修改daemon脚本,更换为系统的Java虚拟机
  2. 修改daemon脚本,取消内核环境参数 LD_ASSUME_KERNEL

我的系统中安装两个版本的Java 环境,经测试,任何一个都可以,关于如何切换Java 环境版本,可参考 Gentoo Linux on T43 (12) Java 环境

# java-config -L
The following VMs are available for generation-2:
*)      IBM JDK 1.4.2.9 [ibm-jdk-bin-1.4]
2)      IBM JDK 1.5.0.5a [ibm-jdk-bin-1.5] 

我的内核版本是2.6.23-gentoo:

# uname -svr
Linux 2.6.23-gentoo #7 PREEMPT Tue Nov 6 17:01:35 CST 2007

两处代码更改如下: 

# diff /etc/init.d/db2icd /etc/init.d/db2icd.bak
76,77c76
< #     DB2HELP_JRE="$DB2HELP_DIR/jre/bin/java"
<       DB2HELP_JRE="java"
---
>       DB2HELP_JRE="$DB2HELP_DIR/jre/bin/java"
195,196c194,195
<              #LD_ASSUME_KERNEL=2.4.19
<              #export LD_ASSUME_KERNEL
---
>              LD_ASSUME_KERNEL=2.4.19
>              export LD_ASSUME_KERNEL 

通过http://localhost:51002 访问DB2 Information Center v8.2 成功。

安装路径与卸载问题 

DB2 数据库v8 版本安装不允许修改安装路径/opt/IBM/db2/V8.1/(Solaris 平台除外),同样,信息中心v8 也是如此,虽然其安装脚本db2_install 具有-d 参数,但指定安装目录无效,无论如何都安装在默认目录/opt/IBM/db2/V8.1,会与DB2 数据库v8 混在一起,如果执行Information Center 的卸载程序db2_deinstall,也会将DB2 数据库v8 一并卸载掉,这点需要特别注意。

如果意外卸载了DB2 数据库 v8,用原有的选项重新安装即可,无须重新创建或者修改实例。

Gentoo Linux on T43 (14) 内存虚拟盘加速系统

对于一个喜欢折腾系统的人来说,为笔记本电脑建立内存虚拟盘,来弥补笔记本小硬盘天然的性能瓶颈问题,总是免不了的。 内核选项  Linux 内核内建了ramdisk支持,正常情况下,内核中下列选项应该是enable 的。 $ zcat /proc/config.gz |grep -i tmpfs CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y 这就表明,可以直接利用mount 命令创建一个内存虚拟盘。...

对于一个喜欢折腾系统的人来说,为笔记本电脑建立内存虚拟盘,来弥补笔记本小硬盘天然的性能瓶颈问题,总是免不了的。

内核选项 

Linux 内核内建了ramdisk支持,正常情况下,内核中下列选项应该是enable 的。

$ zcat /proc/config.gz |grep -i tmpfs
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y

这就表明,可以直接利用mount 命令创建一个内存虚拟盘。

创建内存盘

我打算把内存虚拟盘放在/mnt/ram 。使用以下简单的命令:

# mkdir /mnt/ram 
# mount -t tmpfs -o 128m none /mnt/ram

也可以不指定内存盘大小:

# mount -t tmpfs none /mnt/ram 

在内存盘建立之后,查看top 或者系统监视器,可用内存并未相应减少(明确指定大小的内存盘也是如此)。经过测试,未明确指定大小的内存盘会动态分配内存,可以持续向内存盘中写入文件,当再无可用物理内存时才会报空间不足的错误。 tmpfs 文件系统默认采用1G 的容量,但并未实际分配并占用这部分内存,而是动态分配。这要比Windows下流行的内存虚拟盘方案 方便得多。

启动时自动创建

接下来,将以下行加入/etc/fstab,让系统在每次启动时自动创建内存盘。

none            /mnt/ram    tmpfs       noatime 0 0 

利用内存盘 

最后,可以把一些常用软件的临时文件夹指定到/mnt/ram,如果应用程序不支持临时文件夹配置,也可以将其转换成到/mnt/ram 的符号链接。

Lotus Notes 8

notes 8会在$HOME目录自动建立workplace-tmp 目录来存储临时文件,我们可以将其转移到内存盘中。先关闭notes,然后执行以下命令:

$ mkdir /mnt/ram/workplace-tmp
$ echo ' mkdir /mnt/ram/workplace-tmp' >> ~/.bash_profile
$ mv ~/workplace-tmp ~/workplace-tmp.bak
$ ln -s /mnt/ram/workplace-tmp ~/workplace-tmp
$ ls -l ~/workplace-tmp
lrwxrwxrwx 1 alex users 22 2008-02-19 09:36 /home/alex/workplace-tmp -> /mnt/ram/workplace-tmp  

更新 2008-03-24

将/var/tmp 与/tmp 也加入到tmpfs

/etc/fstab

none			/tmp	    tmpfs		noatime	0 0
none			/var/tmp    tmpfs		noatime	0 0

设置Notes

修改~/.bash_profile

if [ ! -e /var/tmp/workplace-tmp ]; then
mkdir /var/tmp/workplace-tmp
fi

重启后,修改Notes临时文件夹符号连接

$ rm ~/workplace-tmp
$ ln -s /var/tmp/workplace-tmp ~/workplace-tmp

将/var/tmp/ 放入tmpfs 之后,在merge一些巨大的软件包时,中途可能因为临时空间不足而失败退出,这种情况下,可以指定PORTAGE_TMPDIR 到其它具有足够空间的路径来解决。比如:

# PORTAGE_TMPDIR=~/tmp emerge -av openoffice
$ sudo PORTAGE_TMPDIR=~/tmp emerge -av openoffice 

延展阅读

(未完)

Gentoo Linux on T43 (13) 应用程序中字体的纠正

这篇日志打算对Gentoo Linux on T43 (7) 中文字体 进行一些补充,继续讨论一些需要单独对字体有所调整的应用程序,这里不追求字体的完美显示,只记录一些必要的调整步骤,以解决字体乱码,或者字体严重变形以至影响辨认的问题。 wine 一些依靠wine 模拟器运行的Windows 应用程序,字体会严重变形,比如BeyondCompare,虽然应用程序选项提供了字体选项,调整后也无法令所有界面显示易于辨识的字体。经过参考设置wine程序的字体一文,我做出调整,将Linux系统主要字体复制给wine使用,解决了问题。 $ ls -1 /usr/local/share/fonts/TTF/*.ttf...

这篇日志打算对Gentoo Linux on T43 (7) 中文字体 进行一些补充,继续讨论一些需要单独对字体有所调整的应用程序,这里不追求字体的完美显示,只记录一些必要的调整步骤,以解决字体乱码,或者字体严重变形以至影响辨认的问题。

wine

一些依靠wine 模拟器运行的Windows 应用程序,字体会严重变形,比如BeyondCompare,虽然应用程序选项提供了字体选项,调整后也无法令所有界面显示易于辨识的字体。经过参考设置wine程序的字体一文,我做出调整,将Linux系统主要字体复制给wine使用,解决了问题。

$ ls -1 /usr/local/share/fonts/TTF/*.ttf
msyhbd.ttf
msyh.ttf
simhei.ttf
simsun18030.ttf
simsun.ttf
sthei.ttf
wqy-zenhei.ttf 
$ cp /usr/local/share/fonts/TTF/*.ttf ~/.wine/drive_c/windows/fonts/ 
$ ls -1 ~/.wine/drive_c/windows/fonts/
msyhbd.ttf
msyh.ttf
simhei.ttf
simsun18030.ttf
simsun.ttf
sthei.ttf
wqy-zenhei.ttf 

仅此一步即可,没有按上文修改.wine/system.reg ,默认的96dpi 很合适,否则字体会过大。

以上几种中文字体,被我的配置文件~/.fonts.conf所引用,你可以使用自己的字体。

$ wine --version
wine-0.9.48 

picasa2

pciasa2 是Google 的一款非常出色的免费图片管理软件,已经推出了Linux版本,并且包含在Gentoo官方Package列表中,Gentoo用户可以直接emerge安装。

其实它不是真正的Linux版本,而是通过wine 来模拟的,但其不依赖于系统的wine, 而是自动单独安装一份经过google team 优化的版本,其也有菜单字体严重变形问题。前面对系统wine 做的配置对picasa2 无效,需要单独配置。

# cp /home/yourname/.wine/drive_c/windows/fonts/* /home/yourname/.picasa/drive_c/windows/fonts/

注意,上一步需要root 权限,因为 .picasa/drive_c/windows/fonts/ 是一个符号连接。

copy 完字体后,picasa2 有以下字体可用:

 $ ls -1 .picasa/drive_c/windows/fonts/
couree.fon
coure.fon
courer.fon
cvgasys.fon
marlett.ttf
msyhbd.ttf
msyh.ttf
simhei.ttf
simsun18030.ttf
simsun.ttf
sserifee.fon
sserife.fon
sserifer.fon
sthei.ttf
svgasys.fon
VeraBd.ttf
VeraBI.ttf
VeraIt.ttf
VeraMoBd.ttf
VeraMoBI.ttf
VeraMoIt.ttf
VeraMono.ttf
VeraSeBd.ttf
VeraSe.ttf
Vera.ttf
vgasyse.fon
vgasys.fon
vgasysr.fon
wineding.ttf
wqy-zenhei.ttf

经过以上配置,菜单中的字体变形问题得到解决,但文件夹管理的文件夹树中,中文显示为黑块,其它的方中文均正常,目前不知道解决方案(据令狐虫介绍 ,Picasa 2.7 beta for linux 已经解决了此问题)。

我的picasa2 版本是2.2-2820-5。

emacs

TODO 

(未完) 

Gentoo Linux on T43 (12) Java 环境

安装IBM JDK 对于jdk有很多种选择,可以通过emerge -s jdk列出,我的环境以IBM产品为主,因此选择安装ibm jdk,其已经包含在Gentoo官方ebuild中,可以直接emerge,但jdk安装文件因为license 问题没有放入Gentoo mirror,需要自己下载,手工放入Portage,再继续emerge。 ibm jdk 目前最新版本是1.5(也称为 5.0),下面会安装此版本,为了兼容性,jdk 1.4.2 也一并安装,如果愿意,再安装1.3.1 也不是问题,Gentoo 的java...

安装IBM JDK

对于jdk有很多种选择,可以通过emerge -s jdk列出,我的环境以IBM产品为主,因此选择安装ibm jdk,其已经包含在Gentoo官方ebuild中,可以直接emerge,但jdk安装文件因为license 问题没有放入Gentoo mirror,需要自己下载,手工放入Portage,再继续emerge。

ibm jdk 目前最新版本是1.5(也称为 5.0),下面会安装此版本,为了兼容性,jdk 1.4.2 也一并安装,如果愿意,再安装1.3.1 也不是问题,Gentoo 的java 环境控制非常方便。

以上jdk 在IBM Java download 可以找到,页面中包含各个版本,选择32-bit xSeries (Intel compatible)平台,tar/tgz 格式的文件下载。下载时需要登录ibm.com,如果还没有帐户可以免费注册(前段时间IBM 已经将各语言版本的ibm.com 帐户统一)。 

USE flag

USE flag 中加入java 与nsplugin ,没有nsplugin支持,基于浏览器的java applet 无法使用。

jdk 1.5 

直接emerge 会出错:

# emerge -av =ibm-jdk-bin-1.5.0.5a

或者 

# emerge -av ibm-jdk-bin
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild   RF  ] dev-java/ibm-jdk-bin-1.5.0.5a  USE="X alsa nsplugin -doc -examples -javacomm" 61,611 kB 
Total: 1 package (1 reinstall), Size of downloads: 61,611 kB
Fetch Restriction: 1 package (1 unsatisfied)
Would you like to merge these packages? [Yes/No] 
>>> Verifying ebuild Manifests...
>>> Emerging (1 of 1) dev-java/ibm-jdk-bin-1.5.0.5a to /
!!! dev-java/ibm-jdk-bin-1.5.0.5a has fetch restriction turned on.
!!! This probably means that this ebuild's files must be downloaded
!!! manually.  See the comments in the ebuild for more information.
* Due to license restrictions, we cannot redistribute or fetch the distfiles
 * Please visit: http://www.ibm.com/developerworks/java/jdk/linux/download.html
* Under J2SE 5.0, download SR5 for your arch:
* (note that we switched to tgz format because it's now versioned)
 * ibm-java2-sdk-5.0-5.1-linux-i386.tgz
* You can use direct link to your arch download page:
* https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=sdk5&S_PKG=intel5sr5a&S_TACT=105AGX05&S_CMP=JDK
* Place the file(s) in: /usr/portage/distfiles
* Then restart emerge: 'emerge --resume'
* Note: if SR5 is not available at http://www.ibm.com/developerworks/java/jdk/linux/download.html
* it may have been moved to http://www.ibm.com/developerworks/java/jdk/linux/older_download.html. Lately that page
* isn't updated, but the files should still available through the
* direct link to arch download page. If it doesn't work, file a bug.
* Fetch failed for 'dev-java/ibm-jdk-bin-1.5.0.5a'
* Messages for package dev-java/ibm-jdk-bin-1.5.0.5a:
* Fetch failed for 'dev-java/ibm-jdk-bin-1.5.0.5a' 

自己从ibm.com下载,保存为 /usr/portage/distfiles/ibm-java2-sdk-5.0-5.1-linux-i386.tgz,再次执行emerge ,安装成功。

jdk 1.4.2

与jdk 1.5 相同,同样需要自己下载,保存为 /usr/portage/distfiles/IBMJava2-SDK-1.4.2-9.0.tgz,指定版本执行emerge。

# emerge -av =ibm-jdk-bin-1.4.2.9 

java 环境切换

Gentoo Linux 允许不同版本的Java 环境共存,支持对系统和用户级别java 环境的独立控制,提供方便的机制对其进行管理,实现即时切换。有以下2种工具可以利用:

  • java环境配置工具java-config
  • 系统命令eselsect

通过以下命令,可以实现java环境动态切换,任何已存在的session 无需重新登录或者重新执行profile,新的环境设定会即刻生效。

注意:带# 提示符的命令需要在root 权限下执行。

java-config
$ java-config -L
The following VMs are available for generation-2:
1)      IBM JDK 1.4.2.9 [ibm-jdk-bin-1.4]
*)      IBM JDK 1.5.0.5a [ibm-jdk-bin-1.5]
$ java-config -s 1
Now using ibm-jdk-bin-1.4 as your user JVM 
# java-config -S 1
Now using ibm-jdk-bin-1.4 as your generation-2 system JVM 
eselect

eselect 命令也可以做以上工作。

$ eselect java-vm list
Available Java Virtual Machines:
  [1]   ibm-jdk-bin-1.4
  [2]   ibm-jdk-bin-1.5  system-vm user-vm
$ eselect java-vm set user 1 
# eselect java-vm set system 1

延展阅读

(未完)

Gentoo Linux on T43 (11) CPU 频率自动控制

TODO...
TODO

Gentoo Linux on T43 (10) Fingerprint Reader 指纹认证

Thinkpad Integrated Fingerprint Reader 可以使用指纹认证代替用户登录过程中的密码认证,减少用户手工输入密码的机会,在Windows 下使用CSS 软件,配合内置加密芯片,更可以实现指纹认证的文件加解密。 在Gentoo Linux 下整个配置过程比较容易,How to enable the fingerprint reader...

Thinkpad Integrated Fingerprint Reader 可以使用指纹认证代替用户登录过程中的密码认证,减少用户手工输入密码的机会,在Windows 下使用CSS 软件,配合内置加密芯片,更可以实现指纹认证的文件加解密。

在Gentoo Linux 下整个配置过程比较容易,How to enable the fingerprint reader with ThinkFinger - ThinkWiki 提供了非常清晰的描述,请参考文中的Gentoo 部分以及后续步骤。下面仅列出几点Gentoo 用户需要注意的地方。

  • 文件/etc/pam.d/common-auth 在Gentoo Linux 下无法找到,应该使用 /etc/pam.d/system-auth,以下是我修改后的内容。

/etc/pam.d/system-auth

#%PAM-1.0
auth       required     pam_env.so
# Added by alex
auth       sufficient   pam_thinkfinger.so
auth       sufficient   pam_unix.so try_first_pass likeauth nullok
auth       required     pam_deny.so
account    required     pam_unix.so
# This can be used only if you enabled the cracklib USE flag
password   required     pam_cracklib.so difok=2 minlen=8 dcredit=2 ocredit=2 try_first_pass retry=3
# This can be used only if you enabled the cracklib USE flag
password   sufficient   pam_unix.so try_first_pass use_authtok nullok md5 shadow
# This can be used only if you enabled the !cracklib USE flag
# password   sufficient pam_unix.so try_first_pass nullok md5 shadow
password   required     pam_deny.so
session    required     pam_limits.so
session    required     pam_unix.so
  • 将uinput 加入/etc/modules.autoload.d/kernel-2.6
# Modules for fingerprint
uinput
  • 将文中的环境变量$USERNAME 替换为$USER 再使用,例如:
# gpasswd -a $USERNAME fingerprint 
  • 若使指纹认证在xscreensaver/gnome-screensaver 中工作,必须按照上文4 xscreensaver/gnome-screensaver 一节进行额外配置。我在以下环境测试成功。
    • gnome-screensaver-2.20.0
    • pam-0.99.9.0

      但需要指出的是,文件/etc/pam.d/gnome-screensaver 并不需要修改,因为其已经通过include 关键字包含文件system-auth。
  • 关于gksu/gksudo 的workaround ,我未进行测试。

延展阅读

Gentoo Linux on T43 (9) HDAPS 硬盘动态保护系统

本文参考How to protect the harddisk through APS ,以下内容可直接应用于Gentoo Linux。 Thinkpad HDAPS 依靠笔记本内部的2D 加速度传感器检测笔记本位移, 将数据写入sysfs,系统中有一个demon (守护进程)负责监视这个sysfs...

本文参考How to protect the harddisk through APS ,以下内容可直接应用于Gentoo Linux。

Thinkpad HDAPS 依靠笔记本内部的2D 加速度传感器检测笔记本位移, 将数据写入sysfs,系统中有一个demon (守护进程)负责监视这个sysfs interface,必要时执行硬盘磁头parking 动作。此外,有一个applet,可以在任务托盘实时反映当前的保护状态,这个不是必须的。

在Linux 上完整的HDAPS 包括以下几个部分:

  • hdaps 驱动程序,从硬件传感器读取数据(内核内置此驱动,但不要使用,推荐使用tp_smapi 提供的驱动)。
  • 内核 patch,负责向sysfs 写入数据,需要重新编译内核。
  • hdapsd,demon 程序
  • applet,有多种选择:gnome-hdaps-applet, khdapsmonitor 等,可以不安装,并不影响HDAPS 作用。

下面就以上4个部分分别讨论。

内核Patch 

这一步需要提前来做。

根据自己的内核版本,找到相应的patch 下载另外一个下载地址),我的内核版本是2.6.23:

$ eselect kernel list
Available kernel symlink targets:
  [1]   linux-2.6.20-gentoo-r8
  [2]   linux-2.6.23-gentoo *
  [3]   linux-2.6.23-gentoo-r1

网络上没有找到版本完全符合的patch,但在2.6.23-kamikaze4 中找到了thinkpad-2.6.23-1.patch ,它里面包含了我们需要的protection patch,我将其提取出来,做成 hdaps-protect-2.6.23.patch ,可以单独使用。

用以下命令应用patch,并重新编译内核安装modules 。

# cd /usr/src/linux
# patch -p1 <  ~/hdaps-protect-2.6.23.patch 
# make && make modules_install

重新启动系统之后,会在sysfs 生成文件 /sys/block/xxx/queue/protect,表明patch 成功。

hdaps 驱动程序 

首先要禁止内核中的驱动程序,确保以下内核选项没有被设置,否则,将在不同的路径生成两个同名的module hdaps,load 过程会出错。

$ zcat /proc/config.gz |grep -i hdaps
# CONFIG_SENSORS_HDAPS is not set 

接下来在/etc/make.conf 的USE flag 中加入hdaps 支持,将会被tp_smapi 用到。

/etc/make.conf

USE="hdaps"

tp_smapi 已经被加入Gentoo package list,可以直接emerge,我目前使用0.31 版本。

# emerge -av app-laptop/tp_smapi

载入hdaps 与tp_smapi

# modprobe tp_smapi hdaps 

并将其加入到/etc/modules.autoload.d/kernel-2.6

# Modules for Thinkpad HDAPS
tp_smapi
hdaps

hdapsd

安装demon,直接emerge 即可,我的版本是20060409-r1 。

# emerge -av  app-laptop/hdapsd

编辑hdapsd 配置文件,在DISK 中指定需要保护的硬盘设备名称,作为可选,也可以调整保护动作阈值THRESHOLD ,值越小,保护动作越早,但也会更频繁。

/etc/conf.d/hdapsd

# The name of the disk device that hdapsd should monitor.
# Usually this is 'hda' or 'sda' the primary master.
DISK="sda"
# hdapsd sensitivity 
# The lower the threshold is the earlier 
# the heads are parked when the laptop is shaked
THRESHOLD="15"
# Set any extra options here, like -a for Adaptive mode
OPTIONS="-a"

启动hdaspd 服务

# /etc/init.d/hdapsd start

将hdapsd 设置为跟随系统自动启动 

# rc-update add hdapsd boot 

applet

如果希望监视硬盘保护状态,则需要安装applet 。我使用gnome 环境,因此选择了gnome-hdaps-applet ,但其还未被加入Gentoo 官方package list,需要下载回来自己编译安装。以下是步骤。

下载:

$ cd
$ wget http://www.zen24593.zen.co.uk/hdaps/gnome-hdaps-applet-20060120.tar.gz
$ mkdir gnome-hdaps-applet
$ tar -zxvf gnome-hdaps-applet-20060120.tar.gz -C gnome-hdaps-applet
$ cd gnome-hdaps-applet

编译:

$ gcc $(pkg-config --cflags --libs libpanelapplet-2.0) -o gnome-hdaps-applet gnome-hdaps-applet.c

安装:

# cp gnome-hdaps-applet /usr/bin
# mkdir /usr/share/pixmaps/gnome-hdaps-applet/
# cp *.png /usr/share/pixmaps/gnome-hdaps-applet/
# cp GNOME_HDAPS_StatusApplet.server /usr/lib/bonobo/servers

重启Xwindow,在applet 列表中可以找到新的项目,加入到panel 即可。

Tips

  • 我在hdapsd 中设置的设备名为sda,但我的第二块硬盘sdb(在硬盘托架内)并没有受到保护,我尝试更改配置文件为sdb,保护动作正常,但无法对2个设备同时进行保护,hdaps project 邮件列表有一条关于此的讨论,希望未来会支持多个设备
  • 如果没有安装applet,在那里查看硬盘的保护状态呢?可以用以下命令查看历史状态,也可以使用ctrl + alt + F12 查看实时状态。
$ dmesg |tail
...
scsi_protect_queue(): head parked..
... 
  • 我曾经在kernel-2.6.20-r8 下设置hdaps,但始终无法成功patch 内核,没有sysfs 数据写入,因此,hdapsd服务也无法启动成功。若有相似问题的用户可以尝试升级内核。

下载

延展阅读

(未完)

Gentoo Linux on T43 (8) X300 显卡的驱动以及3D 加速

T43 包括两种显卡方案,一种是915GM 主板集成Intel 显卡 ,另一种是ATI X300 独立显卡 ,我的显卡是X300 ,这里所有的讨论都是与X300 相关。 ATI X300 有2种驱动方案,一种是开源驱动radeon,通过开源R300 项目已经可以支持X300 显卡的3D...

T43 包括两种显卡方案,一种是915GM 主板集成Intel 显卡 ,另一种是ATI X300 独立显卡 ,我的显卡是X300 ,这里所有的讨论都是与X300 相关。

ATI X300 有2种驱动方案,一种是开源驱动radeon,通过开源R300 项目已经可以支持X300 显卡的3D 加速;另一种是ATI 官方的闭源驱动fglrx 。

下面针对这2种方案,分别给出我的配置,涉及到:内核配置、make.conf 、安装软件包、X11 配置、装载module以及OpenGL 设置。

内核配置

请参照 Gentoo Linux on T43 (5) 配置内核(kernel) 显卡一节。

make.conf

在开时编译一些软件包之前,需要在/etc/make.conf  中设置变量:USE 与VIDEO_CARDS 。

开源驱动与官方驱动都需要设定如下USE flag,将其添加到原有USE flag 列表

USE="dri opengl" 

VIDEO_CARDS 中的设定值会被软件包x11-server、x11-drm 等软件包使用,对于开源驱动设定:

VIDEO_CARDS="radeon vesa"

对于官方驱动设定: 

VIDEO_CARDS="fglrx vesa" 

加入vesa 用来对启动过程中的字符界面提供支持。

安装软件包

如果使用开源驱动,emerge:

# emerge -av xorg-x11 xf86-video-ati 

下面的软件包会作为依赖被自动安装

x11-base/xorg-server
x11-drivers/xf86-video-vesa
media-libs/mesa

前面内核配置,如果没有选择内核中的drm,那么此处应该把drm 也安装上:

# emerge -av x11-base/x11-drm 

如果使用官方驱动,emerge:

# emerge -av ati-drivers 

X11 配置

X11 的配置文件位于/etc/X11/xorg.conf ,这里不介绍如何生成一个默认的xorg.conf 文件(相关内容请参考Gentoo 手册),仅给出我的配置,将其合并入你的配置文件即可,以下是针对T43 1400x1050 高分屏以及X300显卡,并开启3D 加速的配置。

开源驱动
Section "Module"
    Load	"dbe"
    SubSection	"extmod"
        Option	"omit xfree86-dga"
    EndSubSection
    Load 	"glx"
    Load 	"dri"
    ...
EndSection
Section "Extensions"
    Option  "Composite" "1"
EndSection
Section "ServerFlags"
    Option      "AIGLX"         "on"
EndSection
Section "Monitor"
    Identifier	"Thinkpad LCD Monitor"
    Option	"dpms"
    DisplaySize	      370	277
EndSection
Section "Device"
    Identifier	"ATI Graphics Mobile X300"
    Driver	"radeon"
    BusID	"PCI:1:0:0"
EndSection
Section "Screen"
    Identifier "High Screen"
    Device     "ATI Graphics Mobile X300"
    Monitor    "Thinkpad LCD Monitor"
    DefaultDepth     24
    SubSection "Display"
        Viewport   0 0
        Depth      24
        Modes      "1400x1050" "1280x1024" "1024x768" "800x600"
    EndSubSection
EndSection
Section "ServerLayout"
    Identifier	"Main Layout"
    Screen	"High Screen"
    ...
EndSection
Section "dri"
    Mode         0666
EndSection 
官方驱动 

将上面的配置进行如下修改即可

...
Section "Extensions"
    Option  "Composite" "0"
EndSection
Section "ServerFlags"
    Option      "AIGLX"         "off"
EndSection
...
Section "Device"
    Identifier	"ATI Graphics Mobile X300"
    Driver	"fglrx"
    BusID	"PCI:1:0:0"
EndSection
...

装载module 

在/etc/modules.autoload.d/kernel-2.6 文件中加入在启动时需要装载的module 名称。

开源驱动 
# Modules for video card & 3D
drm
radeon
官方驱动 
# Modules for video card & 3D
drm
fglrx

可以使用以下命令确认module 是否装载成功,以及查看引用关系(以开源驱动为例)

$ lsmod |grep radeon
radeon                121376  2 
drm                    63380  3 radeon

OpenGL 配置

为系统选择OpenGL 程序。

开源驱动 
# eselect opengl set xorg-x11
官方驱动 
# eselect opengl set ati

延展阅读

(未完)

Gentoo Linux on T43 (7) 中文字体

Linux 下字体的配置可以很简单,也可以很复杂,这取决于个人需求的复杂程度,以及对相关知识的了解和技术掌控程度,其差别会导致悬殊的时间成本。在我本人开始这项工作之前,对相关内容了解很少,因此不得不花费时间来了解一些基础性内容。 在这个过程中,一本在线书籍Free/Open Source Software Localization 为我提供了有益的帮助,其整个第七章都是有关字体的内容,介绍了基本的字体概念,字体的分类,以及Linux 如何处理字体 等。 对于中文字体的详细配置,参考了quanliking 的2 篇文章: Linux 字体微调 -...

Linux 下字体的配置可以很简单,也可以很复杂,这取决于个人需求的复杂程度,以及对相关知识的了解和技术掌控程度,其差别会导致悬殊的时间成本。在我本人开始这项工作之前,对相关内容了解很少,因此不得不花费时间来了解一些基础性内容。

在这个过程中,一本在线书籍Free/Open Source Software Localization 为我提供了有益的帮助,其整个第七章都是有关字体的内容,介绍了基本的字体概念字体的分类,以及Linux 如何处理字体 等。

对于中文字体的详细配置,参考了quanliking 的2 篇文章: Linux 字体微调 - windows 效果版Linux 字体微调- Vista 效果版 以及kemean 的字体配置local.conf详解[带Win效果和AA效果]

下面先描述一下字体的安装方法,然后给出我的字体配置,更多的内容可以参考以上的链接。

安装字体

Gentoo Linux有2种主要的字体系统并存:Core X11 font systemxft font system,分别有不同的安装方法。

Core X11 font system

对于Core X11,系统与应用程序的字体一般放在/usr/share/fonts 下面的子目录内,建议把用户自己安装的字体放在/usr/local/share/fonts 下的子目录,并且需要将这些路径加入到Xwindow的配置文件 /etc/X11/xorg.conf。举例:

将新的truetype 类型字体放在/usr/local/share/fonts/TTF 目录,然后执行以下命令(注意顺序):

# mkfontscale  /usr/local/share/fonts/TTF
# mkfontdir /usr/local/share/fonts/TTF

接着编辑/etc/X11/xorg.conf 来让使用Core X11 font system 的X 应用程序知道有新的字体可以利用,添加以下行到文件的Files 与Module Section(其实这个目录默认已经存在,无须添加)。

Section "Files"
    FontPath   "/usr/local/share/fonts/TTF"
    ...
EndSection
重启Xwindow 即可,新的字体将会被识别。 
xft font system

有些X 应用程序使用xft font system ,Gentoo Linux 默认设置了以下环境变量,使gtk+ 2.0 应用程序的字体使用xft,而不是Core X11 font system。

$ cat /etc/env.d/50gtk2
GDK_USE_XFT=1

xft font system 会自动搜索标准的字体路径并发现新字体,无须多余的步骤。如果希望新字体可以立即使用,那么执行命令fc-chache -fv 来即可刷新字体缓存。

对字体的配置可以存放在2个文件当中,其一是系统级别的/etc/fonts/local.conf (没有此文件可以自己建立),其二是用户Home目录下的.fonts.conf,仅影响当前用户。

字体配置

目前Linux 下的中文字体配置主要分为以下几种。

Windows 或Mac 效果 

使用Windows 平台的宋体(SimSun)、新宋体(NSimSun)与黑体(SimHei) ,或者最新vista 系统中的微软雅黑字体(Microsoft YaHei)。另外还有Mac 平台采用的华文黑体(STHeiti),其效果与SimHei 类似,但小字体的效果更出色。这几种字体包含的字符集非常齐全,覆盖了汉字简繁以及日韩字体,因此对繁体以及日韩字体显示效果要求不很高的用户,就没必要再去配置细明体(PMingLiU) 等其它字体。

使用这些字体的方法很简单,将其从Windows 目录复制到Linux 下简单配置即可,但严格来讲,这里面有版权问题,因此,在大多数Linux 发布之中,我们找不到以上字体。

使用免费的开源字体 

在这方面做得比较出色的是文泉驿 字体,目前通过网络协作的方式,已经开发出了点阵宋体、黑体以及等宽三大类字体,并不断升级改善中。

可以直接在Gentoo 中安装其中的点阵宋体和正黑字体:

# emerge -av  media-fonts/wqy-bitmapfont media-fonts/wqy-zenhei
配置文件 

为了对比,我尝试了以上的各种字体配置方案,经过调整后,在T43 高分屏1400x1050分辨率下,效果都不错,其差别仅在个人喜好罢了。因此,我将配置文件整理,如果你安装了以上几种字体,那么简单修改几行,重启Xwindow ,即可更换一种字体。

下面是我的.fonts.conf (整理自quanliking 与kemean 的文章),放在我的HOME 目录,会被/etc/fonts/fonts.conf 自动读取,其优先级低于/etc/fonts/local.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- ~/.font.conf file for user customizations -->
<fontconfig>
<!--
    Breaf:
    Search keyword "editable" for configuation.
    Section:
    1. Fonts family configuration
    2. Fonts substitution
    3. Global configuration
    4. English fonts configuration
    5. CJK fonts configuration
    Installed fonts list:
    STHeiti
    微软雅黑,Microsoft YaHei
    黑体,SimHei
    宋体-18030,SimSun-18030
    宋体,SimSun
    新宋体-18030,SimSun-18030,NSimSun-18030
    新宋体,NSimSun
    WenQuanYi Bitmap Song
    文泉驿正黑,文泉罅正黑,WenQuanYi Zen Hei
    Arial
    Arial Black
    Verdana
    Comic Sans MS
    Georgia
    Times New Roman
    Courier New
    Andale Mono
    Fixed
    Impact
    Trebuchet MS
    Webdings
-->
<!--
*******************************************************************************
    1. Fonts family configuration [Begin]
*******************************************************************************
-->
    <alias>
        <family>serif</family>
        <prefer>
            <!-- @@@ editable -->
            <family>SimSun</family>
        </prefer>
    </alias>
    <alias>
        <family>sans-serif</family>
        <prefer>
            <!-- @@@ editable -->
            <family>Microsoft YaHei</family>
        </prefer>
    </alias>
    <alias>
        <family>monospace</family>
        <prefer>
            <!-- @@@ editable -->
            <family>NSimSun</family>
        </prefer>
    </alias>
<!--
*******************************************************************************
    1. Fonts family configuration [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    2. Fonts substitution [Begin]
*******************************************************************************
-->
<!--
    fonts alias substitution
-->
    <match target="pattern">
        <test name="family">
            <string>宋体</string>
        </test>
        <edit name="family" mode="assign">
            <string>SimSun</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>新宋体</string>
        </test>
        <edit name="family" mode="assign">
            <string>NSimSun</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>宋体-18030</string>
        </test>
        <edit name="family" mode="assign">
            <string>SimSun-18030</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>新宋体-18030</string>
        </test>
        <edit name="family" mode="assign">
            <string>NSimSun-18030</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>黑体</string>
        </test>
        <edit name="family" mode="assign">
            <string>SimHei</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>微软雅黑</string>
        </test>
        <edit name="family" mode="assign">
            <string>Microsoft YaHei</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>文泉驿正黑</string>
        </test>
        <edit name="family" mode="assign">
            <string>WenQuanYi Zen Hei</string>
        </edit>
    </match>
<!--
    not installed fonts substitution
-->
    <match target="pattern">
        <test name="family">
            <string>Times</string>
        </test>
        <edit name="family" mode="assign">
            <string>Times New Roman</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>Helvetica</string>
        </test>
        <edit name="family" mode="assign">
            <string>Verdana</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>Courier</string>
        </test>
        <edit name="family" mode="assign">
            <string>Courier New</string>
        </edit>
    </match>
    <match target="pattern" >
        <test name="family" >
            <string>PMingLiU</string>
            <string>MingLiU</string>
            <string>FangSong_GB2312</string>
            <string>KaiTi_GB2312</string>
            <string>AR PL KaitiM GB</string>
            <string>AR PL KaitiM Bit5</string>
            <string>AR PL SungtiL GB</string>
            <string>AR PL Mingti2L Bit5</string>
            <string>AR PL ShanHeiSun Uni</string>
            <string>AR PL ZenKai Uni</string>
            <string>Bitstream Vera Serif</string>
            <string>Bitstream Vera Sans</string>
            <string>Bitstream Vera Sans Mono</string>
            <string>DejaVu Sans</string>
            <string>DejaVu Sans Mono</string>
            <string>DejaVu Serif</string>
            <string>MS 明朝</string>
            <string>MS ゴシック</string>
            <string>Kochi Mincho</string>
            <string>Kochi Gothic</string>
            <string>Baekmuk Batang</string>
            <string>Baekmuk Dotum</string>
            <string>Baekmuk Gulim</string>
            <string>Baekmuk Headline</string>
        </test>
        <edit name="family" mode="assign" >
            <string>san-serif</string>
        </edit>
    </match>
<!--
    english portion substitution
-->
    <match target="pattern" >
        <test name="family" >
            <string>serif</string>
        </test>
        <edit name="family" mode="prepend" binding="strong" >
            <!-- @@@ editable -->
            <string>Georgia</string>
        </edit>
    </match>
    <match target="pattern" >
        <test name="family" >
            <string>sans-serif</string>
        </test>
        <edit name="family" mode="prepend" binding="strong" >
            <!-- @@@ editable -->
            <string>Verdana</string>
        </edit>
    </match>
    <match target="pattern" >
        <test name="family" >
            <string>monospace</string>
        </test>
        <edit name="family" mode="prepend" binding="strong" >
            <!-- @@@ editable -->
            <string>Courier New</string>
        </edit>
    </match>
<!--
*******************************************************************************
    2. Fonts substitution [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    3. Global configuration [Begin]
*******************************************************************************
-->
<!--
    target dots per inch, change dpi to 96
-->
    <match target="pattern" >
        <edit name="dpi" mode="assign" >
            <double>96</double>
        </edit>
    </match>
<!--
    enable sub-pixel rendering.
    if you are using CRT, set rgb -> none
-->
    <match target="font">
        <edit name="rgba" mode="assign">
            <const>none</const>
        </edit>
    </match>
<!--
    default Fonts setting
    here autohint = ture / hinting = false is for free fonts in your system
    we will use autohint = false / hinting = true for MS core fonts
-->
    <match target="font" >
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    font size settings:
    set the apposite font size,so it is easy to be read
-->
    <match target="pattern" >
        <test name="pixelsize" compare="more_eq" >
            <double>8</double>
        </test>
        <test name="pixelsize" compare="less_eq" >
            <double>12</double>
        </test>
        <edit name="pixelsize" mode="assign" >
            <double>12</double>
        </edit>
    </match>
<!--
    synthetic emboldening for fonts that do not have bold face available
-->
    <match target="font">
        <!-- check to see if the font is just regular -->
        <test name="weight" compare="less_eq">
            <int>100</int>
        </test>
        <!-- check to see if the pattern requests bold -->
        <test target="pattern" name="weight" compare="more_eq">
            <int>180</int>
        </test>
        <!-- set the embolden flag -->
        <edit name="embolden" mode="assign">
            <bool>true</bool>
        </edit>
    </match>
<!--
*******************************************************************************
    3. Global configuration [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    4. English fonts configuration [Begin]
*******************************************************************************
-->
<!--
    default : smoothed and hinted
-->
    <match target="font" >
        <test name="foundry" qual="any" >
            <string>monotype</string>
            <string>microsoft</string>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    for point size less equal than 6 : only smoothed
-->
    <match target="font" >
        <test name="foundry" qual="any" >
            <string>monotype</string>
            <string>microsoft</string>
        </test>
        <test name="size" compare="less_eq" >
            <double>6</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
<!--
    Arial Regular
-->
    <match target="font" >
        <test name="family" >
            <string>Arial</string>
        </test>
        <test name="weight" compare="eq">
            <const>regular</const>
        </test>
        <test name="slant" compare="eq" >
            <const>roman</const>
        </test>
        <test name="size" compare="more_eq" >
            <double>7</double>
        </test>
        <test name="size" compare="less_eq" >
            <double>13</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    Times New Roman Bold Italic
-->
    <match target="font" >
        <test name="family" >
            <string>Times New Roman</string>
        </test>
        <test name="weight" compare="eq">
            <const>bold</const>
        </test>
        <test name="slant" compare="eq" >
            <const>italic</const>
        </test>
        <test name="size" compare="more_eq" >
            <double>7</double>
        </test>
        <test name="size" compare="less_eq" >
            <double>13</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    Courier New:
    both enable autohint and hinting looks very well.
-->
   <match target="font" >
      <test name="family" >
         <string>Courier New</string>
      </test>
      <edit name="antialias" mode="assign" >
         <bool>true</bool>
      </edit>
      <edit name="autohint" mode="assign" >
         <bool>true</bool>
      </edit>
      <edit name="hinting" mode="assign" >
         <bool>true</bool>
      </edit>
      <edit name="hintstyle" mode="assign" >
         <const>hintfull</const>
      </edit>
   </match>
<!--
    Courier New font size
-->
   <match target="font" >
      <test name="family" >
         <string>Courier New</string>
      </test>
      <test name="pixelsize" compare="less_eq" >
         <double>14.7</double>
      </test>
      <edit name="pixelsize" mode="assign" >
         <double>14.7</double>
      </edit>
   </match>
<!--
*******************************************************************************
    4. English fonts configuration [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    5. CJK fonts configuration [Begin]
*******************************************************************************
-->
<!--
    the dual-width Asian fonts (spacing=dual) are not rendered correctly,
    apparently FreeType forces all widths to match. Trying to disable the
    width forcing code by setting globaladvance=false alone doesnot  help.
    as a brute force workaround, also set spacing=proportional, i.e. handle
    them as proportional fonts:
-->
    <match target="font" >
        <test target="pattern" name="lang" compare="contains" >
            <string>zh</string>
            <string>ja</string>
            <string>ko</string>
        </test>
        <test name="spacing" compare="eq">
            <const>dual</const>
        </test>
        <edit name="spacing" mode="assign" >
            <const>proportional</const>
        </edit>
        <edit name="globaladvance" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
<!--
    adjusting
-->
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <!-- installed fonts -->
            <!--
            <string>STHeiti</string>
            -->
            <string>Microsoft YaHei</string>
            <string>SimHei</string>
            <string>SimSun</string>
            <string>NSimSun</string>
            <string>SimSun-18030</string>
            <string>NSimSun-18030</string>
            <string>WenQuanYi Bitmap Song</string>
            <string>WenQuanYi Zen Hei</string>
        </test>
        <edit name="rgba" mode="assign">
            <const>none</const>
        </edit>
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
        <edit name="embeddedbitmap" mode="assign" >
            <bool>true</bool>
        </edit>
    </match>
<!--
    enable embedded bitmap fonts
    non-bitmap:
       STHeiti: sthei.ttf 13563000 bytes
       Microsoft YaHei: msyh.ttf 15043584 bytes
       SimHei: simhei.ttf 10044356 bytes
    with bitmap:
       SimSun/NSimSun: simsun.ttf 10500792 bytes
       SimSun-18030/NSimSun-18030: simsun-18030.ttf 12642204
       WenQuanYi Zen Hei: wqy-zenhei.ttf 12844372 bytes
    checked by Linux tool: fontforge
-->
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <string>SimSun</string>
            <string>NSimSun</string>
            <string>SimSun-18030</string>
            <string>NSimSun-18030</string>
        </test>
        <test name="pixelsize" compare="eq" >
            <double>12</double>
            <double>13</double>
            <double>14</double>
            <double>15</double>
            <double>16</double>
            <double>18</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <string>WenQuanYi Bitmap Song</string>
        </test>
        <test name="pixelsize" compare="more_eq" >
            <double>9</double>
        </test>
        <test name="pixelsize" compare="less_eq" >
            <double>12</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <string>WenQuanYi Zen Hei</string>
        </test>
        <test name="pixelsize" compare="eq" >
            <double>12</double>
            <double>13</double>
            <double>15</double>
            <double>16</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
<!--
*******************************************************************************
    5. CJK fonts configuration [End]
*******************************************************************************
-->
</fontconfig>

上面的字体配置使用3种虚拟字体:

  • 衬线字体:Serif
  • 非衬线字体:Sans-serif/Sans serif/Sans
  • 等宽字体:Monospace/Mono

虚拟字体已经被定义在/etc/fonts/conf.d/ 下面的配置文件中,并拥有了一个字体列表,以上字体配置中的字体会被加在顶部,具有更高的优先级。并且,/etc/fonts/fonts.conf 中也为虚拟字体添加了可能采用的别名,比如mono。有关衬线字体与非衬线字体,请参看:细说字体 Sans Serif 与 Serif

在上面,我定义了:对于衬线字体,中文使用宋体,英文使用Georgia;非衬线的字体,中文使用微软雅黑,英文使用Verdana;等宽字体,中文使用新宋体,英文使用Courier New,共6种字体。其中,除了中文字体需要自己额外安装以外,其它英文字体默认已经存在于/usr/share/fonts/corefonts 目录,它们属于media-fonts/corefonts ,如果你找不到这些字体,可以emerge 这个包。

如果想换不同的口味,只需要把上述6处字体名称替换为系统中已经安装的字体即可,为了方便配置,我在每一处增加了<!-- @@@ editable --> 这样的注释。

另外,有人觉得/etc/fonts/conf.d 下面的配置文件没什么用处,还可能干扰自己的配置,可以删除了事。我仔细看过,不提倡删除,如果删除的话,以下2个文件一定要保留,否则fontconfig 就不会读取~/.fonts.conf 与/etc/fonts/local.conf ,它们是这2个配置文件的装载入口。

  • 50-user.conf
  • 51-local.conf

下面是雅黑的效果截图:

screenshot-msyh.jpg

字体有关的命令 

下面介绍几个字体有关的命令,在配置过程中可能会用来进行配置的确认、除错等。

fc-list

列出系统中所有可用的字体名称(包含中英文别名),以及支持的style。

命令后面可加字体名称,但必须是全称,不支持通配符,否则无法匹配。如果是中文字体,要求环境为UTF-8,否则匹配不成功,输出也是乱码。字体名称如果包含空格,使用引号引起。

虚拟字体不会被列出。

fc-match  

列出字体文件名称、英文名称,不支持中文字体名匹配。同样不支持通配符,但支持虚拟字体,可以列出虚拟字体中优先级最高的字体。可以使用-v 参数输出字体详细信息。 

对于配置文件中进行过字体替换的字体,fc-match 会输出替换后的字体名称

$ fc-match courier
cour.ttf: "Courier New" "Normal"
fc-cat

从cache 文件中读取字体信息,很少用到。

以上三个命令来自media-libs/fontconfig,属于xft 的命令。

xlsfonts

xlsfonts 也用于列出字体,但格式不同,此外,它也可以列出一些未被xft 系统识别并cache 的字体。同时这个命令也支持通配符。

$ xlsfonts -fn "*sim*"
-misc-simhei-medium-r-normal--0-0-0-0-p-0-iso10646-1
-misc-simsun 18030-medium-r-normal--0-0-0-0-m-0-iso10646-1
-misc-simsun 18030-medium-r-normal--0-0-0-0-m-0-iso8859-1
-misc-simsun 18030-medium-r-normal--0-0-0-0-m-0-koi8-r
-misc-simsun-medium-r-normal--0-0-0-0-p-0-iso10646-1
-misc-simsun-medium-r-normal--0-0-0-0-p-0-iso8859-1
-misc-simsun-medium-r-normal--0-0-0-0-p-0-koi8-r

如果系统中找不到这个命令,需要emerge x11-apps/xlsfonts

fontforge

这是一个GUI 程序,可用于编辑字体文件,同时也可以获得大量的字体信息,比如一个TrueType 字体是否内嵌了点阵字体,size是多少。对于MS的宋体,fontforge 只能识别出部分size 的点阵字体:12、14、16,13、15、18 则识别不出来,开时我认为是字体文件的版本问题,后来看了quanliking 的回帖才知道是fontforge 的问题。

如果系统中找不到这个命令,需要emerge  media-gfx/fontforge

Tips

如果字体没有变化,仅仅修改了字体配置文件,如果使用fc-match 这样的命令,不需要重启Xwindow。对于其它应用程序,比如gedit,仅仅重新运行这个程序即可应用新的配置,但有些应用程序则需要重启动Xwindow 才可以应用新的配置,比如gnome-terminal 。了解这些可以在测试字体配置的时候节省一些时间。

下载

  • fontconfig 配置文件:.fonts.conf(如果直接使用这个文件,请重命名为 .fonts.conf,下载的文件名中没有点)
  • 因为版权问题,不提供一些字体的下载,在Windows 系统以及本文链接的文章中可以找到。

延展阅读

(未完)

Gentoo Linux on T43 (6) 中文环境

如果是初次安装Gentoo 系统与配置中文环境,在读接下来内容之前,建议首先阅读Gentoo Linux Localization Guide。 Locale locale 名称是一个具有命名约定、带有格式的字符串,其实质是其背后对应的字符集(codeset)。这里有一篇文章 关于locale的设定 Simple HOWTO 可以帮助理解locale ,虽然我并不完全同意文中的所有 观点。 使用不带任何参数的locale命令可以查看当前系统中与locale...

如果是初次安装Gentoo 系统与配置中文环境,在读接下来内容之前,建议首先阅读Gentoo Linux Localization Guide

Locale

locale 名称是一个具有命名约定、带有格式的字符串,其实质是其背后对应的字符集(codeset)。这里有一篇文章 关于locale的设定 Simple HOWTO 可以帮助理解locale ,虽然我并不完全同意文中的所有 观点。

使用不带任何参数的locale命令可以查看当前系统中与locale 有关的变量,以及它们所采用的locale 名称。

$ locale
LANG=en_US
LC_CTYPE=zh_CN
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=  

在Gentoo 手册 6. 安装Gentoo基本系统 最后一节,作为可选,简单的介绍了如何生成locale。Gentoo 提供了/etc/locale.gen 文件,用于指定为glibc 生成哪些locale,籍此来控制生成的locale 数量,减小系统体积。查看当前系统中已经生成并可用的locale 有哪些,使用以下命令:

$ locale -a
C
en_US
en_US.utf8
POSIX
zh_CN
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

所有生成的locale 会被放在 /usr/lib/locale/ 下面的子目录,并且与locale 名称同名(除字符集部分的大小写)。(由于历史原因,C 与POSIX 是2个很特殊的locale)

$ ls -1 /usr/lib/locale/
en_US
en_US.utf8
zh_CN
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

locale.gen 文件内容具有如下格式,空格之前是locale 名称,locale 名称中可以不包含字符集的部分,空格之后是所对应的字符集。

en_US ISO-8859-1
en_US.UTF-8 UTF-8 

作为中文用户,为了系统可以正确的识别、显示并处理中文字符,必须生成与中文字符集有关的的额外locale。字符集可以采用以下之一:

  • GB18030
  • GBK
  • GB2312
  • UTF-8

其中除UTF-8  是Unicode 解决方案以外,其它三个是父子集关系,其中GBK18030 最为完整,但仍然建议按以下格式,添加GBK 与GB2312 字符集相关的locale 到locale.gen 文件:

en_US ISO-8859-1
en_US.UTF-8 UTF-8
zh_CN GB18030
zh_CN.GBK GBK
zh_CN.GB2312 GB2312
zh_CN.UTF-8 UTF-8 

为什么不单独使用最完整的GB18030 字符集?理由是为了向下与一些较早的应用程序保持兼容,这个方法来自于 最精简有效的 glibc locales 设定

如果见到有些文章介绍使用/etc/locale.build 文件和不同的格式做类似的事情,不要奇怪,请用以下命令查看你的glibc 版本,如果大于等于glibc-2.3.6-r4 ,那么请用本文的文件名与格式,否则升级glibc 或者按他说的做。

$ emerge -s %^glibc$
*  sys-libs/glibc
Latest version available: 2.6.1
Latest version installed: 2.6.1

设置locale 有关的环境变量

对于中文用户,一般可以分为2种

  1. 一般性中文要求,仅要求系统具有中文的处理能力。
    要求操作系统以及应用程序能够正确显示并处理中文字符,包括文件名、文本文件内容等,并且可以输入中文。
  2. 全面性中文要求,要求中文界面。
    在一般性要求之外,还要求操作系统以及应用程序的菜单、选项、以及消息等均尽可能以中文进行显示。

以上2种情况,分别对应了2种典型的locale 环境变量设置。

一般性中文要求

很多软件开发者,或者在国外的中文用户,会采用这种方案,好处是:

  • 有助于测试软件
  • 避免术语翻译不当或者语言习惯所带来的困扰
  • 在不影响中文处理能力的前提下,最大化英文的使用范围

推荐的环境变量配置:

export LANG=en_US
export LC_CTYPE=zh_CN
全面性中文要求

大部分普通用户会采用这种方案,对应的环境变量配置:

export LANG=zh_CN
export LC_ALL=zh_CN

这份指南中说明了所有LC_* 和LANG 变量的作用与关系,额外设置LANG,也是为了对个别不支持LC_ALL 的应用程序保持兼容性。

建议将上述变量设置在日常用户的profile 当中,比如:/home/user/.bash_profile,不建议设置在系统级别,对于Gentoo 这个文件是:/etc/env.d/02locale

G_BROKEN_FILENAMES

G_BROKEN_FILENAMES 是一个与Glib 有关的环境变量,把它作为小标题是因为它十分关键,曾因为它带来了很多困扰。

我们周围几乎所有的Windows 系统都设定为使用GB 编码中文文件名,而不是Unicode,任何Unicode 的编码的中文文件名在这些Windows下都会显示为乱码。因此我们与这样的Windows 系统交换包含中文文件名的文件,最好的方案就是也同样使用GB 编码文件名,这样就不会带来显而易见的麻烦。

通过以上的locale 设定,已经可以看出,我们的确在设定一个GB 编码的中文Gentoo ,而不是Unicode Gentoo,但总有一些事情出乎我们的意料。Gnome 以及几乎所有应用程序(已知除Gnome Terminal 以外)会无视以上的locale 设定,仍然使用UTF-8 编码中文文件名,以Nautilus 为代表,虽然他们可以同时正确的显示与处理GB 与UTF-8 编码的文件名,但另外的一些应用程序会说不,比如Gnome Terminal, Krusader 等等,其他Windows 用户或者FTP 用户也会抱怨。

要解决这个问题,就需要设置:

export G_BROKEN_FILENAMES=1 

 或者

export G_BROKEN_FILENAMES=yes 

设置这个变量后,需要重新启动系统才能生效,或者至少logout 之后重新启动X Window,比如kill 掉X 后回到命令提示符,logout 之后重新login,再执行一个startx。

有关这个变量作用的更多信息,请参考Display Name of Filename in Glib

中文输入法 Scim

Linux 下的中文输入法有很多,Xsim, Scim, Chinput, Xcin, Fcitx等等,我现在使用Scim ,其功能类似Windows下的紫光输入法,可以整句输入,也会动态加入新的词组并调整词频,但其智能性与现今Windows 平台的搜狗或者Google 输入法还有差距。

Scim for Gentoo 安装过程比较简单,我使用gnome 环境,没有安装kde,但安装了几个特别需要的kde 应用程序,因此,我的系统上也有qt3,qt4 以及kde 应用所必需的包。

For gnome 

首先,要让Scim 在gnome 环境工作,需要以下步骤:

  • 在make.conf 的USE 变量中加入 nls cjk unicode,如果它们还不在的话。
  • 为了安全起见,执行以下命令来检查是否有软件包会被这些新的USE 变量影响,如果有的话,那么就继续执行,否则退出即可。
# emerge -av --newuse world
  • 执行以下命令安装Scim
# emerge -av scim scim-pinyin
  • 设置以下环境变量(对于gnome 环境未设置也没有发现问题):
export XMODIFIERS=@im=SCIM    #case matters for this variable!
export GTK_IM_MODULE=scim
export QT_IM_MODULE=scim

重启系统,即可以在gnome 应用中使用ctrl+space 调出Scim 使用。

For kde 

为了能在kde 应用程序中调用Scim,需要继续完成以下步骤,如果不打算使用kde 应用程序,也可以跳过。

  • 在make.conf 的USE 变量中加入immqt-bc
  • 执行以下命令,确保qt3 使用immqt-bc USE flag 编译,否则,接下来的步骤会出错。
# emerge -av =qt-3*
[ebuild   R   ] x11-libs/qt-3.3.8-r4  USE="cups gif immqt-bc* mysql opengl xinerama -debug -doc -examples -firebird -immqt -ipv6 -nas -nis -odbc -postgres -sqlite" 135 kB 
  • 接下来安装qt 环境中用于支持im-module 的软件包(gnome 的gtk 内建im-module 支持) 以及skim:
# emerge -av scim-qtimm skim

安装完成后,就可以在kde 应用程序中使用scim 了。

在gnome 与kde 中scim 有2套不同的配置界面与输入条,具体使用哪一个,可以在选项中的General Scim 的Other 标签页中设置,当然,也可以不去关心它。

在kde 中配置Scim,花费了我不少时间,以下几篇是我参考的Scim 官方资源:安装简介for Gentoo,更详细的安装指南for Gentoo,针对一般Linux 发布的安装指南,但也有一定的参考价值。

非必须步骤 

以下步骤在安装指南 中有所提及,但经试验并非必须。

  • 安装scim-tables: 
$ emerge app-i18n/scim-tables

访问其它非Linux 分区

通常,移动硬盘、U盘、存储卡、MP3、Thinkpad 的第二块硬盘等移动设备,以及双启动的系统中会包含非Linux 分区,一般来说,它们会采用与Windows 兼容的FAT 分区,个别也可能是NTFS 分区。为了能在这些设备上正确显示和处理中文文件名,需要在mount 选项中指定字符集。

mount 是Linux 中一个基本的命令,可以将包括本地文件系统在内的多种文件系统映射为一个本地路径, 由于不同文件系统的特性差别,mount 针对不同的文件系统均支持一组不同的选项,这里需要用到iocharset。

对于FAT 或者NTFS 类型的分区,我们需要在mount 选项中包含:

iocharset=gb2312 

迄今为止,我们还不能在这里指定其它更完整的GB字符集:gbk 与gb18030 。对于NTFS 分区,新增一个选项nls,与原有iocharset 意义相同,仅仅是为了替换它,旧的选项也保留着。nls 在其它分区类型却没有提供,因此如果喜欢使用新的选项nls 那么需要注意其仅仅针对NTFS 分区有效。

针对不同的设备,我的fstab 如下:

# 双启动Windows分区
/dev/sda3               /mnt/w          vfat            noauto,noatime,user,ro,codepage=936,iocharset=gb2312    0 0
# 第二块硬盘 
#/dev/sdb2              /mnt/m          ntfs            noauto,noatime,user,iocharset=gb2312    0 0                                                                        
# usb 设备
/dev/sdc1               /mnt/u1         auto            noauto,noatime,user,iocharset=gb2312    0 0
/dev/sdc2               /mnt/u2         auto            noauto,noatime,user,iocharset=gb2312    0 0
/dev/sdc3               /mnt/u3         auto            noauto,noatime,user,iocharset=gb2312    0 0
/dev/sdc4               /mnt/u4         auto            noauto,noatime,user,iocharset=gb2312    0 0
/dev/sdc5               /mnt/u5         auto            noauto,noatime,user,iocharset=gb2312    0 0
# 光驱
/dev/sr0                /mnt/dvd        auto            noauto,noatime,user,ro,iocharset=gb2312    0 0

说明:

  1. 针对vfat 分区,为了安全起见,额外指定了codepage 选项,依据文档,似乎与8.3 短文件名转换有关,但我还不知道其具体会在什么情况下起作用。
  2. 对于usb 设备,分区类型指定auto,而不限制在vfat,以增加灵活性。
  3. 同样,光驱设备也没有限制为iso9660,指定了auto,原因同上。

如果不打算定义在fstab 中,只在命令行临时mount,或者为了测试,使用以下格式:

# mount -t vfat -o codepage=936,iocharset=gb2312 /dev/sda3 /mnt/w
# mount -t auto -o iocharset=gb2312 /dev/sdc1 /mnt/u1 

延展阅读

( 未完)

Gentoo Linux on T43 (5) 配置内核(kernel)

以下的内容,适合于正在按照Gentoo手册安装Gentoo Linux 系统,并且已经进行到:第7部分 配置内核 的人。此外,也适合那些已经安装了Gentoo 系统,打算调整内核配置或者需要升级内核的人。 内核版本:gentoo-sources-2.6.23  不同的内核 在网络上,我们经常会看到很多命名不同的Linux kernel 以及它们所对应的patchs,比如: git-sources, mm-sources 等等,它们分别代表了不同的含义,vanilla-sources 是官方...

以下的内容,适合于正在按照Gentoo手册安装Gentoo Linux 系统,并且已经进行到:第7部分 配置内核 的人。此外,也适合那些已经安装了Gentoo 系统,打算调整内核配置或者需要升级内核的人。

内核版本:gentoo-sources-2.6.23 

不同的内核

在网络上,我们经常会看到很多命名不同的Linux kernel 以及它们所对应的patchs,比如: git-sources, mm-sources 等等,它们分别代表了不同的含义,vanilla-sources 是官方 的定期发布版本,未经过任何修改与patch,而git-sources 则每天更新,是vanilla-sources 的开发快照。其它的,诸如mm-sources 是一个增加了补丁集合的版本,由Andrew Morton 进行维护。

这些kernel 也包含在Gentoo 的官方Package 列表里面,可以使用emerge 命令进行安装(虽然Gentoo 并不推荐),Gentoo 也为它们提供了一个概要的描述

在Gentoo手册中要求安装的gentoo-sources 也与它们类似,属于Gentoo Team 维护的一个经过patch 的版本。我们接下来的讨论都是基于此内核。

T43 有关的内核配置

这一节讨论与硬件有关的内核配置选项,以下的内容源于我在网上查找的资料以及自己的经验,有出处的的方我尽量附上链接。对于内核中配置的选择,我尽量摒除无用的选项,以减小内核文件的体积和生成的Modules 规模,但由于我的知识所限,以及个人喜好,仍然会有很多有争议的的方,如果您认为是一个错误,欢迎指正。

T43 不同型号的配置可能会有差别, 以下每一项设备后面,都标出了可能配备的硬件型号,这些硬件信息来源于ThinkWiki ,在开始之前,多花些时间,了解您的Thinkpad 含有哪些硬件,是值得的。

CPU

Intel Pentium M (Dothan) 1.6, 1.73, 1.86, 2.0, 2.13 or 2.26 GHz CPU

CONFIG_X86_PC=y
CONFIG_MPENTIUMM=y
CONFIG_X86_GENERIC=y
主板南桥 

Intel 82801FBM ICH6-M southbridge

CONFIG_I2C_I801=m 
电源管理
CONFIG_PM=y
CONFIG_PM_SLEEP=y
CONFIG_SUSPEND_UP_POSSIBLE=y
CONFIG_SUSPEND=y
CONFIG_HIBERNATION_UP_POSSIBLE=y
CONFIG_ACPI=y
CONFIG_ACPI_SLEEP=y
CONFIG_ACPI_AC=y
CONFIG_ACPI_BATTERY=y
CONFIG_ACPI_BUTTON=m
CONFIG_ACPI_FAN=m
CONFIG_ACPI_DOCK=m
CONFIG_ACPI_BAY=m
CONFIG_ACPI_PROCESSOR=m
CONFIG_ACPI_THERMAL=m
CONFIG_ACPI_BLACKLIST_YEAR=0
CONFIG_ACPI_DEBUG=y
CONFIG_ACPI_DEBUG_FUNC_TRACE=y
CONFIG_ACPI_EC=y
CONFIG_ACPI_POWER=y
CONFIG_ACPI_SYSTEM=y
CONFIG_X86_PM_TIMER=y
CPU 频率调节
CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_TABLE=y
CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y
CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
CONFIG_CPU_FREQ_GOV_POWERSAVE=y
CONFIG_CPU_FREQ_GOV_USERSPACE=y
CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
CONFIG_X86_ACPI_CPUFREQ=m
Fn + Keys
CONFIG_THINKPAD_ACPI=m
CONFIG_THINKPAD_ACPI_BAY=y
硬盘/光驱
  • 40, 60 or 80GB PATA HDD1
  • UltraBay Slim with one of the following:
    • DVD-ROM
    • DVD-ROM/CD-RW Combo
    • DVD±RW

有关PATA ,其实就是传统的、使用扁线缆的ATA 硬盘,是对应新的SATA 硬盘而提出的名称。T43 使用PATA 硬盘,但控制器是SATA 的。

前面文章中,提到了硬盘/光驱设备名称的问题 ,以下的设置会决定设备使用哪一种驱动程序,也决定了设备名使用sd* ,还是hd*。

如果打开CONFIG_IDE 选项,那么设备将会识别为hd* ,即使同时打开了scsi 的有关选项。因此,应该关闭CONFIG_IDE 及其以下的所有选项,无论它看起来多么正确,或者你仅仅为了保持兼容性,它都会强制使用落后的驱动程序,硬盘传输速度将遭受明显损失,CPU 占用率也明显提高。方案来源:Desktop Lags under Heavy IO

# CONFIG_IDE is not set
#
# SCSI device support
#
# CONFIG_RAID_ATTRS is not set
CONFIG_SCSI=y
CONFIG_SCSI_DMA=y
CONFIG_SCSI_NETLINK=y
CONFIG_SCSI_PROC_FS=y
#
# SCSI support type (disk, tape, CD-ROM)
#
CONFIG_BLK_DEV_SD=y
CONFIG_BLK_DEV_SR=y
CONFIG_CHR_DEV_SG=y
#
# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
#
CONFIG_SCSI_WAIT_SCAN=m
#
# SCSI Transports
#
CONFIG_SCSI_SPI_ATTRS=y
CONFIG_SCSI_FC_ATTRS=m
CONFIG_ATA=y
CONFIG_ATA_ACPI=y
CONFIG_ATA_PIIX=y
CONFIG_PATA_MPIIX=m
CONFIG_MD=y
CONFIG_BLK_DEV_DM=y
CONFIG_DM_CRYPT=y
显卡

ATI X300 有2种驱动方案,一种是开源驱动,一种是ATI 官方的闭源驱动(已经加入Gentoo Package 列表),闭源驱动对3D 加速支持的更好一些,不过最近开源社区的R300 项目已经可以支持X300 显卡的3D 加速功能了。对于内核配置之外的内容,将来讨论。

以下内核选项对显卡系统起到支持作用,确保已经配置(来源于Gentoo ATI Radeon FAQ: 2.1 - Which kernel options are important for the ATI drivers?

CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_KMOD=y
CONFIG_PCI=y
CONFIG_MTRR=y
CONFIG_TMPFS=y

下面讨论与显卡直接相关的内核选项。

使用开源驱动程序,仅仅需要配置以下2项即可。

CONFIG_DRM=m
CONFIG_DRM_RADEON=m

CONFIG_DRM 与CONFIG_DRM_RADEON 编译为module 会分别对应为drm 与radeon 。

如果使用官方驱动,仅配置以下选项即可

CONFIG_DRM=m

另外一种选择,可以在内核disable CONFIG_DRM 选项,然后在外面emerge x11-base/x11-drm 软件包。

有很多人在论坛上问,X300 是否需要配置CONFIG_AGP(对应agpgart module),X300是 PCIe 接口,经过测试,不需要配置CONFIG_AGP ,无论是内建,还是Module,虽然加入AGP 支持可能不会产生错误,但也不会带来任何性能提升。以下FAQ 也可以作为参考: 2.1 - Which kernel options are important for the ATI drivers? 

NOTE 2: if you have a PCIe card, the AGP settings should be irrelevant. If you encounter problems, make sure you're using a recent kernel and the latest driver version. Some people have also reported that they had to enable AGP for their PCIe cards to work.

...
If you're using a PCIe card, then as noted above, it shouldn't be necessary to enable AGP, but it may be worth trying if you have problems. 

网卡

Broadcom 10/100/1000 Ethernet

CONFIG_TIGON3=m  
无线网卡

Intel 2200/2915 芯片可以使用内置驱动程序

CONFIG_IPW2200=m 
Bluetooth/Modem
声卡 

AD1981B AC'97 Audio controller

内核支持很多种类的声卡驱动,主要包括2种:ALSA 与OSS,如下。几年前在Linux 下装声卡驱动程序,都是用OSS,不过现在有了更好的ALSA

<*> Sound card support
Advanced Linux Sound Architecture  ---> 
Open Sound System  ---> 

对于T43,我们可以使用内核中的ALSA 驱动程序,选项CONFIG_SND_INTEL8X0 为此提供支持,CONFIG_SND_INTEL8X0M是对Modem 的支持,也要选择上。

以下是在我的系统中设定的所有与声卡有关的内核选项:

CONFIG_SOUND=y
CONFIG_SND=m
CONFIG_SND_TIMER=m
CONFIG_SND_PCM=m
CONFIG_SND_HWDEP=m
CONFIG_SND_RAWMIDI=m
CONFIG_SND_SEQUENCER=m
CONFIG_SND_OSSEMUL=y
CONFIG_SND_MIXER_OSS=m
CONFIG_SND_PCM_OSS=m
CONFIG_SND_PCM_OSS_PLUGINS=y
CONFIG_SND_SEQUENCER_OSS=y
CONFIG_SND_MPU401_UART=m
CONFIG_SND_AC97_CODEC=m
CONFIG_SND_DUMMY=m
CONFIG_SND_VIRMIDI=m
CONFIG_SND_MTPAV=m
CONFIG_SND_MPU401=m
CONFIG_SND_INTEL8X0=m
CONFIG_SND_INTEL8X0M=m
CONFIG_SND_AC97_POWER_SAVE=y
CONFIG_AC97_BUS=m 

另外还有一种方案,即使用外面的ALSA 驱动程序,可以直接在alsa 项目 的主页下载 alsa-driver。

有关内核以外的配置,后面单独讨论。

PCMCIA *2

CardBus slot (Type 2) (未测试)

ExpressCard/54 slot (未测试)

HDAPS 硬盘动态保护系统

IBM Active Protection System(使用第三方驱动)

Fingerprint Reader 指纹识别

Integrated Fingerprint Reader(使用第三方驱动)

嵌入式加密

IBM Embedded Security Subsystem 2.0 (未测试)

键盘、指点杆、触摸板、usb鼠标

UltraNav (TrackPoint / Touchpad combo) (整理中)

内核选项如下:

CONFIG_INPUT=y
CONFIG_INPUT_MOUSEDEV=y
CONFIG_INPUT_MOUSEDEV_PSAUX=y
CONFIG_INPUT_MOUSEDEV_SCREEN_X=1400
CONFIG_INPUT_MOUSEDEV_SCREEN_Y=1050
CONFIG_INPUT_EVDEV=y
CONFIG_INPUT_KEYBOARD=y
CONFIG_INPUT_MOUSE=y
CONFIG_INPUT_MISC=y
CONFIG_INPUT_UINPUT=m
CONFIG_MOUSE_PS2=y
CONFIG_MOUSE_PS2_ALPS=y
CONFIG_MOUSE_PS2_LOGIPS2PP=y
CONFIG_MOUSE_PS2_SYNAPTICS=y
CONFIG_MOUSE_PS2_LIFEBOOK=y
CONFIG_MOUSE_PS2_TRACKPOINT=y

 

非T43 相关特性的内核配置

这些配置不再一一列举,请见配置文件:config-2.6.23

Tips

查看当前运行系统的内核配置

$ zcat /proc/config.gz |grep -i drm  

延展阅读

(未完)

Gentoo Linux on T43 (4) 驱动无线网卡

识别无线网卡型号 T43 内置的无线网卡有多种型号,为以下之一: IBM 11a/b/g Wireless LAN Mini PCI Adapter II Intel PRO/Wireless 2200BG Mini-PCI Adapter...

识别无线网卡型号

T43 内置的无线网卡有多种型号,为以下之一:

它们使用了不同的芯片,也需要使用不同的驱动程序。因此,在着手驱动无线网卡之前,要弄清楚网卡的型号。

我的IBM 11a/b/g Wireless LAN Mini PCI Adapter II 使用了Atheros 的AR5212 系列芯片,可以使用以下命令确认:

# lspci |grep Ethernet
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5751M Gigabit Ethernet PCI Express (rev 11)
0b:02.0 Ethernet controller: Atheros Communications, Inc. AR5212 802.11abg NIC (rev 01)

安装驱动程序

2200/2915 芯片 

对于Intel 2200/2915芯片的无线网卡,Linux 内核内置了驱动程序,如下图,如果你的网卡在此列,那么在配置内核时需要选中,如果标记为<M>,那么在编译内核后,需要将其加入文件:/etc/modules.autoload.d/kernel-2.6,在下次启动系统时,这个Module 就会自动装载。

usr-src-linux.gif

AR5212 芯片 

对于AR5212 系列芯片,必须安装第三方驱动程序。幸运的是,Gentoo 的Package  列表已经加入了madwifi 为其编写的驱动程序与工具:net-wireless/madwifi-ng 与 net-wireless/madwifi-ng-tools,使用以下命令即可以安装:

# emerge -av madwifi-ng
# emerge -av madwifi-ng-tools

安装完成之后,会编译出一个新的Module: ath_pci,将其加入文件:/etc/modules.autoload.d/kernel-2.6。

# echo ath_pci >> /etc/modules.autoload.d/kernel-2.6 

可以通过以下命令查看当前装载的Modules:

$ lsmod 

如果希望手工卸载或者装载一个Module ,用以下命令实现:

# modprobe -r <Module_Name>
# modprobe <Module_Name>

若Modules 之间存在依赖关系(可以在lsmod 的输出中查看),则需要一层一层的卸载,但有些依赖不会显示出来,导致无法卸载,这时可以使用以下命令强制卸载:

# rmmod --force <Module_Name> 

待确认所需Module 已经加载,执行ifconfig 命令,应该可以看到新的网络接口,一般会是ath0。接下来可以使用iwlist  来查找附近的无线接入点:

# iwlist ath0 scan 
ath0      Scan completed :
Cell 01 - Address: 00:07:40:ED:87:02
ESSID:"alexzhangsatgmaildotcom"
Mode:Master
Frequency:2.462 GHz (Channel 11)
Quality=17/70  Signal level=-78 dBm  Noise level=-95 dBm
Encryption key:on
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Extra:bcn_int=100

找到后,使用iwconfig 配置连接信息:

# iwconfig ath0 essid alexzhangsatgmaildotcom 
# iwconfig ath0 key XXXXXX

第二步为加密的连接指定密钥,若无线AP 上Encryption key 没有启用,则省略第二步。对于使用WEP 静态密钥加密的无限AP 测试成功,其它加密方式未经测试。密钥要求是十六进制格式,如果是ASCII 格式,使用这样的格式:s:XXXXXX

最后,使用dhcp 向AP 请求IP 地址:(假定你使用dhcpcd 客户端)

 # dhcpcd ath0

若dhcpcd 成功获取了IP 地址,那么无线网络连接建立成功。

NOTE

  • 给出的命令如果前面带有#,那么默认需要root 权限执行。
  • 如果在执行lspci, lsusb, lsmod 等命令时遇到找不到命令的错误,那么需要安装以下对应的包:
# emerge -av sys-apps/pciutils sys-apps/usbutils sys-apps/module-init-tools
  • 我不太清楚iwconfig 可以识别多少种加密连接,对于更多样的加密连接,需要安装net-wireless/wpa_supplicant。

Troubleshooting

升级内核 从2.6.20-r8 到2.6.23 ,madwifi 无线网卡不工作

Module ath_pci load 失败。

这是一个bug ,需要安装一个补丁patch-madwifi-r2630-2.6.23-build-fix.diff ,然后重新emerge madwifi-ng。否则re-emerge madwifi-ng会有file_operations错误。

因为内核升级,sandbox 也会引起问题, 在emerge madwifi-ng过程中会有"access violation summary" 错误。

临时方案:-sandbox

# FEATURES=-sandbox emerge madwifi-ng 

解决方案: 升级 sandbox 从 1.2.18.1 到1.2.18.1-r1或者更新版本

# emerge --sync && emerge sandbox-1.2.18.1-r1 

重新emerge madwifi-ng 成功后,ath_pci 可以load 成功。

(未完)

Gentoo Linux on T43 (3) 安装指南的指南

指南  我并不打算重新写一篇Gentoo手册 ,这既远远的超出了我的能力范围,又显得毫无意义。果已经打算开始安装Gentoo Linux,那么请详细阅读官方手册,并按步实施,这篇文档会额外介绍一些笔者在安装过程中遇到的一些问题,以及心得,并附上一些有用的链接。其中大部分 内容与Thinkpad T43 有关,另外一部分会涉及到有关IBM 的一些应用环境,一并介绍(更新:这部分将单独写一份文档)(2008-3-12: 因为涉及一些受限访问的资源,很难整理区分,不打算发布了,有兴趣的朋友可以来信交流)。 为了顺利的安装Linux,相对于Windows 我们需要更多的关注硬件信息,这有助于选择合适的驱动程序,或者在网络上寻求正确的帮助。ThinkWiki 包含了非常丰富的各型号Thinkpad 硬件特性,以及在多种Linux 发布下所获得的支持,虽然,由于Linux 发布的区别,部分内容不能直接在Gentoo 下应用,但这大概是目前这方面最好的资源了。...

指南 

我并不打算重新写一篇Gentoo手册 ,这既远远的超出了我的能力范围,又显得毫无意义。果已经打算开始安装Gentoo Linux,那么请详细阅读官方手册,并按步实施,这篇文档会额外介绍一些笔者在安装过程中遇到的一些问题,以及心得,并附上一些有用的链接。其中大部分 内容与Thinkpad T43 有关,另外一部分会涉及到有关IBM 的一些应用环境,一并介绍(更新:这部分将单独写一份文档(2008-3-12: 因为涉及一些受限访问的资源,很难整理区分,不打算发布了,有兴趣的朋友可以来信交流)。

为了顺利的安装Linux,相对于Windows 我们需要更多的关注硬件信息,这有助于选择合适的驱动程序,或者在网络上寻求正确的帮助。ThinkWiki 包含了非常丰富的各型号Thinkpad 硬件特性,以及在多种Linux 发布下所获得的支持,虽然,由于Linux 发布的区别,部分内容不能直接在Gentoo 下应用,但这大概是目前这方面最好的资源了。

此外,这里有一份Windows 软件类似替代列表 , 有人负责维护更新,但中文版本更新很慢,网络上广泛转载的版本也是出于此。

提纲 

下面的目录,是我为后续内容列出的一个提纲,我也可能会一边写,一边修改它。

  1. 驱动无线网卡
  2. 配置内核(kernel)
  3. 中文环境
  4. 中文字体
  5. X300 显卡的驱动以及3D 加速
  6. HDAPS 硬盘动态保护系统
  7. Fingerprint Reader 指纹认证
  8. CPU 频率自动控制
  9. Java 环境
  10. 应用程序中字体的纠正
  11. 内存虚拟盘加速系统
  12. 声卡驱动
  13. 总结

在我今天回来整理这个文档的时候,我才发现Gentoo手册已经多出了一个中文版本 ,与最新的英文版 同步,这也看出Gentoo中文社区发展的迅速。

参考信息

(未完) 

Gentoo Linux on T43 (2) 安装之前

在安装之前,需要做一些简单的决定,以为将来节省一些时间,涉及以下几个方面: 安装所在物理硬盘 T43 可以通过硬盘托架安装第二块内置硬盘,并获得与第一块硬盘相同的性能,虽然占用了光驱位置,但也是一种扩展存储或者实现快速备份的方案。如果仅仅使用第一块硬盘,可以跳过这一小节。 如果打算安装在第二块硬盘,那么有一点需要注意,即对第二块硬盘的设备名称的引用。 正常情况下,第一块硬盘会被设别为/dev/hda 或者/dev/sda (具体为哪一个,依赖于在配置内核参数时所选择的驱动程序,后面会具体讲到),而第二块硬盘会被识别为/dev/hdb 或者/dev/sdb。 但当在启动时,使用F12 改变启动顺序,更改到第二块硬盘启动,则情况刚好反过来,第二块硬盘会识别为hda/sda ,第一块硬盘变为hdb/sdb。因此,需要决定平时以哪一种方式来启动第二块硬盘上的Linux 系统,以决定如何编写/boot/grub.conf 以及/etc/fstab 文件。...

在安装之前,需要做一些简单的决定,以为将来节省一些时间,涉及以下几个方面:

安装所在物理硬盘

T43 可以通过硬盘托架安装第二块内置硬盘,并获得与第一块硬盘相同的性能,虽然占用了光驱位置,但也是一种扩展存储或者实现快速备份的方案。如果仅仅使用第一块硬盘,可以跳过这一小节。

如果打算安装在第二块硬盘,那么有一点需要注意,即对第二块硬盘的设备名称的引用。

正常情况下,第一块硬盘会被设别为/dev/hda 或者/dev/sda (具体为哪一个,依赖于在配置内核参数时所选择的驱动程序,后面会具体讲到),而第二块硬盘会被识别为/dev/hdb 或者/dev/sdb。

但当在启动时,使用F12 改变启动顺序,更改到第二块硬盘启动,则情况刚好反过来,第二块硬盘会识别为hda/sda ,第一块硬盘变为hdb/sdb。因此,需要决定平时以哪一种方式来启动第二块硬盘上的Linux 系统,以决定如何编写/boot/grub.conf 以及/etc/fstab 文件。

说到这里给一点小小的建议,我使用了第二块硬盘托架,最初希望在第一块硬盘上运行Windows 来作为日常工作系统,在第二块硬盘安装Linux 作为个人系统。但最终,我把它放在了第一块硬盘,并且在工作和个人时间都使用它,第二块硬盘仅仅作为备份使用。我的建议是,如果打算把Linux 作为一个主要的系统来使用,那么装在托架内是不大方便的。

安装媒介

安装过程需要使用光驱引导安装光盘上的系统,如果安装在第二块硬盘,则无法使用内置光驱,那么需要额外准备一个USB 或者PCMCIA 接口的光驱。

是否还需要Windows

我想大多数人是需要的,尽管Linux 已经拥有了众多功能丰富的应用以及Windows 方案的替代,但以下几项仍会成为我偶尔启动Windows 的理由:

  • 部分网上购物的支付过程
  • 使用网上银行系统
  • 证券交易系统

其它几乎我的所有工作以及个人需求,都能在Linux 下得到很好的满足,极少部分应用可能需要使用Wine 模拟Windows 环境进行运行,但速度以及稳定性感觉不到任何差别,有关应用后面会专门介绍。

另外有一个方案,可以给极少需要使用Windows 系统但仍不可或缺的人,即在Linux 系统运行一个virtualbox 虚拟机,并安装一个Windows 系统,这样可以在不重启Linux 的情况下访问Windows 应用。

多系统共存与引导

Gentoo Linux 使用grub 作为引导程序,grub 提供了强大的命令行支持,可以在启动失败时重新修改启动参数,查看启动环境,甚至访问分区上的文件。

我习惯于将grub 安装于主硬盘的MBR,然后在grub.conf 中配置对不同操作系统的访问条目。在为不同的系统分配分区时,有一个需要注意的地方,最好将包含有每一个系统引导文件的分区,放在硬盘的1024扇区(约8.4G)以内,对于Linux 是存放内核文件的Boot 分区,对于Windows 是存放ntldr 文件的分区,否则可能会在启动时引起麻烦。有兴趣可以参考 Windows XP 与Linux多系统引导的进一步探讨中的第7小节。

另外,同一块硬盘只允许有4个主分区(由于历史以及MBR 空间的限制),其它分区必须作为逻辑分区存在于扩展分区(注意:扩展分区也占用一个主分区的位置),我习惯于以下的划分方法:

主分区: 

sda1:    Linux 启动分区
sda2:    Linux 交换分区
sda3:    Windows系统分区
sda4:    扩展分区

逻辑分区: 

sda5:    Linux 根分区
sda6:    其它分区
...

(未完)

Gentoo Linux on T43 (1) 为什么使用Gentoo

吸引你的特色  Gentoo Linux 是众多Linux 系统发布版本中的一种,具有2个主要特色: 自动化的软件包获取与安装过程 软件尽可能以源码形式分发 Gentoo 拥有一个自动化的软件包分发与安装机制,称为Portage,是从FreeBSD 借鉴而来。简而言之,就是人们只需关心需要什么软件,而无需关心如何获取安装文件、如何进行安装,甚至对于安装所依存的软件包也无需关注,软件的版本升级也变得很简单,这一切都由Portage 系统来照顾。 此外,Gentoo Portage 系统中的软件包大部分是以源码形式分发,除少量版权允许的闭源软件是以二进制形式分发以外,大部分需要编译,不过整个过程包括编译前的配置是自动进行的,对于没有编译经验的人也可以顺利完成大部分软件的安装。 由此,Gentoo Linux是一个配置性非常强的系统,经过优化的二进制代码包更节省系统资源,十分适于作为一台开发工作站的桌面系统。...

吸引你的特色 

Gentoo Linux 是众多Linux 系统发布版本中的一种,具有2个主要特色:

  1. 自动化的软件包获取与安装过程
  2. 软件尽可能以源码形式分发

Gentoo 拥有一个自动化的软件包分发与安装机制,称为Portage,是从FreeBSD 借鉴而来。简而言之,就是人们只需关心需要什么软件,而无需关心如何获取安装文件、如何进行安装,甚至对于安装所依存的软件包也无需关注,软件的版本升级也变得很简单,这一切都由Portage 系统来照顾。

此外,Gentoo Portage 系统中的软件包大部分是以源码形式分发,除少量版权允许的闭源软件是以二进制形式分发以外,大部分需要编译,不过整个过程包括编译前的配置是自动进行的,对于没有编译经验的人也可以顺利完成大部分软件的安装。

由此,Gentoo Linux是一个配置性非常强的系统,经过优化的二进制代码包更节省系统资源,十分适于作为一台开发工作站的桌面系统。

有关特色,可以到这里阅读更多的内容

可能放弃的理由 

一些其它Linux 发布默认提供了非常丰富的软件包,Linux 系统安装完成之后,这些软件也都可以使用了,而Gentoo 的安装大体上就要分为几个阶段:(1)通过光盘启动系统并配置网络,(2)安装系统基本文件以及Portage 系统,(3)配置并编译内核,(4)必需的基本系统设置, (5)至此才开时安装额外所需的系统与应用软件。

这些软件需要使用者自己做出选择,有时安装过程也会遇到各种各样的问题,要考验使用者的动手能力,尤其对于中文用户,有关locale、字体、文件名编码以及输入法等,还有更多工作要做。有一些Linux 发布在第一次安装时,甚至就不需要查看安装手册,而我在第二次安装Gentoo 时,却依然需要分步查阅这个内容丰富的在线安装指南。因此,相对于一般的其它的Linux 发布,Gentoo 可能会耗费你更多,甚至是成倍的时间,来获取一些不知所谓的好处,或者是乐趣什么的东西。

有关选择的一个小建议 

某些时候,面对如此之多的选择,会无所适从,其它的Linux 发布我了解很少,只用过Redhat,所以,这里也不做比较,在了解了一个系统的优点和缺点之后,如果还无法决定,那就亲自试试,毕竟,在这里阅读文字也会浪费时间,结果无非两个,或许会陶醉其中,或是浅尝辄止回来继续你的美好生活。

另外一个选择,如果你相信“占卜”,也可以把你的选择权交给 Linux Distribution Chooser

更新 2008-03-21

今天碰巧看到一篇文章,我為什麼採用 Gentoo 當作我的系統. 后面列举了一些缺点,1..7 ,但对已经成文Gentoo 用户的人来说,是一些不错的Tips。

(未完)

延展阅读

Subversion 安装笔记

subversion 是一个开源的版本控制软件,虽然在稳定性方面较cvs还有些距离,不过很受追捧,牛顿顿说,这主要得益于subversion在处理大项目效率方面的优势,目前版本是1.4.4。 安装subversion 服务 在这里 下载subversion 的windows 平台软件包,解压缩即可。 然后打开一个DOS 命令行,进入到解压缩的bin目录,运行以下命令创建一个repository(存放版本控制信息的地方)。把PROJECT_NAME 替换为你需要的项目名称。 C:\svn\bin> mkdir \repository\subversion\PROJECT_NAME C:\svn\bin>...

subversion 是一个开源的版本控制软件,虽然在稳定性方面较cvs还有些距离,不过很受追捧,牛顿顿说,这主要得益于subversion在处理大项目效率方面的优势,目前版本是1.4.4。

安装subversion 服务

这里 下载subversion 的windows 平台软件包,解压缩即可。

然后打开一个DOS 命令行,进入到解压缩的bin目录,运行以下命令创建一个repository(存放版本控制信息的地方)。把PROJECT_NAME 替换为你需要的项目名称。

C:\svn\bin> mkdir \repository\subversion\PROJECT_NAME
C:\svn\bin> svnadmin create \repository\subversion\PROJECT_NAME

然后参照这里的安装指南 把subsersion安装为windows系统服务,并在启动时加载。意等号后面必须留有空格。

C:\svn\bin> sc create svn binpath= "C:\svn\bin\svnserve.exe --service 
-r C:\repository\subversion" displayname= "Subversion Server" 
depend= Tcpip start= auto

注意:执行命令时,需要把subversion 的安装路径以及repository 的路径替换成你自己的路径。svn 是服务名称,你也可以随便命名。

这个系统服务可以通过 sc delete svn 命令删除,服务的启动有两种方式:sc start svn 或者 net start svn 。具体可以参考windows 的sc  以及net 命令。

配置版本库权限

配置文件位于 .\repository\subversion\PROJECT_NAME\conf\ 目录

passwd 文件定义了存取版本库的用户名与密码,格式为:

myusername - mypassword 

svnserve.conf 文件需要添加如下几行:

anon-access = noneauth-access = writepassword-db = passwd 

如够希望匿名用户可以checkout 版本库,那么修改第一行为 anon-access = read。 下面一行用于复杂一些的权限配置,如果添加此行,需要配置authz 文件,在这里我把此行注释掉。

# authz-db = authz 

另外还有一行用于定义Project名称,但经过实验,这行可以省略。

# realm = PROJECT_NAME 

至此,subversion 服务安装完成,并且创建了一个版本库。如果已经安装了subversion客户端,则可以通过svn://localhost/PROJECT_NAME 进行访问。

subversion 客户端

subversion 的客户端在windows 可以使用tortoiseSVN 或者subversion eclipes plugin. 

tortoiseSVN 是一个基于subversion服务的windows GUI,并集成了tortoiseMerge 版本比较工具。它和Windows 资源管理器紧密地结合在一起,以插件形式出现,来进行版本控制操作,当前版本也是1.4.4。

使用subversion eclipes plugin 需要先安装eclipes,然后通过插件更新安装subversion plugin,安装完成后,就可以像使用cvs 一样在eclipes 中使用subversion。

在这里下载 tortoiseSVN 1.4.4,安装完成之后,在资源管理器中点击右键,就会看到相关菜单。可以在资源管理器找到要管理的源代码,在目录上点击右键,选择TortoiseSVN 菜单中的Import ,并在Url of repository 下来菜单中选择刚才创建好的repository 即可。然后在working copy 目录中将代码checkout,就在working copy 目录中实现了代码的版本管理。

版本库备份

如果需要对项目版本库备份,只需要把整个.\repository\subversion\PROJECT_NAME 目录备份即可,如果需要在另一台还原备份,需要先安装好subversion服务与客户端(不必创建repository),然后把上述目录copy到svn服务所引用的目录中即可(本例为 c:\repository\subversion)。然后刷新subversion client,通过认证即可看到版本库。

参考信息

Windows XP 与Linux多系统引导的进一步探讨

以下是Windows XP 启动所需的三个文件: ntldr ntdetect.com boot.ini 有篇文章对此介绍得很详细 ,这里讨论其他的几个问题: 手动复制到根目录下的ntldr是否有效? 有效!与最早的DOS 系统不同,只要保证ntldr 在分区的根目录就行,并不关心这个文件在磁盘的那个扇区。(DOS系统启动所需的IO.SYS与MSDOS.SYS只能使用sys命令在启动分区产生) ntldr是否必须位于启动分区? 启动分区也称为活动分区,每个物理磁盘只能有一个分区被标记为启动分区,标记一般为:活动、*号 Active等。在MSDOS中使用fdisk...

以下是Windows XP 启动所需的三个文件:

  • ntldr
  • ntdetect.com
  • boot.ini

有篇文章对此介绍得很详细 ,这里讨论其他的几个问题:

  1. 手动复制到根目录下的ntldr是否有效?

    有效!与最早的DOS 系统不同,只要保证ntldr 在分区的根目录就行,并不关心这个文件在磁盘的那个扇区。(DOS系统启动所需的IO.SYS与MSDOS.SYS只能使用sys命令在启动分区产生)

  2. ntldr是否必须位于启动分区?

    启动分区也称为活动分区,每个物理磁盘只能有一个分区被标记为启动分区,标记一般为:活动、*号 Active等。在MSDOS中使用fdisk 命令标记,Windows 2000/XP中使用磁盘管理器标记,Linux 下使用fdisk 命令也可以标记。

    启动分区标记对于Windows 的意义要大于Linux,电脑启动时,在MBR 找到Windows 的引导记录之后,会继续寻找启动分区,找到后在根目录下寻找ntldr 文件,否则会引导失败。

    对于Linux 目前常用的引导程序grub,这个标记似乎没什么意义,甚至可以在fdisk中随意设置多个标记。

    回到刚才的问题:ntldr是否必须位于启动分区?

    1. 如果使用Windows 引导方式(MBR),那么ntldr必须位于启动分区。这里或许有个例外,就是可以调整bios的启动分区到ntldr所在分区。
    2. 如果使用grub之类的引导程序引导,则ntldr 可以位于任何分区。还有一个例外,后面说。

  3. ntldr 是否必须与系统(Windows目录)位于相同分区?

    不必!但ntldr 所在分区根目录必须要有boot.ini,并且boot.ini具备引导到系统分区的正确参数。

  4. 如何将grub或者Lilo 的MBR恢复回Windows MBR?

    1. Windows安装盘提供了内置的命令fixmbr来修复 ,可以很容易的恢复引导区记录(不是通常人们所建议的重新安装系统,并在拷贝文件之后退出,再手动清理安装临时文件。未经过测试)。

    2. 另外,这里也有一个第三方的工具mbrfix ,在这里下载 (未经过测试)。

    3. MSDOS 引导后,使用命令行 fdisk /mbr (我习惯使用这个方法)

  5. linux grub 启动管理器通过rootnoverify (hd0,2) chainloader +1 来加载ntldr,是如何做到的?

    上面的命令是告诉引导程序去hd0 设备的3号分区的第一个扇区加载操作系统启动程序。前面说过ntldr 并不位于物理第一扇区,为什么还可以加载呢?硬盘除了具有一个主引导记录(MBR)之外,另外在每个分区的头部还有分区引导记录,我想应该是"chainloader +1" 找到分区引导记录,并由分区引导记录找到并加载了ntldr 文件。

  6. 为什么通过rootnoverify (hd0,2) chainloader /ntldr 或者 chainloader (hd0,2)/ntldr加载会失败?

    chainloader 支持直接指定文件名来加载启动程序。但如果ntldr 位于ntfs 格式分区,上述命令会失败,我猜测原因是grub 在文件系统级别不支持读取ntfs 分区,当然也无法读取ntldr。vfat 分区我没有试验。

  7. 在使用grub 时,windows 系统或者ntldr 被安装在扩展分区的逻辑分区,与在主分区有什么不同?

    似乎没有什么不同,在上述情况下grub 引导成功。与上面第2条第2小点有相同的例外,马上讲到。

    例外情况:无论是ntldr 所在分区,还是linux /boot 所在分区,其起始点如果超过硬盘1024扇区(约8.4G),则MBR有可能无法访问到分区上的引导记录,当然也无法加载ntldr 或者linux 内核。要解决这个问题可以在BIOS 中为硬盘指定LBA 模式,grub 新的版本会自动检测LBA是否可用,并正确引导。

    这个网页包含grub 错误号码的详细解释 ,在引导出错时很有参考价值。比如,对于以上例外情况产生的错误,grup 返回错误码 18:

    	18 : Selected cylinder exceeds maximum supported by BIOS
    	This error is returned when a read is attempted at a linear block address beyond the end of the BIOS translated area. This generally happens if your disk is larger than the BIOS can handle (512MB for (E)IDE disks on older machines or larger than 8GB in general). 
    	

  8. grub是否可以跨物理硬盘引导操作系统?

    可以!对于Windows 及Linux 均引导成功。 

延展阅读

DreamHost 主机存在的安全隐患

Dreamhost 的空间已经用了个把月了(使用Fenng 的折扣代码购买 ),最欣赏的是它为用户提供登录Shell,在授权内可以运行绝大部分shell 命令,甚至允许添加cron job,让你在最大限度内保留自有主机的使用习惯。不过在带来灵活性的同时,如果使用不慎,风险也随之而来。下面是新建帐号系统默认建立的目录以及权限设置: [hostname]$ pwd /home/yourname [hostname]$ ls -l total 28 drwx--S---...

Dreamhost 的空间已经用了个把月了(使用Fenng折扣代码购买 ),最欣赏的是它为用户提供登录Shell,在授权内可以运行绝大部分shell 命令,甚至允许添加cron job,让你在最大限度内保留自有主机的使用习惯。不过在带来灵活性的同时,如果使用不慎,风险也随之而来。下面是新建帐号系统默认建立的目录以及权限设置:

[hostname]$ pwd
/home/yourname
[hostname]$ ls -l
total 28
drwx--S---   6 yourname groupname 4096 2006-12-27 04:29 Maildir
drwxr-x--x  33 yourname groupname 4096 2007-02-03 06:07 domain.com
drwxr-sr-x   3 root       root      4096 2006-12-26 15:50 logs

目录domain.com 是对应虚拟主机网站所属的根目录,当前的权限位是drwxr-x--x(751),网站如果希望被正常访问,所需的最小权限位是d--x--x--x(111)。而一般网站都有动态内容生成,比如使用cgi,那么作为运行此cgi 进程的用户则需要对相关目录和文件具有写权限,最小权限位是drwx--x--x(711)。

在深入讨论前,先回顾一下Unix 文件权限位的作用,如果你非常熟悉,请跳过。

每一个文件有10个标识位,第一位d代表目录,空(-)代表文件。其后9位分成三组,分别代表当前用户、同组用户、任何登录用户所对应的权限。r: 读权限,w: 写权限,x: 执行权限。这三种权限对于一个文件都很好理解,对于目录,如果拥有r读权限,可以列出目录下的文件,具有目录的w写权限和x执行权限,可以在目录中增加和删除文件。对于目录具有x执行权限,可以使用cd 命令进入此目录。

下面列出一些可能被误解的权限设置。 

例子一: 

drwx----wx /dir
-rwx------ /dir/1.txt

这种权限,虽然其他人无法列出目录dir 中的文件,也无法读取文件1.txt,但是如果已知文件名1.txt,依然可以删除文件,因为Unix 实际把目录也作为一个文件看待,目录实际保存了文件列表,对目录具有写权限就意味可以修改这个列表。

例子二:

drwx-----x /dir
drwx-----x /dir/dir2
-rwx---r-- /dir/dir2/1.txt

对于这种权限,其他人无法通过列目录方式获知文件路径/dir/dir2/1.txt ,但如果已知此路径,就可以读出文件内容。

安全漏洞 

默认的,Dreamhost 为你的home 目录设置如下权限:

[hostname]$ pwd
/home/yourname
[hostname]$ ls -ld .
drwxr-x--x  9 yourname groupname 4096 2007-02-03 06:00 .
 

这保证了任何本组以外的用户无法列出你的home 目录文件,但并不保证无法列出home 目录以下的子目录,这依赖于你的权限设置,而大多数用户都设置了一个非常宽松的权限。有关Dreamhost用户组的设置,下一个小节会讨论。

例子二就是本文讨论的目的,前面说过,对于网站所属的目录,为了保证正常浏览,对于所有目录都要求设置一个最小权限d--x--x--x(111),同时对于网站目录中的cgi 文件,我们通常设置为drwxr-xr-x(755),如果一个不怀好意者拥有一个与你相同主机上的shell 帐户,可以通过猜测或者其它途径获得你的敏感文件路径,然后使用以下命令轻松获得你的敏感信息,比如,人们通常把movable type 系统的数据连接信息保存在文件mt-config.cgi 中。

$ cat /home/yourname/yourdomain.com/mt/mt-config.cgi 

对于上面的安全问题,我有2种解决方法,一种是让人无法获知敏感文件的准确路径,但是这种方法非常具有局限性,即使实现,管理成本也很高。Dreamhost 已存在的一个安全漏洞使大部分未觉察的用户都暴露在此风险下。另一种方法是小心的配置敏感文件的权限,而对于非敏感文件则可以不作考虑。比如对于mt-config.cgi 文件,应该设置权限-rw-------(600),此文件虽然具有cgi 扩展名,不过仅仅是一个配置文件,只要保证以你的帐户身份运行的cgi 程序可以读取此文件即可。对于其它类似的敏感文件可根据情况进行类似权限设置。

更多的讨论

Dreamhost 允许用户建立多个shell 帐户,如果你打算同其他人share 你的host 空间,或者为你的朋友提供hosting,大概就需要为他们创建shell 登录帐户。默认的,这些新建的帐户将与你自己的帐户拥有相同的group,这个默认行为提供了一定的便利性,但也似乎无法改变,需要引起注意。应该根据情况,小心的为你自己的目录和文件设置组权限,并提醒与你share 主机的朋友做好自己的组权限设置(你们在同一个group 内),权限rwxrwx--- 黄底色的部分将影响到你们之间的关系。

如果确定了一个自己认为安全的权限位,并且适合大多数情况,则可以将此权限写入默认设置,使新建的目录和文件自动拥有此设置。这通过umask 命令 实现,并将其写入自己的profile 中。在Dreamhost 此文件位于 /home/yourname/.bash_profile, 并具有如下默认设定:

umask 002
此设置下,默认新建的目录具有权限drwxrwxr-x(775),文件具有权限-rw-rw-r--(664)。

在Dreamhost自动备份mysql数据库

今天准备在Dreamhost 上自动备份blog的DB,MySQL是Dreamhost唯一提供的关系数据库服务,当前版本5.0 我了解很少(这里有个学习笔记 ),已知可以在命令行使用mysqldump 命令备份整个数据库,备份时似乎无需了解数据库的当前状态(比如是否正在运行事务),它会自行处理,从备份出的文件看,mysqldump实现的是冷备份,也就是说,仅采用这种备份方法,数据仅能恢复到最后一次运行mysqldump的时间点。 MySQL也介绍了一个热备份工具mysqlhotcopy,不过文档中有以下声明,我不清楚什么是MyISAM 与ARCHIVE tables,也不大明白MySQL 热备份的恢复机制(如何前滚日志)。还好,我的数据库目前很小,而我的空间很大很大,每次全备份只花费很少的时间,也占用很小的空间。 mysqlhotcopy works only for backing up...

今天准备在Dreamhost 上自动备份blog的DB,MySQL是Dreamhost唯一提供的关系数据库服务,当前版本5.0 我了解很少(这里有个学习笔记 ),已知可以在命令行使用mysqldump 命令备份整个数据库,备份时似乎无需了解数据库的当前状态(比如是否正在运行事务),它会自行处理,从备份出的文件看,mysqldump实现的是冷备份,也就是说,仅采用这种备份方法,数据仅能恢复到最后一次运行mysqldump的时间点。

MySQL也介绍了一个热备份工具mysqlhotcopy,不过文档中有以下声明,我不清楚什么是MyISAM 与ARCHIVE tables,也不大明白MySQL 热备份的恢复机制(如何前滚日志)。还好,我的数据库目前很小,而我的空间很大很大,每次全备份只花费很少的时间,也占用很小的空间。

mysqlhotcopy works only for backing up MyISAM and ARCHIVE tables. It runs on Unix and NetWare.

使用mysqldump备份出来的文件,是一个包含了sql语句的文本文件,含有建表语句以及Insert语句。我采用这种方式恢复:连接到mysql进入mysql提示符,创建一个db(如果不存在),连接到此db,执行备份文件,如:

mysql> source ./mybackup.sql 

执行结束则恢复完毕。这里有篇日志 介绍了另外一种恢复方法(如下),不过我没有尝试过。 

$ mysqldump -u root -p'123456' test2 < samp.db.txt 

言归正传,我准备采用crontab 自动运行mysqldump 来自动备份数据库。写了一个shell脚本如下,备份文件使用当前系统时间(到分钟)作为文件名,备份成功后进行压缩。

backupdb.sh 

bakfile=~/xxx/mt-db_`date '+\%Y\%m\%d\%H\%M'|tr -d '\\\'`.sql
mysqldump -hmysql.mydomain.com -umyname -pmypasswd mt > $bakfile
gzip $bakfile
exit 0

然后在crontab中加入条目,定时自动运行此脚本。这里设置为每4个小时,在整点运行一次,每天产生一份日志。

00 0-23/4 * * * ~/xxx/backupdb.sh >> ~/xxx/logs/backupdb_`date '+\%Y\%m\%d'|tr -d '\\\'`.log 

经试验`date '+\%Y\%m\%d'|tr -d '\\\'`部分似乎不能被cron命令成功替换,但是在shell中是可以成功执行的。

$ echo backupdb_`date '+\%Y\%m\%d'|tr -d '\\\'`.log
backupdb_20070127.log

schedual awstats update on Dreamhost

My blog is hosted by Dreamhost, that is based on linux and allows crontab command....

My blog is hosted by Dreamhost, that is based on linux and allows crontab command. About cron here's good article for reference. To add a new schedual job, use following command in shell.

$crontab -e
then insert a line like this.
 
00 0-23/4 * * * /home/yourname/jobs/updawt.sh > /home/yourname/jobs/logs/updawt_`date '+\%Y\%m\%d\%H\%M'|tr -d '\\\'`.log 

That means run the script once every 4 hour each day. The code is for updawt.sh:

cd /home/yourname/aiview.com/cgi-bin/awstats/
./awstats.pl -config=aiview.com -update
exit 0

As the time of cron was not available, I used this solution.

 

# updawt.sh
# run this shell as:
#   nohup ./updawt.sh &
# then it will keep running in background whatever you
# logout your shell.
#
# this shell trigers the awstats to update httpd log for
# website aiview.com
#
# by alex, alezhangs@gmail.com, www.aiview.com
# last modified: Jan 18, 2007
cd /home/xxx/aiview.com/cgi-bin/awstats/
./awstats.pl -config=aiview.com -update
sleep 3600
. $0
exit 0
3600 is meaning 3600 second, 10 hours. Run this script as below on Linux, then logout.
$ nohup ./updawt.sh & 

Using "ps" shell command

Here's a normal output from ps command with -ef parameters./home/zhangy/> ps -ef UID PID PPID C...

Here's a normal output from ps command with -ef parameters.

/home/zhangy/> ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Dec 03 - 13:32 /etc/init
root 3932 1 0 Dec 03 - 0:01 /usr/lib/errdemon
root 4670 1 1 Dec 03 - 416:09 /usr/sbin/syncd 60
root 5196 7498 0 Dec 03 - 0:06 /usr/local/sbin/sshd
...
  • -e: Print all processes info except kernel processes.
  • -f: Here tells ps to show user name instead of user id at UID and to show parameters for command at CMD.
The explanation for each column.
  • UID: The user who kicked off the process
  • PID: The process ID of the process
  • PPID: The process ID of the parent process
  • C: Usage of CPU
  • STIME: The starting time of the process
  • TTY:
  • TIME: The total run time of the process
  • CMD: The command with parameters and its full path

Tips

We use PID and PPID to track process tree. For killing any process, we should refer to PID. To track PPID we could kill a group of related processes.

STIME is very helpful to indicate the multi-process with the same script name. Usually they have different run time.

CMD is also helpful to get command name and path. 

Reference 

A full reference on column explaination from unix man page.

ADDR
(-l and l flags) Contains the segment number of the process stack, if normal;
if a kernel process, the address of the preprocess data area.

BND
(-o THREAD flag) The logical processor number of the processor to which the
kernel thread is bound (if any). For a process, this field is shown if all its
threads are bound to the same processor.

C
(-f, l, and -l flags) CPU utilization of process or thread, incremented each
time the system clock ticks and the process or thread is found to be running.
The value is decayed by the scheduler by dividing it by 2 once per second. For
the sched_other policy, CPU utilization is used in determining process
scheduling priority. Large values indicate a CPU intensive process and result
in lower process priority whereas small values indicate an I/O intensive
process and result in a more favorable priority.

CMD
(-f, -l, and l flags) Contains the command name. The full command name and its
parameters are displayed with the -f flag.

COMMAND
(s, u, and v) Contains the command name. The full command name and its
parameters are displayed with the -f flag.

F Field Table

Flags Hexadecimal Value Definition

SLOAD 0x00000001 Indicates that the process is operating in core memory.

SNOSWAP 0x00000002 Indicates that the process cannot be swapped out.

STRC 0x00000008 Indicates that the process is being traced.

SWTED 0x00000010 Indicates that the process stopped while being traced.

SFWTED 0x00000020 Indicates that the process stopped after a call to the fork
subroutine, while being traced.

SEWTED 0x00000040 Indicates that the process stopped after a call to the exec
subroutine, while being traced.

SLWTED 0x00000080 Indicates that the process stopped after a call to the load
or unload subroutine, while being traced.

SFIXPRI 0x00000100 Indicates that the process has a fixed priority, ignoring
the pcpu field descriptor.

SKPROC 0x00000200 Indicates a Kernel process.

SOMASK 0x00000400 Indicates restoration of the old mask after a signal is
received.

SWAKEONSIG 0x00000800 Indicates that the signal will abort the sleep
subroutine. The contents must not be equal to those of the PCATCH flag. The
contents of both PCATCH and SWAKEONSIG must be greater than those of PMASK.

SUSER 0x00001000 Indicates that the process is in user mode.

SLKDONE 0x00002000 Indicates that the process has done locks.

STRACING 0x00004000 Indicates that the process is a debugging process.

SMPTRACE 0x00008000 Indicates multi-process debugging.

SEXIT 0x00010000 Indicates that the process is exiting.

SSEL 0x00020000 Indicates that the processor is selecting: wakeup/waiting
danger.

SORPHANPGRP 0x00040000 Indicates an orphaned process group.

SNOCNTLPROC 0x00080000 Indicates that the session leader relinquished the
controlling terminal.

SPPNOCLDSTOP 0x00100000 Indicates that the SIGHLD signal is not sent to the
parent process when a child stops.

SEXECED 0x00200000 Indicates that process has been run.

SJOBSESS 0x00400000 Indicates that job control was used in the current
session.

SJOBOFF 0x00800000 Indicates that the process is free from job control.

PSIGDELIVERY 0x01000000 Indicates that the process is used by the
program-check handler.

SRMSHM 0x02000000 Indicates that the process removed shared memory during a
call to the exit subroutine.

SSLOTFREE 0x04000000 Indicates that the process slot is free.

SNOMSG 0x08000000 Indicates that there are no more uprintf subroutine
messages.

F
(-l and l flags) Some of the more important F field flags (hexadecimal and
additive) associated with processes and threads are shown below:

F Field Table

Flags Hex Value Definition

SLOAD 0x00000001 Indicates that the process is operating in core memory.

SNOSWAP 0x00000002 Indicates that the process cannot be swapped out.

STRC 0x00000008 Indicates that the process is being traced.

SKPROC 0x00000200 Indicates a kernel process.

SEXIT 0x00010000 Indicates that the process is exiting.

SEXECED 0x00200000 Indicates that the process has been run.

SEXECING 0x01000000 Indicates that the process is execing (performing an
exec).

TKTHREAD 0x00001000 Indicates that the thread is a kernel-only thread.

Note: You can see the definitions all process and thread flags by consulting
the p_flags and t_flags fields in the /usr/include/sys/proc.h and
/usr/include/sys/thread.h files respectively.

LIM
(v flag) The soft limit on memory used, specified via a call to the setrlimit
subroutine. If no limit has been specified, then shown as xx. If the limit is
set to the system limit, (unlimited), a value of UNLIM is displayed.

NI
(-l and l flags) The nice value; used in calculating priority for the sched
other policy.

PID
(all flags) The process ID of the process.

PGIN
(v flag) The number of disk I/Os resulting from references by the process to
pages not loaded in core.

PPID
(-f, l, and -l flags) The process ID of the parent process.

PRI
(-l and l flags) The priority of the process or kernel thread ; higher numbers
mean lower priority.

RSS
(v flag) The real-memory (resident set) size of the process (in 1KB units).

S
(-l and l flags) The state of the process or kernel thread :

For processes:

O
Nonexistent

A
Active

W
Swapped

I
Idle (waiting for startup)

Z
Canceled

T
Stopped

For kernel threads:

O
Nonexistent

R
Running

S
Sleeping

W
Swapped

Z
Canceled

T
Stopped

SC
(-o THREAD flag) The suspend count of the process or kernel thread. For a
process, the suspend count is defined as the sum of the kernel threads suspend
counts.

SCH
(-o THREAD flag) The scheduling policy for a kernel thread. The policies
sched_other, sched_fifo, and sched_rr are respectively displayed using: 0, 1,
2.

SIZE
(v flag) The virtual size of the data section of the process (in 1KB units).

SSIZ
(s flag) The size of the kernel stack. This value is always 0 (zero) for a
multi-threaded process.

STAT
(s, u, and v flags) Contains the state of the process:

0
Nonexistent

A
Active

I
Intermediate

Z
Canceled

T
Stopped

K
Available kernel process

STIME
(-f and u flags) The starting time of the process. The LANG environment
variables control the appearance of this field.

SZ
(-l and l flags) The size in 1KB units of the core image of the process.

THCNT
(-o thcount flag) The number of kernel threads owned by the process.

TID
(-o THREAD flag) The thread ID of the kernel thread.

TIME
(all flags) The total execution time for the process.

TRS
(v flag) The size of resident-set (real memory) of text.

TSIZ
(v flag) The size of text (shared-program) image.

TTY
(all flags) The controlling workstation for the process:

-
The process is not associated with a workstation.

?
Unknown.

Number
The TTY number. For example, the entry 2 indicates TTY2.

UID
(-f, -l, and l flags) The user ID of the process owner. The login name is
printed under the -f flag.

USER
(u flag) The login name of the process owner.

WCHAN
(-l flag) The event for which the process or kernel thread is waiting or
sleeping. For a kernel thread, this field is blank if the kernel thread is
running. For a process, the wait channel is defined as the wait channel of the
sleeping kernel thread if only one kernel thread is sleeping; otherwise a star
is displayed.

WCHAN
(l flag) The event on which process is waiting (an address in the system). A
symbol is chosen that classifies the address, unless numerical output is
requested.

%CPU
(u and v flags) The percentage of time the process has used the CPU since the
process started. The value is computed by dividing the time the process uses
the CPU by the elapsed time of the process. In a multi-processor environment,
the value is further divided by the number of available CPUs since several
threads in the same process can run on different CPUs at the same time.
(Because the time base over which this data is computed varies, the sum of all
%CPU fields can exceed 100%.)

%MEM
(u and v flags) The percentage of real memory used by this process.
 

A full reference on flag parameters from unix man page.

Flags

The following flags are preceded by a - (minus sign):

-A Writes to standard output information about all processes.

-a Writes to standard output information about all processes, except the session
leaders and processes not associated with a terminal.

-c Clist Displays only information about processes assigned to the workload
management classes listed in the Clist variable. The Clist variable is either a
comma separated list of class names or a list of class names enclosed in double
quotation marks (" "), which is separated from one another by a comma or by one
or more spaces, or both.

-d Writes information to standard output about all processes, except the session
leaders.

-e Writes information to standard output about all processes, except kernel
processes.

-F Format Same as -o Format

-f Generates a full listing.

-G Glist Writes information to standard output only about processes that are in
the process groups listed for the Glist variable. The Glist variable is either a
comma-separated list of process group identifiers or a list of process group
identifiers enclosed in double quotation marks (" ") and separated from one
another by a comma or by one or more spaces. This flag is equivalent to the -g
Glist flag.

-g Glist This flag is equivalent to the -G Glist flag.

-k Lists kernel processes.

-l Generates a long listing. See also the l flag.

-m Lists kernel threads as well as processes. Output lines for processes are
followed by an additional output line for each kernel thread. This flag does not
display thread-specific fields ( bnd, scount, sched, thcount, and tid), unless
the appropriate -o Format flag is specified.

-N Gathers no thread statistics. With this flag ps simply reports those
statistics that can be obtained by not traversing through the threads chain for
the process.

-n NameList Specifies an alternative system name-list file in place of the
default. The operating system does not use the -n flag, since information is
supplied directly to the kernel.

-o Format Displays information in the format specified by the Format variable.
Multiple field specifiers can be specified for the Format variable. The Format
variable is either a comma-separated list of field specifiers or a list of field
specifiers enclosed within a set of " " (double-quotation marks) and separated
from one another by a comma or by one or more spaces, or both.

Each field specifier has a default header. The default header can be overridden
by appending an = (equal sign) followed by the user-defined text for the header.
The fields are written in the order specified on the command line in column
format. The field widths are specified by the system to be at least as wide as
the default or user-defined header text. If the header text is null, (such as if
-o user= is specified), the field width is at least as wide as the default
header text. If all header fields are null, no header line is written.

The following field specifiers are recognized by the system:

args
Indicates the full command name being executed. All command-line arguments are
included, though truncation may occur. The default header for this field is
COMMAND.

bnd
Indicates to which (if any) processor a process or kernel thread is bound. The
default header for this field is BND.

class
Indicates the workload management class assigned to the process. the default
header for this field is CLASS.

comm
Indicates the short name of the command being executed. Command-line arguments
are not included. The default header for this field is COMMAND.

cpu
Determines process scheduling priority. CPU utilization of process or thread,
incremented each time the system clock ticks and the process or thread is
found to be running. The value is decayed by the scheduler by dividing it by 2
once per second. For the sched_other policy, Large values indicate a CPU
intensive process and result in lower process priority whereas small values
indicate an I/O intensive process and result in a more favorable priority.

etime
Indicates the elapsed time since the process started. The elapsed time is
displayed in the following format:

[[ dd-]hh:]mm:ss

where dd specifies the number of days, hh specifies the number of hours, mm
specifies the number of minutes, and ss specifies the number of seconds. The
default header for this field is ELAPSED.

group
Indicates the effective group ID of the process. The textual group ID is
displayed. If the textual group ID cannot be obtained, a decimal
representation is used. The default header for this field is GROUP.

nice
Indicates the decimal value of the process nice value. The default header for
this field is NI.

-o Format (Continued)

pcpu
Indicates the ratio of CPU time used to CPU time available, expressed as a
percentage. The default header for this field is %CPU.

pgid
Indicates the decimal value of the process group ID. The default header for
this field is PGID.

pid
Indicates the decimal value of the process ID. The default header for this
field is PID.

ppid
Indicates the decimal value of the parent process ID. The default header for
this field is PPID.

rgroup
Indicates the real group ID of the process. The textual group ID is displayed.
If the textual group ID cannot be obtained, a decimal representation is used.
The default header for this field is RGROUP.

ruser
Indicates the real user ID of the process. The textual user ID is displayed.
If the textual user ID cannot be obtained, a decimal representation is used.
The default header for this field is RUSER.

scount
Indicates the suspend count for a kernel thread. The default header for this
field is SC.

sched
Indicates the scheduling policy for a kernel thread. The default header for
this field is SCH.

tag
Indicates the Workload Manager application tag. The default header for this
field is TAG. The tag is a character string up to 30 characters long and may
be truncated when displayed by ps. For processes which do not set their tag,
this field displays as a hyphen (-).

thcount
Indicates the number of kernel threads owned by the process. The default
header for this field is THCNT.

-o Format (Continued)

THREAD
Indicates the following fields:
o User name (the uname field)
o Process and parent process IDs for processes (the pid and ppid fields)
o Kernel thread ID for threads (the tid field)
o The state of the process or kernel thread (the S field)
o The CPU utilization of the process or kernel thread (the C field)
o The priority of the process or kernel thread (the PRI field)
o The suspend count of the process or kernel thread (the scount field)
o The wait channel of the process or kernel thread (the WCHAN field)
o The flags of the process or kernel thread (the F field)
o The controlling terminal of the process (the tty field)
o The CPU to which the process or kernel thread is bound (the bnd field)
o The command being executed by the process (the comm field).

Threads are not actually displayed with the -o THREAD flag, unless the -m flag
is also specified.

tid
Indicates the thread ID of a kernel thread. The default header for this field
is TID.

time
Indicates the cumulative CPU time since the process started. The time is
displayed in the following format:

[ dd-]hh:mm:ss

where dd specifies the number of days, hh specifies the number of hours, mm
specifies the number of minutes, and ss specifies the number of seconds. The
default header for this field is TIME.

tty
Indicates the controlling terminal name of the process. The default header for
this field is TT.

user
Indicates the effective user ID of the process. The textual user ID is
displayed. If the textual user ID cannot be obtained, a decimal representation
is used. The default header for this field is USER.

vsz
Indicates, as a decimal integer, the size in kilobytes of the process in
virtual memory. The default header for this field is VSZ.

-o Format (Continued)

Otherwise, multiple fields in a specified format can be displayed by the Format
variable, including field descriptors. If field descriptors are used in the
Format variable, it must be enclosed in double quotation marks (" "). The
following table shows how field descriptors correspond to field specifiers:

Field Field Default

Descriptors Specifiers Headers

%a args COMMAND

%c comm COMMAND

%t etime ELAPSED

%G group GROUP

%n nice NI

%C pcpu %CPU

%r pgid PGID

%p pid PID

%P ppid PPID

%g rgroup RGROUP

%u ruser RUSER

%x time TIME

%y tty TTY

%U user USER

%z vsz VSZ

-p Plist Displays only information about processes with the process numbers
specified for the Plist variable. The Plist variable is either a comma separated
list of process ID numbers or a list of process ID numbers enclosed in double
quotation marks (" ") and separated from one another by a comma or by one or
more spaces, or both.

-t Tlist Displays only information about processes associated with the
workstations listed in the Tlist variable. The Tlist variable is either a comma
separated list of workstation identifiers or a list of workstation identifiers
enclosed in double quotation marks (" ") and separated from one another by a
comma or by one or more spaces, or both.

-U Ulist Displays only information about processes with the user ID numbers or
login names specified for the Ulist variable. The Ulist variable is either a
comma-separated list of user IDs or a list of user IDs enclosed in double
quotation marks (" ") and separated from one another by a comma and one or more
spaces. In the listing, the ps command displays the numerical user ID unless the
-f flag is used; then the command displays the login name. This flag is
equivalent to the -u Ulist flag. See also the u flag.

-u Ulist This flag is equivalent to the -U Ulist flag.

Options

The following options are not preceded by a - (minus sign):

a Displays information about all processes with terminals (ordinarily only the
user's own processes are displayed).

c Displays the command name, as stored internally in the system for purposes of
accounting, rather than the command parameters, which are kept in the process
address space.

e Displays the environment as well as the parameters to the command, up to a
limit of 80 characters.

ew Wraps display from the e flag one extra line.

eww Wraps display from the e flag as many times as necessary.

g Displays all processes.

l Displays a long listing having the F, S, UID, PID, PPID, C, PRI, NI, ADDR, SZ,
PSS, WCHAN, TTY, TIME, and CMD fields.

n Displays numerical output. In a long listing, the WCHAN field is printed
numerically rather than symbolically. In a user listing, the USER field is
replaced by a UID field.

s Displays the size (SSIZ) of the kernel stack of each process (for use by
system maintainers) in the basic output format. This value is always 0 (zero)
for a multi-threaded process.

t Tty Displays processes whose controlling tty is the value of the Tty variable,
which should be specified as printed by the ps command; that is, 0 for terminal
/dev/tty/0, lft0 for /dev/lft0 , and pts/2 for /dev/pts/2.

u Displays user-oriented output. This includes the USER, PID, %CPU, %MEM, SZ,
RSS, TTY, STAT, STIME, TIME, and COMMAND fields.

v Displays the PGIN, SIZE, RSS, LIM, TSIZ, TRS, %CPU, %MEM fields.

w Specifies a wide-column format for output (132 columns rather than 80). If
repeated, (for example, ww), uses arbitrarily wide output. This information is
used to decide how much of long commands to print.

x Displays processes with no terminal.
 

Some examples from unix man page.

Examples

1. To display all processes, enter:

ps -e -f

2. To list processes owned by specific users, enter:

ps -f -l -ujim,jane,su

3. To list processes that are associated with the /dev/console and /dev/tty1
ttys, enter:

ps -t console,tty/1

4. To list processes not associated with a terminal, enter:

ps -t -

5. To display a specified format with field specifiers, enter:

ps -o ruser,pid,ppid=parent,args

The output is:
RUSER PID parent COMMAND

helene 34 12 ps -o ruser,pid,ppid=parent,args

6. To display a specified format with field descriptors, enter:

ps -o "< %u > %p %y : %a"

The output is:
< RUSER > PID TT : COMMAND

< helene > 34 pts/3 : ps -o < %u > %p %y : %a

7. To display information about processes and kernel threads controlled by the
current terminal , enter:

ps -lm

The output is similar to:
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD

240003 A 26 8984 7190 1 60 20 2974 312 pts/1 0:00 -ksh

400 S - - - 1 60 - - - - - -

200005 A 26 9256 8984 15 67 20 18ed 164 pts/1 0:00 ps

0 R - - - 15 67 - - - - - -

8. To display information about all processes and kernel threads, enter:

ps -emo THREAD

The output is similar to:
USER PID PPID TID S C PRI SC WCHAN FLAG TTY BND CMD

jane 1716 19292 - A 10 60 1 * 260801 pts/7 - biod

- - - 4863 S 0 60 0 599e9d8 8400 - - -

- - - 5537 R 10 60 1 5999e18 2420 - 3 -

luke 19292 18524 - A 0 60 0 586ad84 200001 pts/7 - -ksh

- - - 7617 S 0 60 0 586ad84 400 - - -

luke 25864 31168 - A 11 65 0 - 200001 pts/7 - -

- - - 8993 R 11 65 0 - 0 - - -
 

 

Automic login with sftp

It's impossible to automic log into server using sftp in unix shell script with password authorization...

It's impossible to automic log into server using sftp in unix shell script with password authorization like what we can do with ftp below.

ftp -nv <<EOF
open ${FTP_HOST}
user ${FTP_USER}
${FTP_PASSWD}
binary
cd ${FTP_DIR}
put ${FTP_FILE_NAME}
dir
${FTP_FILE_NAME}
quit
EOF          

But we have another solution for this, once it setup, it both conveneint and sercure. see following steps. tested on AIX.

On the client machine, type:

ssh-keygen -t rsa (or dsa, depending on the desired mode)
respond to the questions with CR

Make sure that the ssh daemon is running on the server.

On the client machine, CD to the .ssh directory in your home directory
and type:

scp id_rsa.pub <serverloginid>@<serverhostname>:id_rsa.pub
you will have to enter the password this time

Log onto the server and CD to your home directory. (The "id_rsa.pub"
file should be visible). Check to see if a .ssh directory exists; if
not, create one and type:

cat id_rsa.pub >> .ssh/authorized_keys

You can delete the id_rsa.pub file from the server (or move it into the
.ssh folder).

That should set up the automatic login authentication.

Reference

2006-6-14 Update

If access to the remote system is still denied you should check the permissions of the following files on it:
  • the home directory itself
  • the ~/.ssh directory
  • the ~/.ssh/authorized_keys file

The permissions should allow writing only by you (the owner). This example shows the most relaxed permissions you could use.

  hrothgar% cd
hrothgar% ls -ld . .ssh .ssh/authorized_keys
drwxr-xr-x 36 kim kim 4096 Jul 25 02:24 .
drwxr-xr-x 2 kim kim 512 Apr 10 02:30 .ssh
-rw-r--r-- 1 kim kim 1674 Apr 10 02:29 .ssh/authorized_keys

Mount Linux EXT3 Partition from USB hdd on Windows XP

I found this helpful link. Mount your EXT2 Partition On Windows NT/2K/XP (EXT3 too) driver...

I found this helpful link.

It introduces 3 tools:

  1. EXT2IFS
  2. Ext2Fsd
  3. Ext2 Installable File System For Windows

EXT2IFS

I try EXT2IFS first.

  1. run the service.exe of ext2ifs.
  2. Install Driver at step 1 (manually startup).
  3. Plugin my USB hdd which contains EXT3 partition.
  4. I can not find the EXT volumes at step 2a. but found them at step 2b, then assigned driver letter for each them.
  5. reboot.
  6. After reboot,run the service.exe.
  7. go to step 3, click Start Driver because I choose manually Startup at above.
  8. then all the driver letter I assigned above are available now. Bingo!
  9. I copy files from the EXT3 partition successfully, but this driver does not support Write feature. this EXT3 partition is read-only for Windows XP.

NOTE: Explorer gets random crash when using this driver.

running Linux on my thinkpad

I don't find following drivers for Linux version.Wireless LAN Adapter SoftwareFingerprint softwareClient Security SoftwareBluetooth deviceActive Protection...

I don't find following drivers for Linux version.

  • Wireless LAN Adapter Software
  • Fingerprint software
  • Client Security Software
  • Bluetooth device
  • Active Protection System software

There're also some important IBM applications I can't found a linux version.

  • Access Connection
  • Software Installer
  • Power Manager
Refference

install linux on 2nd hdd in my thinkpad

Install Red Hat Enterprise Linux 3 on 2nd hdd in my thinkpad with usb dvd-rom.Choose Grub...

Install Red Hat Enterprise Linux 3 on 2nd hdd in my thinkpad with usb dvd-rom.

Choose Grub as boot selector and install grub on the first sector of 2nd hdd without lba support. Reboot, hit F12, choose 2nd hdd to boot up, during booting, screen showed GRUB 4 characters, then stop there. Grub can't continue to load boot menu.

Boot using linux cd in rescue mode, reinstall grub with on the first sector of 2nd hdd:

$ grub-install /dev/hdc

Reboot, hit F12, choose 2nd hdd, during boot, can't see the boot menu, but grub continues to load and get following error message:

  • Cannot mount selected partition
  • This error is returned if the partition requested exists, but the filesystem type cannot be recognized by GRUB.
See current setting files.
$ cat /boot/grub/device.map
fd0  /dev/fda
hd0  /dev/hda
hd1  /dev/hdc
$ cat /boot/grub/grub.conf 
title Linux
root (hd1,0)
kernel /vmlinuz-2.4.21-4.EL ro root=LABEL=/
initrd /initrd-2.4.21-4.EL.img

title Windows
root (hd0,0)
chainload (+1)

Finally, I caught the point. When choosing 2nd hdd as first boot device by F12 during booting, BIOS will see it as hda, and the ist native hdd will change from hda to hdc.

During the grub installing, grub will guess the boot devices list, and generate a device.map file and grub.conf with the detected settings. that time, grub is right, but when booting from 2nd hdd, the thing changes.

I had it working with following settings.

$ cat /boot/grub/device.map
fd0  /dev/fda
hd0  /dev/hda
hd1  /dev/hdc
$ cat /boot/grub/grub.conf 
title Linux
root (hd0,0)
kernel /vmlinuz-2.4.21-4.EL ro root=LABEL=/
initrd /initrd-2.4.21-4.EL.img

title Windows
root (hd1,0)
chainload (+1)

But i am still wondering why linux could keep recognize /dev/hdc but grub not? needs answer.

refer to:

服务器环境改造

原来的网络结构 在rh linux 9 上通过adsl modem(无路由)拨号上网,linux 服务器安装两块网卡,eth0 连接adsl modem,eth1 连接10M hub,并设置nat 映射,其它电脑连入hub,设定内网IP,网关设定为linux 服务器eth1 的IP 地址,即可实现共享上网。 linux...

原来的网络结构

在rh linux 9 上通过adsl modem(无路由)拨号上网,linux 服务器安装两块网卡,eth0 连接adsl modem,eth1 连接10M hub,并设置nat 映射,其它电脑连入hub,设定内网IP,网关设定为linux 服务器eth1 的IP 地址,即可实现共享上网。

linux 开放apache 与ssh 服务,用于网站服务和远程维护。adsl 使用网通服务,120元/月,不限流量,IP 是自动获取,由服务器动态分配,每48小时服务器reset 一次connection,不过IP 地址不变(只要adsl 连接没有断开)。每次重启服务器,需要重新设置网站域名IP 地址的解析,为此,在linux 服务器上写了脚本,每次重启后,当ppp0(adsl)连接后,取得IP,并通过本机sendmail 服务发送到笔者的邮箱。

此结构有个很明显的缺点,就是服务器不能随便重启,否则影响网站的稳定访问,而维护性的重启是不可避免的。

调整后的结构

仍然使用adsl 连接internet 。

 

购买一个无线路由器,具有ppoe 客户端功能,路由器wan 端口(RJ45)连接adsl modem,通过adsl modem拨号上网,此路由器获得公网IP。

linux 服务器原eth0 网卡停掉,eth1 连接到无线路由器的交换端口中的一个,设定自动获取IP 或者指定一个与路由器同网段(192.168.1.xxx)的IP ,即可上网,考虑到可能需要在路由器中为linux server 配置策略,采用了手动指定IP。

路由器中设定port forward,将80 (web)与22 (ssh)端口的数据转发到linux server eth1 所在的IP ,这样在外部通过浏览器访问路由器所在的IP 时,就像在访问linux server 的web 服务一样,ssh 同理。

笔记本电脑安装了一个无线网卡,通过无线路由器连入internet。使用自动获取IP。

路由器中为emule 客户端设置port forward,将4662-4672端口的数据转发到具有内部地址的其它上网电脑(除linux server),这样,这些电脑使用emule 下载时可以获取到HighID。

调整后的优点

将原来linux server 网关的功能转移到了无线路由器,路由器比linux server 更稳定,只要保持adsl modem 和路由器的电源,即可保持网络不断,IP 不会发生改变。

linux server 此时变成了拥有内部IP 的内部主机,可以随意重启维护(只会造成短暂的网站服务终止),并且具有了一层天然的防火墙。

其它

打算购置一块pci 接口的无线网卡,用于linux server,通过无线路由器接入网络,这样主机可以更加灵活的放置和移动。不过目前市场上还没找到支持linux 的pci 接口无线网卡,据说netgear 或是d-link 有一款支持linux,其它均不支持。

准备购置一台ups,300W(500VA)左右,用于adsl modem 与wireless router 的供电,可保持停电工作1小时左右。

前些日子linux server随机性的死机,频率约为1-2小时/次,当server 负载增大时,比如mt 整体rebuild,会更容易诱发死机。之前在升级gcc 到最新版本,make bootstrap 执行到同一个位置总是会死机,无法完成升级。cpu 风扇有些老化有响声,不过死机时cpu 并不过热,几乎査遍了所有能想到的问题,替换了手头有的零件,问题依然存在,最后更换了cpu 风扇,问题完美解决。风扇选择了滚珠轴承的强力风扇,噪音比普通的大一些。

购置设备情况

wireless router: linksys 11M 全向wireless router ,附送一块linksys 11M 笔记本无线网卡,330元。

linux 网关配置nat,使emule 工作在HighID 方式

如果通过linux 网关上网,emule 会工作在LowID 方式,可以通过在linux 上设置nat 映射来转换到HighID 方式。 # /sbin/iptables -t nat -A PREROUTING -i ppp0 -p...

如果通过linux 网关上网,emule 会工作在LowID 方式,可以通过在linux 上设置nat 映射来转换到HighID 方式

# /sbin/iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 4662 -j DNAT -d 192.168.18.198:466 
# /sbin/iptables -t nat -A PREROUTING -i ppp0 -p udp --dport 4672 -j DNAT -d 192.168.18.198:4672
# /etc/rc.d/init.d/iptables save

配置完之后,在emule 中重新登录服务器,在“我的信息”中查看,已经变为HighID。

linux 下apache 配置虚拟主机

什么是虚拟主机虚拟主机用于在物理的一台主机上运行多个站点,譬如:www.example1.com、www.example2.com,也可以是这样的:www.example.com、blog.example.com。虚拟主机有两种类型:IP-based 和name-based,前者用于同一台主机上的多个站点具有不同的IP 地址,后者用于同一台主机上的多个站点使用同一个IP 地址,仅依靠名字来区分不同的站点。apache 1.1 版本之后开始支持这两种虚拟主机类型,平常我们一般谈到和用到的虚拟主机都是第二种类型:name-based 。name-based 的限制一些比较古老的浏览器无法正确访问虚拟主机的站点,这是因为部分基于http 1.0 的浏览器不发送http 主机头信息(host header)。所有基于http 1.1 的浏览器和部分比较流行的http 1.0 浏览器则不存在此问题。使用安全套接层协议(SSL)的服务器不能使用虚拟主机,这是由于SSL...

什么是虚拟主机

虚拟主机用于在物理的一台主机上运行多个站点,譬如:www.example1.com、www.example2.com,也可以是这样的:www.example.com、blog.example.com。

虚拟主机有两种类型:IP-basedname-based,前者用于同一台主机上的多个站点具有不同的IP 地址,后者用于同一台主机上的多个站点使用同一个IP 地址,仅依靠名字来区分不同的站点。

apache 1.1 版本之后开始支持这两种虚拟主机类型,平常我们一般谈到和用到的虚拟主机都是第二种类型:name-based 。

name-based 的限制

一些比较古老的浏览器无法正确访问虚拟主机的站点,这是因为部分基于http 1.0 的浏览器不发送http 主机头信息(host header)。所有基于http 1.1 的浏览器和部分比较流行的http 1.0 浏览器则不存在此问题。

使用安全套接层协议(SSL)的服务器不能使用虚拟主机,这是由于SSL 协议本身的特性决定的。

一些由操作系统或者网络设备实现的带宽管理技术会遇到问题,因为它们可能无法通过IP 区分不同的站点。

设置一个name-based 虚拟主机

以linux 环境采用apache 服务器为例,设置虚拟主机,需要有至少一个独立外网IP ,至少一个域名,并且可以修改二级域名,并不要求具有自己的DNS 服务器。

设置虚拟主机,只需要添加以下行到httpd.conf 文件,这个文件一般在/etc/httpd/conf/httpd.conf 可以找到。

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/html/blog
</VirtualHost>

剩下的工作就是去你的域名服务商处,设置DNS 解析,建立两个主机名,分别为www 与blog,指向的IP 相同,均为这台虚拟主机的IP 地址。这样就可以通过www.example.com 与blog.example.com 访问到同一台主机上的不同站点。

题外话:实现形入example.com 的解析,设置主机名为@ ,@ 代表域名自身。实现形入*.example.com 的解析,设置主机名为* 即可。

参考资源

samba 服务器设置备忘

samba 服务器的安装配置,这里已经有了很全面的文章介绍,你无需继续阅读下面的内容,权作为自己备忘。安装RH Linux 时,已经选择了samba 服务包,使用如下命令启动或停止samba 服务:$ service smb start$ service smb stop配置文件在/etc/samba/smb.conf ,打开进行编辑。设定samba 共享所在的工作组,可以设为与你的Windows 主机相同的工作组(如果采取了工作组方式):workgroup =...

samba 服务器的安装配置,这里已经有了很全面的文章介绍,你无需继续阅读下面的内容,权作为自己备忘。

安装RH Linux 时,已经选择了samba 服务包,使用如下命令启动或停止samba 服务:

$ service smb start
$ service smb stop

配置文件在/etc/samba/smb.conf ,打开进行编辑。

设定samba 共享所在的工作组,可以设为与你的Windows 主机相同的工作组(如果采取了工作组方式):

workgroup = WORKGROUP

设定哪些主机有权访问samba,可以指定为单个IP,也可以指定一个网段。下面的配置严格限定只有局域网和本机上可以使用samba 服务(如果你的samba 主机位于Internet )。

hosts allow = 192.168.1.100 192.168.2 127.

设定认证方式,share 方式不进行密码验证:

security = share

设定samba 共享目录的路径以及权限,这里是/mnt/win ,并允许guest 用户访问:

[win]
comment = Old data on Windows
path = /mnt/win
public = yes
guest ok = yes

保存退出。

还需要为samba 建立guest 用户:

$ useradd pcguest

重启动samba 服务,使新设置生效:

$ sercice samba restart

设置完毕。

RH linux 9 中samba 中文文件名乱码问题

问题最近配置一台RH linux 9samba 共享,在支持中文的windows xp 系统上访问,samba 共享的中文目录和文件名乱码,显示为问号,但打开文件,里面的中文显示正常。查看语言环境如下:# cat /etc/sysconfig/i18nLANG="en_US.UTF-8"SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"查看分区环境如下:$ mount.../dev/hdc5 on /mnt/win type vfat (rw)...解决对于类似问题,Linux下的中文显示和支持常见问题解答中有比较详细的解决方法。首先,使用正确的代码页和字符集mount 带有中文的分区,编辑文件/etc/fstab...

问题

最近配置一台RH linux 9samba 共享,在支持中文的windows xp 系统上访问,samba 共享的中文目录和文件名乱码,显示为问号,但打开文件,里面的中文显示正常。

查看语言环境如下:

# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"

查看分区环境如下:

$ mount
...
/dev/hdc5 on /mnt/win type vfat (rw)
...

解决

对于类似问题,Linux下的中文显示和支持常见问题解答中有比较详细的解决方法。

首先,使用正确的代码页和字符集mount 带有中文的分区,编辑文件/etc/fstab ,修改为:

/dev/hdc5 /mnt/data1 vfat defaults,codepage=936,iocharset=cp936 0 0

这个修改在下次启动系统时生效,修改当前的mount 配置:

$ umount /dev/hdc5
$ mount -t vfat -o codepage=936,iocharset=cp936 /dev/hdc5 /mnt/win
$ mount
...
/dev/hdc5 on /mnt/data1 type vfat (rw,codepage=936,iocharset=cp936)
...

接下来,编辑samba 配置文件/etc/samba/smb.conf ,在[global] 中加入如下2 行(注意顺序):

client code page = 936
character set = 936

如果是繁体中文系统,使用950 替换936。修改完smb.conf 可使用如下命令check 配置文件是否包含语法错误:

$ testparm
unrecognized character set 936

这个错误信息会出现,但这句的确有用。重启动samba 服务使修改的配置文件生效:

$ service smb restart

通过Windows 再访问samba 共享,中文目录和文件名已经可以正常显示。

另外,有很多资料介绍在smb.conf 中进行如下配置来解决此问题(比如:http://www.blog.edu.cn/user1/2065/archives/2005/212233.shtml):

 

display charset = cp936
unix charset = cp936
dos charset = cp936

上面的参数只有在较新的samba 版本中才支持,随RHL 9 提供的版本2.2.7a不支持以上参数:

$ smbd -V
Version 2.2.7a
$ man smb.conf

修改smb.conf 后使用testparm 检查一遍是个不错的主意。

参考资源

你还在使用telnet 与ftp 吗?

传统的telnet 与ftp 服务都使用明文传送用户名和密码,如果在运行服务器或者客户端的网络中装有嗅探器(有很多现成的工具可利用),那么服务器的安全将是非常脆弱的。幸好,我们可以使用连接加密的SSH 协议,由OpenBSD group 开发的OpenSSH 是遵循SSH 协议的一套免费开源工具包,目前已经被集成在大多数的类unix 平台和他们的发布版本中,这也包括商业的操作系统,因为OpenSSH 基于BSD 协议,BSD 协议相对比较宽松。这里是一个运行它的系统列表,当然也包含RedHat Linux 发布。OpenSSH 提供的sshd 服务可用于替代传统telnet...

传统的telnet 与ftp 服务都使用明文传送用户名和密码,如果在运行服务器或者客户端的网络中装有嗅探器(有很多现成的工具可利用),那么服务器的安全将是非常脆弱的。

幸好,我们可以使用连接加密的SSH 协议,由OpenBSD group 开发的OpenSSH 是遵循SSH 协议的一套免费开源工具包,目前已经被集成在大多数的类unix 平台和他们的发布版本中,这也包括商业的操作系统,因为OpenSSH 基于BSD 协议,BSD 协议相对比较宽松。这里是一个运行它的系统列表,当然也包含RedHat Linux 发布。

OpenSSH 提供的sshd 服务可用于替代传统telnet 服务器端程序,sftp-server 子系统(实际由sshd 进行调用)可用于替代传统ftp 服务器端程序,ssh(secure shell) 与sftp(secure ftp)分别用于替代传统的telnet 与ftp 客户端工具。

在RH Linux 下,可以直接使用OpenSSH 软件包,有了OpenSSH,不建议再安装telnet 组件。

$ ssh www.domain.com
$ sftp www.domain.com

在Windows 下,同样有一套出色的支持SSH 协议的免费开源软件包,那就是putty 。最喜欢使用的就是软件包中的putty.exe,它相当于OpenSSH 中的ssh ,putty 功能很多,支持logging、proxy、与本地系统之间的copy、paste等,还兼容telnet 和rlogin 。

putty 提供的psftp.exe 基于命令行,对于大量文件的频繁传输,还是GUI 更方便些,WinSCP2sshwinclient 就是两个不错的工具,都使用SSH 协议,操作风格类似于传统的ftp 图形客户端。前者是绿色软件,小巧实用,后者需要安装,功能更强一些。

 

 

want to know more about sftp tools?here

你还在使用telnet 与ftp 吗?或许是时候关闭它们了,只开放sshd(22端口)服务,使用加密认证的远程命令执行与文件传输吧。

vi 命令傻瓜讲解

正文下面介绍vi 的一般用法,本文适合初学者入门,但不适合作为手册进行查询,如果需要以命令导向的手册,请使用$ man vi|more ,或看这里的:vi 命令一览表。打开文件进入编辑编辑一个文件:$ vi example.txt同时编辑多个文件:$ vi file1 file2 ... fileN如果使用vi 编辑的某个文件没有正常保存退出,会遗留一个隐含的文件:.filename.swp ,使用如下命令恢复从最后一次保存到非正常退出前所做的编辑:$ vi...

正文

下面介绍vi 的一般用法,本文适合初学者入门,但不适合作为手册进行查询,如果需要以命令导向的手册,请使用$ man vi|more ,或看这里的:vi 命令一览表

打开文件进入编辑

编辑一个文件:

$ vi example.txt

同时编辑多个文件:

$ vi file1 file2 ... fileN

如果使用vi 编辑的某个文件没有正常保存退出,会遗留一个隐含的文件:.filename.swp ,使用如下命令恢复从最后一次保存到非正常退出前所做的编辑:

$ vi -r filename

注意当前模式

进入文件编辑后,vi有四种模式,一种是插入模式(按键盘i 进入),这个模式下键盘输入会作为字符增加到文件中。

另一种是编辑模式,这个状态下可以直接输入命令来移动光标,删除字符等操作,不需要回车确认,每一个命令按键都会直接发生作用。在插入模式下按ESC 键会回到编辑模式。

第三种是命令模式,在编辑模式下按冒号":" 即进入命令模式,这时键盘输入的字符会出现在屏幕下方,回车后,命令执行。这个模式下可以输入保存、字符串搜索、退出编辑等命令。命令模式下,按回车或者ESC 键,回到编辑模式。

第四种是搜索模式,在编辑模式下输入斜杠"/" 或者问号"?" 即进入搜索模式。

上面的四种模式是我为了描述方便所起的名字,下面将引用到。

光标移动

光标的上、下、左、右移动,分别对应按键:k、j、h、l (编辑模式)。

定位到最后一行,输入大写G(编辑模式)。

回到第一行,输入小写g(编辑模式)。

跳到第n 行,在命令模式下输入数字n ,回车。

显示当前所在行数和列数,编辑模式下输入ctrl+g 。

插入内容

在当前字符前面插入内容,编辑模式下输入i ,进入了插入模式,然后输入内容,输入完成之后,按ESC 回到编辑模式。

在当前字符后面插入内容,编辑模式下输入a ,其它操作与上面相同。

在本行首插入内容,编辑模式下输入大写I 。其它操作与上面相同。

在本行尾追加内容,编辑模式下输入大写A 。其它操作与上面相同。

删除

删除当前光标的字符,编辑模式下输入x ,如果希望删除当前光标前面的字符,输入大写X 。

删除一行,编辑模式下连续两次输入d 。删除一个单词,编辑模式下依次输入dw 。

从当前光标删除至行尾,编辑模式下依次输入d$ 。

撤销操作

撤销刚才的一次修改,编辑模式下输入u ,撤销对这一整行的修改,输入大写U 。

如果希望撤销对文件的所有修改,命令模式下依次输入e! ,回车(输入冒号":" 进入命令模式,:e!)。

拷贝粘贴

拷贝一行内容,编辑模式下连续输入两次y 。

将剪贴板中的一行粘贴到当前行的后面,编辑模式下输入p 。

拷贝n 行内容,编辑模式下输入数字n(n是要拷贝的行数,从当前行算起),然后输入y ,拷贝完成,输入p 粘贴多行。

保存/退出

如果保存并关闭文件,命令模式下输入x ,回车即可。

如果保存,同时继续文件编辑,命令模式下输入w ,回车。

如果放弃所有更改,直接退出,命令模式下输入q! ,回车。

命令模式下输入wq 与x 等价。

在两个文件中复制粘贴

需要将file2 的某行粘贴到file1 中。

同时打开两个文件,中间用空格分隔:

$ vi file1.txt file2.txt

打开后当前编辑的为file1 ,在命令模式下输入n ,切换到file2。

找到相关行,编辑模式下输入yy ,再进入命令模式,输入大写N ,切换回上一个文件(以打开顺序为准),找到相关位置,编辑模式下输入p ,粘贴完毕。

 

搜索字符串

要搜索字符串abc ,在搜索模式下(编辑模式下输入斜杠"/" 或者问号"?" 即进入搜索模式),输入abc ,回车。

如果找到,光标会定位到从当前位置到第一个出现字符串abc 的位置,输入n 会跳到下一个abc 出现的位置,输入大写N ,跳到上一个abc 出现的位置。

斜杠"/" 与问号"?" 的区别,前者向后正向搜索,后者向前反向搜索。

替换字符串

要将当前行中的所有字符串abc 替换成efg ,命令模式下输入s/abc/efg/g ,回车。

上面命令只会替换abc 而不会替换ABC 或者aBc 。如果希望忽略大小写,加上参数i ,s/abc/efg/gi ,回车。

如果希望进行全文件范围替换,命令模式下输入%s/abc/efg/g ,回车。

如果替换的字符串中包含了例如斜杠"/" 这样的特殊字符,使用反斜杠"\" 转义。

命令模式下,输入%s/\/image/\/img/gi ,回车

以上命令会将文件中所有的字符串/image 替换成 /img ,并且不区分image 的大小写。

Linux 系统管理学习笔记(四)

rpm 下面列出rpm的一般用法,这里也有一篇非常全面的介绍:rpm 详解。 安装一个软件包: $ rpm -ivh example.rpm 在已安装基础上升级软件包: $ rpm -Uvh upgrade.rpm 删除软件包: $ rpm...

rpm

下面列出rpm的一般用法,这里也有一篇非常全面的介绍:rpm 详解

安装一个软件包:

$ rpm -ivh example.rpm

在已安装基础上升级软件包:

$ rpm -Uvh upgrade.rpm

删除软件包:

$ rpm -e nouse.rpm

查询一个软件包是否已经安装(忽略大小写):

$ rpm -qa |grep -i example

如果要安装的软件包依赖于其它尚未安装的软件包,要忽略依赖关系,强制安装:

$ rpm -ivh --nodeps example.rpm

查看一个软件包中包含哪些文件:

$ rpm -qlp example.rpm

eject

弹出光驱:

$ eject

关闭光驱(直接使用mount 命令,光驱也会自动关闭):

$ eject -t

有关eject 命令这里还有更有趣的讨论

locale

列出当前系统安装的所有locales:

$ locale -a

find

对查找到的文件集合进行命令操作,{}代表文件集合,反斜杠以及前面的空格与后面的分号都不能少。

find . -name "*.dat" -exec cp {} /tmp \;

google code search

 

Google 有一个未公开的code search引擎 http://www.google.com/codesearch。专门搜索源代码时非常有用。比如搜索以下字符串:

lang:shell find {} exec cp

注意,不能输入 -exec,虽然你的目的是搜索字符串"-exec",  但搜索引擎认为你不想在结果中包括 "exec"。

(未完)

Linux 系统管理学习笔记(三)

iptables 有关iptables,这里有一篇非常全面的介绍。 Linux iptables信息包过滤过程图 http://www-128.ibm.com/developerworks/cn/linux/network/s-netip/diagram1.jpg 查看已有的包过滤规则# iptables -L 这将显示默认的表filters中的规则,如果想查看nat表或者mangle表,需要使用# iptables -t nat -L# iptables -t mangle...

iptables

有关iptables,这里有一篇非常全面的介绍

Linux iptables信息包过滤过程图

http://www-128.ibm.com/developerworks/cn/linux/network/s-netip/diagram1.jpg

查看已有的包过滤规则

# iptables -L

这将显示默认的表filters中的规则,如果想查看nat表或者mangle表,需要使用

# iptables -t nat -L
# iptables -t mangle -L

需要注意的是,rh linux 中有两个iptables 命令,一个是/sbin/iptables ,也是我们设置规则所使用的命令。另一个是/etc/rc.d/init.d/iptables ,用于保存设置的iptables 规则,或者重启动iptables 服务等等:

# /etc/rc.d/init.d/iptables save

 

iptables 命令所编辑的规则被保存到以下文件:

/etc/sysconfig/iptables

 

GnuPG(gpg)

验证一个使用GnuPG 签名(Signed)的文件,首先需要获得对此文件进行签名者的公钥(Pub Key),公钥一般可通过签名者的网站获得,是一个扩展名为 .asc 的文本文件。下载回来之后,先导入此公钥,并查看本地已经保存的公钥:

$ gpg --import filename.asc
$ gpg --list-key

验证文件 filename.tar.gz 的签名,filename.tar.gz.sig 是随着filename.tar.gz 一同发布的签名文件。

$ gpg --veriry filename.tar.gz.sig filename.tar.gz
gpg: Signature made Fri 15 Jul 2005 04:13:35 AM CST using DSA key ID 89E917F3
gpg: Good signature from "tcpdump.org (SIGNING KEY) <tcpdump-workers@tcpdump.org>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 0227 54EB 4C30 9185 FD31  33A3 464D 3CEB 89E9 17F3

使用GnuPG 为自己建立用于签名的公钥与私钥

$ gpg --gen-key

然后按提示操作,将为你生成一对公钥与私钥,将公钥发布出去,私钥自己妥善保存。

使用私钥加密一个文件:

$ gpg --sign filename.txt

解密文件:

$ gpg filename.txt

参考 man gpg

curl

命令行下的Web 客户端 curl,读取一个链接,并把内容输出到标准输出,如果想查看 www.aiview.com 的首页,如下操作:

$ curl www.aiview.com |more

用于集线器(Hub) 环境的sniffer 工具 tcpdump,下载地址:www.tcpdump.org

top

top 命令不仅可以用于查询系统资源使用情况,还可以显示系统当前总计运行时间:

$ top
 19:46:28  up 5 days,  6:48,  2 users,  load average: 0.05, 0.04, 0.01
60 processes: 58 sleeping, 2 running, 0 zombie, 0 stopped
CPU states:   0.3% user   0.0% system   0.0% nice   0.0% iowait  99.6% idle
Mem:   255268k av,  238332k used,   16936k free,       0k shrd,   85536k buff
                    155172k actv,       0k in_d,    4148k in_c
Swap:  265000k av,       0k used,  265000k free                  126372k cached

free

free 命令相对于top 提供了更简洁的查看系统内存使用情况:

$ free
             total       used       free     shared    buffers     cached
Mem:        255268     238332      16936          0      85540     126384
-/+ buffers/cache:      26408     228860
Swap:       265000          0     265000
  • Mem:表示物理内存统计
  • -/+ buffers/cached:表示物理内存的缓存统计
  • Swap:表示硬盘上交换分区的使用情况,这里我们不去关心。

系统的总物理内存:255268Kb(256M),但系统当前真正可用的内存b并不是第一行free 标记的 16936Kb,它仅代表未被分配的内存。

我们使用total1、used1、free1、used2、free2 等名称来代表上面统计数据的各值,1、2 分别代表第一行和第二行的数据。

  • total1:表示物理内存总量。
  • used1:表示总计分配给缓存(包含buffers 与cache )使用的数量,但其中可能部分缓存并未实际使用。
  • free1:未被分配的内存。
  • shared1:共享内存,一般系统不会用到,这里也不讨论。
  • buffers1:系统分配但未被使用的buffers 数量。
  • cached1:系统分配但未被使用的cache 数量。buffer 与cache 的区别见后面。
  • used2:实际使用的buffers 与cache 总量,也是实际使用的内存总量。
  • free2:未被使用的buffers 与cache 和未被分配的内存之和,这就是系统当前实际可用内存。

可以整理出如下等式:

total1 = used1 + free1
total1 = used2 + free2
used1 = buffers1 + cached1 + used2
free2 = buffers1 + cached1 + free1
buffer 与cache 的区别

A buffer is something that has yet to be "written" to disk. A cache is something that has been "read" from the disk and stored for later use.

更详细的解释参考:Difference Between Buffer and Cache

对于共享内存(Shared memory),主要用于在UNIX 环境下不同进程之间共享数据,是进程间通信的一种方法,一般的应用程序不会申请使用共享内存,笔者也没有去验证共享内存对上面等式的影响。如果你有兴趣,请参考:What is Shared Memory?

关闭不使用的服务

如果你正在运行一个Linux 服务器,那么关掉那些不常用或者永远不会用到的服务是个好主意。

使用如下命令检查当前系统设置了哪些服务在启动时运行(注意,这与当前系统运行了哪些服务有区别)

# chkconfig --list |grep 3:on

如果你的系统默认运行在命令行模式,使用“3:on”,如果默认运行了图形界面,使用“5:on”,这个数字代表了系统的启动级别,在/etc/inittab 中进行配置。

对于一些你很清楚的非必要服务,使用如下命令停止服务,并关闭其在所有级别的启动,如果仅希望关闭在某个级别的启动,使用参数 --level,具体请参考笔者第一篇笔记。

# service srvname stop
# chkconfig srvname off

对于不清楚的服务,参考:Linux Services, Devices, and Deamons

比如,对于一般不启动图形界面的Linux 服务器,以下服务均可关闭:

  • rawdevices 用于裸设备
  • pcmcia 笔记本的pc 卡设置
  • apmd 笔记本电池监测
  • gpm 鼠标支持
  • autofs 自动mount文件系统
  • isdn 设置isdn连接
  • portmap 为NFS 等服务提供RPC 支持
  • nfs 网络文件系统服务器,让别人通过网络mount 你的文件
  • nfslock 服务于nfs
  • sendmail 邮件传输
  • squid 用于FTP 与HTTP 服务的代理缓存,加快web 访问速度
  • winbind 用于UNIX 中同步NT 主机上的帐号信息,一般用于配合SMB 共享
  • smb 与Windows主机进行文件与打印机资源共享
  • xfs X 系统下的字体服务
  • vsftpd FTP服务器

Linux服务器部署记录

1 安装2块网卡,8139、DLink530,Disable掉主板上已坏掉的声卡,BIOS日期为2000年1月1日2 安装Redhat 9,自定义包最小化安装3 磁盘分区,磁盘设备名:/dev/hdc,    主分区:        /boot(83)        /(83),         /home(83)        扩展分区(f)    逻辑分区:  ...
1 安装2块网卡,8139、DLink530,Disable掉主板上已坏掉的声卡,BIOS日期为2000年1月1日
2 安装Redhat 9,自定义包最小化安装
3 磁盘分区,磁盘设备名:/dev/hdc,
    主分区:
        /boot(83)
        /(83),
        /home(83)
        扩展分区(f)
    逻辑分区:
        /mnt/data1(FAT32)
        swap(82)
        /var/log(83)
4 grub启动,无密码,安装在主分区MBR
5 配置网卡
    eth0(DLink): 192.168.0.1(外网)
    eth1(8139):192.168.18.254(内网)
    主机名:aiview.com

6 配置ADSL
    #adsl-setup
    名称:ppp0
    选择设备eth0
    #ifup ppp0
    #adsl-status
    连接成功

    编辑/etc/sysconfig/network-scripts/ifcfg-ppp0
    添加一行
        DEMAND=no
    修改
        #PEERDNS=no
        #PPPOE_TIMEOUT=20
        #LCP_INTERVAL=80
        PEERDNS=yes
        PPPOE_TIMEOUT=80
        LCP_FAILURE=3
    这样就不会总超时自动关闭ADSL连接了。
        
    

7 配置IP转发和映射
    #echo 1 > /proc/sys/net/ipv4/ip_forward
    #iptables -t nat -A POSTROUTING -s 192.168.18.0/24 -o ppp0 -j MASQUERADE
    # iptables-save > /etc/sysconfig/iptables

8 配置其它客户端
    linux主机eth0已经与adsl modem连接好,eth1连接到hub的一个端口,windows客户端网卡连接到hub,
    windows主机设网卡定ip:192.168.18.198,网关:192.168.18.254
    打开IE即可上网     

9 安装网站
    获得Linux ADSL分配的动态IP,更改域名Aiview.com的指向到210.210.245.232。
    启动httpd和vsftpd
        #httpd -k start
        #service vsftpd start
        #chkconfig --level 3 httpd on
        #chkconfig --level 3 httpd on
        #chkconfig --level 3 httpd on

    创建用户alex
        groupadd -g 999 alex
        useradd -u 999 -g alex -G alex alex
        passwd alex
    
    ftp登录,上传站点文件site.tar和工具job.tar到/home/alex
    #tar -xvf site.tar
    #mv -r /home/alex/site/cgi-bin/* /var/www/cgi-bin
    #chown -R alex:alex /var/www/cgi-bin
    #chmod 755 /var/www/cgi-bin/weblog/*.cgi
    #chmod 755 /var/www/cgi-bin/awstats/*.pl
    #rmdir /home/alex/site/cgi-bin
    #mv -r /home/alex/site/* /var/www/html
    #chown -R alex:alex /var/www/html
    #chmod -R 777 /var/www/html
    #find /var/www/html -type f |xargs chmod 666
    #mv -r /home/alex/job.tar /root
    #tar -xvf job.tar
    #cd job
    #vi awfix.sh
    #su - alex
    $mkdir httpdlog
    $exit
    #./awudp.sh
    
    装入第一张redhat9光盘,安装perl模块
    #mount /mnt/cdrom
    #cd /mnt/cdrom/Redhat/RPMS
    #rpm -ivh perl-5.8....
    #rpm -ivh perl-URI....
    #cd
    #umount /mnt/cdrom
    装入第二张redhat9光盘,安装perl模块
    # rpm -ivh perl-DB_File-....


    编辑/home/alex/site/cgi-bin/weblog/mt.cfg
        将DataSource /var/www/html/alex/weblog/mtdb修改为:/var/www/html/weblog/mtdb
    编辑/var/www/cgi-bin/weblog/tmpl/cms/edit_entry.tmpl
        找到串"/var/www/html/alex/weblog/editlet/editlet_new.html",修改为:
        "/var/www/html/weblog/editlet/editlet_new.html"

    编辑 /etc/httpd/conf/httpd.conf
        变更默认的字符集为GB2312
        修改404的文档到/archives/missing.html
        为了兼容旧版本网站增加默认索引文档 index.htm,需排在index.html之后
        禁止访问者列目录,注释掉:Options Indexes FollowSymLinks,变为:#Options FollowSymLinks

    访问http://www.aiview.com/cgi-bin/weblog/mt.cgi,修改Blog“DB2学习笔记”的参数,将/var/www/html/alex...改为/var/www/html,保存

写于:2005/7/31
更新:2005/8/1

在RHEL2.0 上部署Websphere5.0 集群环境

根据笔者在项目中的实践经验,本文介绍了在Redhat Linux企业版上部署IBM Websphere5.0 Cluster 的一般步骤,如果您感兴趣,欢迎来信提出意见。 服务器软硬件环境Linux 操作系统版本: RHEL 2.1 (Red Hat Enterprise Linux) pplication Server 版本:IBM...

根据笔者在项目中的实践经验,本文介绍了在Redhat Linux企业版上部署IBM Websphere5.0 Cluster 的一般步骤,如果您感兴趣,欢迎来信提出意见。

服务器软硬件环境

  • Linux 操作系统版本: RHEL 2.1 (Red Hat Enterprise Linux)
  • pplication Server 版本:IBM Websphere Application Server 5.0
  • 数据库版本:IBM DB2 UDB v8.1
  • 4台xSeries 335, 双scsi硬盘,一块暂时未用。
  • 1台xSeries 345, 双scsi硬盘,做了镜像,接了一个磁盘阵列,使用345自带的raid卡。
  • 磁盘阵列,6块scsi盘,5块做了raid 5,余下一块做spare盘。
  • 四台335主机用于Websphere集群,将在其中一台安装WAS ND 版本(Websphere Network Deployment)、称为管理节点,其他三台安装WAS 服务和DB2 的客户端,称为业务节点,并在其中一个节点安装IHS(IBM Http Server)。

部署步骤

  1. 为5台服务器安装RHEL 2.1,如果处理中文,需要在安装过程中选择语言包支持;
  2. 在345主机上安装DB2服务,创建数据库;
  3. 在三台业务节点上安装WAS 5.0, 然后安装WAS FP2;
  4. 在一台业务节点安装IHS;
  5. 为了访问数据库,以上三台业务节点还需要安装DB2 V8.1 运行时客户端,安装完成之后,运行/opt/IBM/db2/V8.1/instance/db2icrt 创建实例,编目远程数据主机节点,编目远程数据库;
  6. 在余下管理节点上安装WAS ND版,然后安装WAS ND FP2;
  7. 配置WAS 服务:
    • 在startServer.sh 文件开头加入如下语句:/home/db2/sqllib/db2profile
    • 前面的路径根据DB2 实例安装位置的不同有所不同;
    • 配置WAS环境变量 DB2_JDBC_DRIVER_PATH 为:
      /opt/IBM/db2/V8.1/java
    • 建立安全认证别名,需要访问远程数据库的有效用户名和密码;
    • 建立数据源,驱动程序使用'{DB2_JDBC_DRIVER_PATH}/db2java.zip',数据库名称使用上面编目的远程数据库别名,选择认证别名;配置好后可以使用测试数据源功能测试是否可以正常访问数据库(只有安装Fix Pack 2 才提供测试功能);
  8. 启动WAS,访问http://localhost:9090/admin 部署应用程序,部署好的应用程序通过以下地址访问:
    http://localhost:9080/AppName

以上是配置的大体步骤,配置成功之后,可以通过安装了IHS的业务节点来访问部署的企业应用,负载会被分布在三台业务节点上,由WAS ND来自动进行调配,实现了企业应用的高可用性,以及业务处理的负载均衡。随着企业业务规模的扩大,可以很方便的通过增加节点来处理大量的请求。对于以上主机的网络配置,仅仅安装IHS的业务节点需要公网IP地址,用于对外发布Web服务。其他节点均配置内部地址,可以放入安全区域,尤其是数据库服务器,可设定更严格的安全策略,这里不作深入讨论。

WAS与Linux兼容性

根据IBM 与RedHat 的官方资料,WAS与RH Linux对应关系如下:

  • WAS 5.0 +RHEL 2.1 AS
  • WAS 5.1 +RHEL 3.0 AS + update level 1
RHEL 3.0官方声明可以支持IBM WAS 5.1,但需要升级到RHEL update level 1升级包,还需要安装一些其他的补丁。 WAS 5.0是无法在RHEL 3.0版本上安装成功的,因为RHEL使用jdk1.4,而WAS 5.0采用的是jdk1.3.1。如果在这样的环境下安装,安装过程会报出以下错误:
Segment fault.
尝试过设置如下环境变量,也并不能够解决此问题,因此版本的选择,在规划时必需要搞清楚,免得部署阶段麻烦。
LD_ASSUME_KERNEL=2.2.5
或者 
LD_ASSUME_KERNEL=2.4.19
RPM_FORCE_NPTL=1

参考资源

Linux 系统管理学习笔记(二)

Linux系统管理命令的一点拾零,这是第二部分,主要关注Linux系统安全方面。其余的笔记请到这里浏览。 正文 给一个目录设置粘连位,设置了粘连位的目录在属性中的最后一位有一个字母t,使用ls -l查看。设置了粘连位的目录中,用户只能删除自己创建的文件。$ chmod +t dir_name 比如一般linux发布中,/tmp目录默认被设置粘连位。$ ls -ld /tmpdrwxrwxrwt 27 root root 8192 Nov...

Linux系统管理命令的一点拾零,这是第二部分,主要关注Linux系统安全方面。其余的笔记请到这里浏览

正文

给一个目录设置粘连位,设置了粘连位的目录在属性中的最后一位有一个字母t,使用ls -l查看。设置了粘连位的目录中,用户只能删除自己创建的文件。

$ chmod +t dir_name

比如一般linux发布中,/tmp目录默认被设置粘连位。

$ ls -ld /tmp
drwxrwxrwt 27 root root 8192 Nov 29 23:12 /tmp

另外还有两个文件许可位,suid与sgid。设置了suid或者sgid许可位的文件在执行时,不依赖于当前执行的用户(或当前执行用户的组),而使用此文件所有者(或所有者的组)的身份来执行。
设置了suid或者sgid位的文件,相应许可位rwx中的x变为s。
使用如下命令设置设置suid位:

# chmod u+s filename
# ls -l filename
-rwsr-xr-x

使用如下命令设置sgid位:

# chmod g+s filename
# ls -l filename
-rwxr-sr-x

使用下面的命令可以列出系统中所有的suid或者sgid程序:

# $ find / \( -perm -02000 -o -perm -04000 \) -ls

定期使用命令

# grep -i 'authentication failure' /var/log/messages > failed_logins.txt

查看系统是否有未成功的登录企图是很有用的,不同的linux发布可能有不同的特征串,其中-i参数指定匹配中忽略大小写。
也可以把这个命令作为一个任务定期运行,但要注意文件的输出问题,以及定期做检查与清理工作。

可以设置一个文件为追加模式,只能加入内容,不允许删除,或者减少内容的操作,只有root能够设置这个属性。

# chattr +a filename

注意,设置了+a 的文件即使root本身也不无法修改和删除,除非使用去除属性设置:

# chattr -a filename

这个操作可以应用于系统的日志文件,这些文件正常情况下只是追加,即使root也不会有删除这些文件内容的需要,这会给已取得root权限的黑客造成一点小的障碍,延误他破坏的进程,虽然只是一小步。
设置了+s属性的文件,在删除时,会把磁盘块清零。

查看一个文件使用chattr设置的属性。

# lsattr filename 

LIDS,一个内核级的Linux入侵检测系统,可以检测到Nmap、SATAN等工具所作的半公开扫描、SYN秘密扫描、秘密FIN以及Xmas等。可讲检测到的扫描通过syslog后者email记录下来。
下载地址:http://www.lids.org
安装lids之后需要重新编译内核,再次安装并重启动linux系统。

Linux系统的日志主要分为两种类型:

  1. 进程所属日志
  2. syslog消息

前者是由用户进程或其他系统服务进程自行生成的日志,比如apache服务器的access_log与error_log日志文件。
后者是由系统syslog记录的日志,任何希望记录日志的系统进程或者用户进程都可以给调用syslog来记录日志,这是一个面对多数应用程序记录日志的通用解决方法。
一般这个消息会发送给/dev/log,然后由syslog记入日志文件。
syslogd是linux系统中默认的系统日志守护进程,可以通过/etc/syslog.conf进行配置消息的去向。如下行取自/etc/syslog.conf文件:

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;news.none;authpriv.none;cron.none /var/log/messages

# The authpriv file has restricted access.
authpriv.* /var/log/secure

# Log all the mail messages in one place.
mail.* /var/log/maillog


# Log cron stuff
cron.* /var/log/cron

# Save boot messages also to boot.log
local7.* /var/log/boot.log

syslog中的功能划分如下:

  • auth 安全性/验证消息(负面)
  • authpriv 安全性/验证消息
  • cron cron 和at
  • daemon 其他系统守护进程(sshd,inetd,pppd等)
  • kern 内核消息
  • lpr 行打印子系统
  • mail 邮件子系统(sendmail,postfix,qmail等)
  • news Usenet新闻消息
  • syslog 内部syslog消息
  • user 一般用户级消息
  • uucp UUCP子系统
  • local0-local7 自定义的级别

syslog的日志级别:

  • emerg 系统以不可用
  • alert 必须马上采取行动
  • crit 危急
  • err 错误
  • warning 警告
  • notice 普通但重要的情形
  • info 通知消息
  • debug 调试消息

syslog.conf 的第一列用来指定日志功能和日志级别,中间用.隔开,可以使用*来匹配所有的日志功能和日志级别
第二列是消息的分发目标,可以有如下格式:

/path/to/filename 将消息追加到指定的文件尾,最常用
@loghost 将消息写到loghost主机上的syslog服务器
|/path/to/named_pipe 将消息写到指定的命名管道(便于外部程序过滤消息)
user1, user2 将消息写到指定的用户
* 将消息写到所有的用户
/de/console, /dev/tty1 等 将消息写到指定的终端

一个好的syslog.conf应该如下:

# Log ALL messages to /var/log/messages
# for easy scanning by log checkers
*.debug /var/log/messages

# write to terminals for really bad situations
kern,daemon.crit /dev/console
kern,daemon.crit root
*.emerg *

# Separate out other logs to be easier to read
# Debug level for more important facilities
kern.debug /var/log/kern.log
mail.debug /var/log/mail.log
daemon.debug /var/log/daemon.log
auth.debug /var/log/auth.log
syslog.debug /var/log/syslog.log
authpriv.debug /var/log/authpriv.log
fpt.debug /var/log/ftp.log

# Notice fine for others
user.notice /var/log/user.log
lpr.notice /var/log/lpr.log
news.notice /var/log/news.log
uucp.notice /var/log/uucp.log
cron.notice /var/log/cron.log
local0,local1,local2.notice /var/log/local.log
local3,local4,local5.notice /var/log/local.log
local6.notice,local7.notice /var/log/local.log

在修改了syslog.conf文件的同时,别忘了,应该把旧的日志文件归档到一个统一的目录,比如: old_log,这样可以使日志文件更清晰一些。但要注意,新的日志文件中,也使用了messages这个文件。

syslogd也可以在shell中被调用,任何验证的用户都可以通过如下调用,在日志中产生一行:

$ logger -p kern.alert -t 'su(pam_unix)' "authentication failure..."

这与一条失败验证产生的日志一模一样。而且黑客可能会大量的产生无用日志信息,用来塞满日志系统,使日志发生轮回,以清除旧的日志,或者使日志塞满,无法再记录新的日志。
因为,我们在保护日志的同时,也必须认识到,日志中的内容并不是完全可信的。

日志文件的许可设置原则:
只有root可以写入日志文件,并且只有logs组的用户才有读权限,如下

# addgroup logs
# cd /var/log
# chgrp -R logs .
# find . -type -d | xargs chmod 750
# find . -type -f | xargs chmod 640
# chmod 750 .

还需要保证/var/log 目录只有root才能写入,否则日志可以被别人删除:

# ls -ld /var/log
drwxr-xr-x 17 root root 4096 Nov 29 01:52 /var/log

一种保护日志的方式,在网络中设定一台秘密的syslog主机,把这台主机的网卡设为混杂模式,用来监听子网内所有的syslog包,这样把所有需要传送日志的主机配置为向一台不存在的主机发送日志即可。
这样即使黑客攻陷了目标主机,也无法通过syslog.conf文件找到备份日志的主机,那只是一个不存在的主机。实际操作中还可以辅以交换机的配置,以确保syslog包可以被备份日志主机上的syslog进程接受到。
比如把syslog.conf中的传送日志主机设为 @192.168.0.13,但实际网络中不存在这个日志主机,实际可能是192.168.0.250或者其他主机正在接受syslog包。

子网掩码30意味着这个子网中只有2台主机。

对于域名拥有者来讲,保存在域名中心的个人信息即是某种正当的需要,同时也暴露了很多个人的隐私,因为这些个人信息一般都填写的是真实有效的。
在unix中,通过如下命令,就可以取到这些的信息,而这对于那些打算展开社交攻击的黑客们已经足够了。

$ whois domain.com 

对于有些whois的版本,在第一次仅会查出有关这个域名的基本信息,但其中包含了用于进一步查找这个域名的服务器:

Whois Server: whois.xxxxxx.xxx

可以通过如下命令进一步查找更详细的信息:
whois domain.com@whois.xxxxxx.xxx

当前在redhat 9发布版本中所带的whois版本已经可以自动进行这种进一步查找,你只需要简单的发布一次:

$ whois domain.com

对于一个IP地址,也可以使用whois服务器查询这个IP地址被分配给了那个组织。这需要使用whois.arin.net数据库:

$ whois ip@whois.arin.net

一般会返回详细信息,包括组织的地址与电话,如果这个whois数据库不包含具体信息,一般会返回一个ReferralServer,比如:

ReferralServer: whois://whois.apnic.net

这是亚太地区的一个服务器,可以继续查询:

$ whois ip@whois.apnic.net

一般这会返回这个ip所属的组织详细信息。

touch命令可用来修改文件属性

# touch -t 200411280000.00 filename

如下命令可以用于找出2004年11月28日以后所有修改过的文件:

# touch -t 200411280000.00 /tmp/comparison
# find / \( -newer /tmp/comparison -o -cnewer /tmp/comparison \) -ls

有关系统漏洞方面的最受推荐的一个邮件列表:

其他还有Vulnwatch和Linux Security等。

参考资源

awstats 日志统计工具安装

安装过程参考了车东的文章 。 在http://awstats.sourceforge.net/ 下载了项目的二进制文件包,是tgz格式,800多k。目前是6.2版本。 $ wget http://optusnet.dl.sourceforge.net/sourceforge/awstats/awstats-6.2.tgz $ gunzip -d awstats-6.2.tgz $ tar -xvf awstats-6.2.tar...

安装过程参考了车东的文章

http://awstats.sourceforge.net/ 下载了项目的二进制文件包,是tgz格式,800多k。目前是6.2版本。

$ wget http://optusnet.dl.sourceforge.net/sourceforge/awstats/awstats-6.2.tgz
$ gunzip -d awstats-6.2.tgz
$ tar -xvf awstats-6.2.tar

解出了目录 awstats-6.2

进来查看了README,觉得自动配置更让人头痛,决定手动安装,直接把 awstats-6.2/wwwroot/cgi-bin 目录copy到apache目录:/var/www/cgi-bin/

 

# mv awstats-6.2/wwwroot/cgi-bin /var/www/cgi-bin/awstats
#cd /var/www/cgi-bin/awstats


打开awstats.model.conf 进行配置

把LogFile换成自己的log地址,比如/var/logs/httpd/access.log

SiteDomain换成自己的域名:aiview.com

hostAliases中加入自己的主机别名,与原有的用空格分开

其他都不作改变,日志格式等均与现有匹配。

打开浏览器,运行http://www.aiview.com/cgi-bin/awstats/awstats.pl

报错了,403,无权限访问。
回来看一下cgi-bin下面的目录

# ls -ld /var/www/cgi-bin/awstats

目录awstats的权限位不对,更改一下

 

# chmod 755 awstats

回来浏览器再运行一次,统计的表格出来了,但数据都是空的,顶部有信息提示,需要更新一下统计信息。到shell,根据文档提示,运行

$ ./awstats.pl  -config=aiview.com -update


提示更新成功。回到浏览器再次查看,2个月的统计信息出来了,已经自动把历史日志文件(*.1, *.2...)进行合并,但关键字分析部分,中文关键字是乱码,需要更改配置文件中的编码。

安装完毕!

Linux 系统管理学习笔记(一)

Linux系统管理命令的一点拾零,这是第一部分,其余的笔记请到这里浏览。 正文 编辑/etc/hosts.allow 和/etc/hosts.deny,设置TCP内核级的访问控制。若需要允许/禁止所有地址对所有服务的访问,添加如下条目:all:all 若需要允许/禁止192.168.1.100对ssh服务的访问,添加如下条目:ssh:192.168.1.100 当两个文件中的策略发生冲突时,以hosts.allow中的条目优先。配置iptables防火墙,如果不具备娴熟的技巧,建议一定要在所配置主机的本地控制台上进行,不要远程配置,因为,一旦配置了一条与当前连接匹配的过滤规则,则会马上生效,并终止当前的连接,甚至某些规则会导致即使在本地主机上也无法登录,比如将"iptables -P INPUT -j DROP" 作为的一条过滤规则命令发布就会导致这种情况,此时,任何远程或者本地都无法登录主机,可以冷启动主机解决此问题,因为尚未发布iptables-save 命令来保存规则设置。inconfig interface [[-net|-host] address [parameters]]ipconfig...

Linux系统管理命令的一点拾零,这是第一部分,其余的笔记请到这里浏览

正文

编辑/etc/hosts.allow 和/etc/hosts.deny,设置TCP内核级的访问控制。
若需要允许/禁止所有地址对所有服务的访问,添加如下条目:

all:all

若需要允许/禁止192.168.1.100对ssh服务的访问,添加如下条目:

ssh:192.168.1.100

当两个文件中的策略发生冲突时,以hosts.allow中的条目优先。

配置iptables防火墙,如果不具备娴熟的技巧,建议一定要在所配置主机的本地控制台上进行,不要远程配置,因为,一旦配置了一条与当前连接匹配的过滤规则,则会马上生效,并终止当前的连接,甚至某些规则会导致即使在本地主机上也无法登录,比如将"iptables -P INPUT -j DROP" 作为的一条过滤规则命令发布就会导致这种情况,此时,任何远程或者本地都无法登录主机,可以冷启动主机解决此问题,因为尚未发布iptables-save 命令来保存规则设置。

inconfig interface [[-net|-host] address [parameters]]

ipconfig eth0 192.168.0.1
ipconfig eth1 203.99.9.9

promisc 参数用于把此以太接口置于“混乱”状态, -promisc 取消此状态。

netstat -r 显示路由信息
netstat -i 以IP地址格式显示
netstat -i 列出配置特性
netstat -a 列出内核中所有接口
netstat -t 仅列出TCP连接
netstat -u 仅列出UDP连接

/etc/host.conf bind 服务器的核心配置文件
/etc/resolv.conf bind 服务器的解析配置文件


DNS的数据库中包含三种类型的记录:

  1. A记录 将主机名映射为IP地址
  2. CNAME记录 将主机的别名和其正式主机名关联在一起,指向一条A记录
  3. SOA记录 表示Start of Authority,其中容纳服务器所属的区之普通信息。比如,它包含所有记录的默认TTL值。

主机名如果以“.“结尾,代表是绝对主机名,即一个完整的包含域名的规范主机名(如:www.domain.com.),否则是一个相对主机名,代表主机名与某一个域名相关联。

SOA记录中的特殊名“@”代表其自身的域名。如果希望解析domain.com 本身到某个IP地址,则使用“@”作为主机名即可。如果希望解析所有xxx.domain.com 到某个IP 地址(xxx可以是任何字母),则使用“*”作为主机名。


/etc/services文件定义了服务名到端口号的转换。

查看磁盘使用情况

$ df -kl 

把 *.tar.Z的文件包解压缩成.tar文件,

$ gunzip -dv filename.tar.Z 

再用tar 命令进行解包,其中,-v用于显示解包过程

$ tar -xvf filename.tar 

把目录打成一个tar包

$ tar -cvf newfile.tar directory

一次完成解压缩和解包.tar.gz 文件的命令

$ tar -zxvf filename.tar.gz

重新启动xinetd服务,用于修改xinetd配置文件后,不需重起主机而重新装载文件。 

# /etc/init.d/xinetd reload 

其他的参数:start, stop, restart, status...
此命令需要root权限执行。

以root的身份执行xinetd命令, 并不更改当前shell

$ su - root -c xinetd reload # 

也可以:

$ su - root -c '(cmd1;cmd2)'

解开 '.bz2' 文件

$ bzip2 -d *.tar.bz2

对于iso文件,linux可以采用mount命令读取,如:

$ mkdir /mnt/iso
$ mount -t iso9660 -o loop disc1.iso /mnt/iso
$ ls /mnt/iso

把一张光盘制作成iso文件(首先mount好光驱):

$ cp /mnt/cdrom disc1.iso

解压.zip文件到新的目录:

$ unzip -d newdir file.zip

查看文件或目录所占用的磁盘块多少,目前linux版本下每个磁盘块默认是1k:

$ du /tmp
$ du /tmp/log.txt

查看文件目录所占用的详细字节数:

$ du -ab /tmp
$ du -ab /tmp/log.txt

命令行下通过http协议下载文件:

$ wget http://www.download.com/file.exe

支持续传:

$ wget -c url

还有很多其他参数,设置cache、http用户认证和代理认证等。

rcp命令可以用于在linux主机间copy文件

列出系统中的所有服务,查看在各个系统启动级别的启动设置:

# chkconfig --list

更改服务启动设置(会修改所有系统启动级别的设置):

# chkconfig srvname on|off

仅修改特定级别的启动设置,n可以指定从1至5:

# chkconfig --level n srvname on|off

启动或者停止某个服务:

# service srvname start|stop

查看所有服务状态:

# service --status-all
查看某个服务状态:
# service srvname status

系统的syslogd服务会写日志文件/var/log/messages,一般其他应用程序的消息也会通过syslogd记录在此文件。
可是用如下命令监视:

$ tail -f /var/log/messages

参考资源

mail.png


最近更新|Recent Entries

不定期更新|Handy Entries

分类栏目|Categories

按月归档|By Month

2008
11
10
07
05
04
03
02
01
2007
12
10
07
06
05
04
03
02
01
2006
12
11
10
09
08
07
06
05
04
03
02
01
2005
11
10
09
08
07
04
03
2004
12
11
10
09
08
07
06
05
04
03
02
01
2003
12
10
09
08
06
2002
09
08
04
03
02
2001
12
09
07
06
05

站内链接|Site Links

Powered by
Movable Type 3.34