Archive

Archive for the ‘开源软件’ Category

Debian 下 MacBook 触摸板设置

March 30th, 2009 1 comment

窃以为,MacBook 的触摸板是 Apple 人机界面中最不方便的一环,只有一个按键,手感也不如 IBM 的指点杆,没有鼠标情况下,操作非常不方便。

Linux 下的 MacBook 触摸板更是痛中之痛。Linux 下触摸板的驱动是 Synaptics,默认设置下,移动速度很慢,反应不灵敏;用两手指轻敲模拟右键的功能无法使用,不接外接鼠标就没有右键;用着简直抓狂。一直以来用 IBM 笔记本养成的在床上编程的习惯受到了严重挑战。

在新版本的 xorg 的中,可以自动发现硬件设备并自动配置,允许用户使用最小化的 xorg.conf 启动 X。其实就是一个空的 xorg.conf 也能启动。但该功能和现存的 Synaptics 配置方法相抵触,导致 google 上搜到的大部分配置方法都不能成功配置 Synaptics 的参数。

解决方法很简单:

  • 方法1:提供一个完整的,old fashion 的 xorg.conf 文件,尤其要包含 ServerLayout Section,其中要引用 Synaptics Section
  • 方法2:如果仍然希望使用 minimal xorg.conf,应该在 Synaptics Section加上 Option “CorePointer”

很显然,方法2要简单些。下面提供一个用方法2配置的 xorg.conf 文件,包含我的 Synaptics 配置。功能如下

  • 禁用 1 Finger Tap 功能
  • 2 Finger Tap 对应右键,3 Finger Tap 对应中键(按不出来),同时点击左上角区域代表中键
  • 触摸板右边和底边分别是垂直和水平滚轮
  • 其他是一些微调参数,主要为了让触摸板更灵敏

下面配置应该适用于 Debian Lenny/Squeeze/Sid,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Section "InputDevice"
    Identifier "Synaptics Touchpad"
    Driver "synaptics"
    Option "SHMConfig" "on"
    Option "CorePointer"
    Option "LeftEdge" "121"
    Option "RightEdge" "1094"
    Option "TopEdge" "80"
    Option "BottomEdge" "300"
    Option "FingerLow" "10"
    Option "FingerHigh" "15"
    Option "FingerPress" "256"
    Option "MaxTapTime" "300"
    Option "MaxTapMove" "220"
    Option "MaxDoubleTapTime" "180"
    Option "SingleTapTimeout" "180"
    Option "ClickTime" "100"
    Option "FastTaps" "1"
    Option "EmulateMidButtonTime" "75"
    Option "EmulateTwoFingerMinZ" "257"
    Option "VertScrollDelta" "5"
    Option "HorizScrollDelta" "5"
    Option "VertEdgeScroll" "1"
    Option "HorizEdgeScroll" "1"
    Option "CornerCoasting" "0"
    Option "VertTwoFingerScroll" "0"
    Option "HorizTwoFingerScroll" "0"
    Option "MinSpeed" "0.493"
    Option "MaxSpeed" "1.5544"
    Option "AccelFactor" "0.2"
    Option "TrackstickSpeed" "40"
    Option "EdgeMotionMinZ" "30"
    Option "EdgeMotionMaxZ" "160"
    Option "EdgeMotionMinSpeed" "1"
    Option "EdgeMotionMaxSpeed" "38"
    Option "EdgeMotionUseAlways" "0"
    Option "UpDownScrolling" "1"
    Option "LeftRightScrolling" "1"
    Option "UpDownScrollRepeat" "1"
    Option "LeftRightScrollRepeat" "1"
    Option "ScrollButtonRepeat" "100"
    Option "TouchpadOff" "0"
    Option "GuestMouseOff" "0"
    Option "LockedDrags" "0"
    Option "LockedDragTimeout" "5000"
    Option "RTCornerButton" "0"
    Option "RBCornerButton" "0"
    Option "LTCornerButton" "2"
    Option "LBCornerButton" "0"
    Option "TapButton1" "0"
    Option "TapButton2" "3"
    Option "TapButton3" "2"
    Option "CircularScrolling" "0"
    Option "CircScrollDelta" "0.1"
    Option "CircScrollTrigger" "0"
    Option "CircularPad" "0"
    Option "PalmDetect" "1"
    Option "PalmMinWidth" "10"
    Option "PalmMinZ" "200"
    Option "CoastingSpeed" "0"
    Option "PressureMotionMinZ" "30"
    Option "PressureMotionMaxZ" "160"
    Option "PressureMotionMinFactor" "1"
    Option "PressureMotionMaxFactor" "1"
    Option "GrabEventDevice" "1"
EndSection
Categories: Apple, 开源软件 Tags: ,

Debian 下编译静态链接的 ffmpeg 版本

March 24th, 2009 1 comment

ffmpeg 是一款开源视频编码转换工具,最近刚刚发布 0.5 版本。ffmpeg 支持 h264,mpeg4,aac,mp3,等多种视频音频编码格式,同时支持 avi,mp4,mov,flv 等多种 container 格式。

Debian 中源中自带 ffmpeg,由于版权问题,只支持很少的几种编解码器,功能非常弱,可用性比较差。Debian Multimedia 项目弥补了这一缺陷,提供了预编译好的支持各种常用格式的 ffmpeg。

由于 Linux 发行版对于动态链接库的使用情有独钟,喜欢用链接到 Shared Object(so)库的方式编译各种软件,Debian 自然也不例外。而 ffmpeg 这款博览各家之长的软件拥有众多的库依赖关系,因此不能单独安装。不同发行版之间,甚至相同发行版的不同版本号之间,ffmpeg 的安装包都是不兼容的。安装起来非常不方便。

花了一周末的时间,使用 Debian 成功编译出静态链接的 ffmpeg 版本,得到脚本如下。下载后在 Debian 中直接运行即可。我在当前 Debian Multimedia 的 ffmpeg-0.5.svn20090318,和 Sid,Squeeze,Lenny 上测试该脚本成功。如果软件下载速度太慢,请自行修改脚本中的 Debian 源 URL。

另外,我用 Intel C Compiler 编译了 ffmpeg 的静态版本,只能运行在 Cuo 2 Duo 之后的芯片上。简单测试了一下,mpeg4 编码大概能比 gcc 版本快 10% 左右。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#/bin/sh
cat > /etc/apt/sources.list.d/build-static-ffmpeg.list <<EOF
deb http://debian.ustc.edu.cn/debian sid main contrib non-free
deb-src http://debian.ustc.edu.cn/debian sid main contrib non-free
 
deb http://debian.ustc.edu.cn/debian-multimedia sid main
deb-src http://debian.ustc.edu.cn/debian-multimedia sid main
EOF
apt-get update
apt-get -t sid install debian-multimedia-keyring debian-archive-keyring
 
mkdir -p nvidia-glx-dev/DEBIAN
cat > nvidia-glx-dev/DEBIAN/control <<EOF
Package: nvidia-glx-dev
Priority: optional
Maintainer: nobody@example.com
Architecture: all
Version: 180.29
Description: dummy package for nvidia-glx-dev
 dummy package for nvidia-glx-dev
EOF
 
dpkg-deb -b nvidia-glx-dev
dpkg -i nvidia-glx-dev.deb 
 
apt-get -t sid build-dep ffmpeg || ( apt-get -t sid install libsdl1.2-dev && apt-get -t sid build-dep ffmpeg )
apt-get -t sid install libusb-1.0-0-dev
 
apt-get -t sid source ffmpeg
 
cd ffmpeg-*/
 
cat > static_build <<EOF
debian/rules clean
debian/rules patch
 
CFLAGS="-Wall -g"
CC="ccache gcc"
NCPUS=\$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
 
./configure \
	--disable-ffplay --disable-ffserver --disable-shared --enable-static \
	--extra-libs="-static -ldirac_encoder -ldirac_decoder -lstdc++ -lspeex -lvorbis -lxvidcore -ldc1394 -lraw1394 -lusb-1.0 -lm -lasound -ldl" \
	--prefix=/usr --extra-cflags="\$CFLAGS" --cc="\$CC" \
	--libdir=\\\${prefix}/lib --shlibdir=\\\${prefix}/lib --bindir=\\\${prefix}/bin \
	--incdir=\\\${prefix}/include/ffmpeg --enable-libmp3lame \
	--enable-gpl --enable-libfaad --mandir=\\\${prefix}/share/man --enable-libvorbis \
	--enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc \
	--enable-libamr-nb --enable-libamr-wb --enable-x11grab --enable-libgsm \
	--enable-libx264 --enable-libtheora --enable-libdc1394 \
	--enable-nonfree --disable-stripping --enable-avfilter --enable-libdirac \
	--disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger \
	--enable-libspeex --enable-avfilter-lavf --disable-mmx \
	--disable-altivec --disable-armv5te --disable-armv6 --disable-vis
 
echo "#define FFMPEG_VERSION \"SVN-r18029-static\"" > version.h
 
make -j \$NCPUS && echo Build success || echo build failed
strip ffmpeg
 
./ffmpeg -version
cp ffmpeg ..
EOF
 
. static_build 
echo Type ". static_build" under source code dir to rebuild
Categories: 开源软件 Tags: , ,

用 syslinux 引导 Windows

March 22nd, 2009 2 comments

FAT 分区的引导扇区(Boot Sector)的功能是将 Windows XP 的 ntldr 文件,或 Windows Vista 的 bootmgr 文件加载到内存适当位置,由此启动 Windows。

Linux 下可以创建 Windows 的 FAT 文件系统,但是不能创建 FAT 文件系统中的 Boot Sector,也就是不能创建可以引导的 FAT 分区,因而 Linux 下无法创建可以引导的 Windows 磁盘。

不过可以曲线救国,通过 syslinux 来引导 Windows。 首先,将 syslinux 安装到 Windows 分区设备上。

syslinux /dev/sdXY

然后,将 syslinux 自带的 chain.c32 文件拷贝到 Windows 分区上。如果是 Debian,这一文件在 /usr/lib/syslinux/ 目录下。

接着,在 Windows 分区上创建 syslinux.cfg 文件

default 1
timeout 0
label 1
  kernel chain.c32
  append hd0,1 ntldr=ntldr

chain.c32 接受的第一个参数代表启动第1块硬盘的第1个分区,并装载分区上的 ntldr 文件。用该配置文件可以引导 Windows XP。如果需要引导 Windows Vista,需要修改成下述内容:

default 1
timeout 0
label 1
  kernel chain.c32
  append hd0,1 ntldr=bootmgr

chain.32 接受的参数说明如下

  • option “swap” to support swapping of BIOS drive numbers. This is necessary to boot certain operating systems (DOS, Windows) from a secondary drive.
  • option “file=” to support loading a boot file from the SYSLINUX filesystem instead of loading the boot sector from the drive.
  • option “seg=” to control the load location.
  • option “ntldr=” as a shorthand for “seg=0×2000 file=”; use this to load one of WinNT’s loaders
  • options “freedos=” and “msdos=”/”pcdos=” as shorthands for “seg=0×60 file=” and “seg=0×70 file=” respectively; use this to load FreeDOS’s kernel.sys, MS-DOS’s io.sys or PC-DOS’s ibmbio.sys.
Categories: 开源软件 Tags: , ,

Linux 下读写 FAT 属性信息

March 22nd, 2009 Comments off

FAT 是 Windows 下的文件系统格式。每个 FAT 下的文件都包含 ARHIVE,SYSTEM,HIDDEN,READ-ONLY 等属性。而 Linux 下面缺乏读写 FAT 属性信息的命令,难以读出,或者设置这些 FAT 属性。

而实际上 Linux 内核的 vfat 模块包含相应的 ioctl 命令,可以修改文件的属性。在 <linux/msdos_fs.h> 定义如下:

#define FAT_IOCTL_GET_ATTRIBUTES	_IOR('r', 0x10, __u32)
#define FAT_IOCTL_SET_ATTRIBUTES	_IOW('r', 0x11, __u32)

上述两个 ioctl 命令接受一个 int 类型,该 int 值的不同 bit 位,按照下面的定义表示不同的文件属性:

#define ATTR_RO		1	/* read-only */
#define ATTR_HIDDEN	2	/* hidden */
#define ATTR_SYS	4	/* system */
#define ATTR_VOLUME	8	/* volume label */
#define ATTR_DIR	16	/* directory */
#define ATTR_ARCH	32	/* archived */

由于没有发现有命令可以利用上述 ioctl 接口,操作 FAT 文件的属性,我自己写了一个 attrib.py 文件,代码在最后。该命令接收两个参数,说明如下

Usage: ./attrib.py dir_or_file dump|load

下面的命令将 /mnt/fat 目录下所有子目录和文件的属性输出到文件 attributes.dump 文件中

./attrib.py /mnt/fat dump > attributes.dump

./attrib.py dump 输出的部分内容如下:

A..SHR     ./ntldr
A..SHR     ./NTDETECT.COM
A..SHR     ./boot.ini
A..SHR     ./IO.SYS
A..SHR     ./MSDOS.SYS
.D..H.     ./WINDOWS/inf
.D.S.R     ./WINDOWS/Fonts
.D.SH.     ./WINDOWS/Installer
.D.S..     ./WINDOWS/Tasks
.D.S..     ./WINDOWS/Downloaded Program Files
...SH.     ./WINDOWS/winnt.bmp
...SH.     ./WINDOWS/winnt256.bmp
A...HR     ./WINDOWS/WindowsShell.Manifest
A..S..     ./WINDOWS/bootstat.dat

下面的命令将根据 attributes.dump 文件中包含的属性信息,给 /mnt/fat 目录下所有子目录和文件设置相应的属性

./attrib.py /mnt/fat load < attributes.dump

下面是 attrib.py 的源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
import os
import sys
import fcntl
import posixpath
 
ATTR_ARCH = 0x20
ATTR_DIR = 0x10
ATTR_VOLUME = 0x08
ATTR_SYSTEM = 0x04
ATTR_HIDDEN = 0x02
ATTR_RO = 0x01
 
AttrBitName = {
    ATTR_ARCH: 'A',
    ATTR_DIR: 'D',
    ATTR_VOLUME: 'V',
    ATTR_SYSTEM: 'S',
    ATTR_HIDDEN: 'H',
    ATTR_RO: 'R',
}
 
AttrBits = AttrBitName.keys()
AttrBits.sort()
AttrBits.reverse()
 
FAT_GETATTR_IOCTL = 0x80047210
FAT_SETATTR_IOCTL = 0x40047211
 
def fat_getattr(filename):
  fd = os.open(filename, os.O_RDONLY)
  try:
    word = fcntl.ioctl(fd, FAT_GETATTR_IOCTL, '    ')
  except:
    os.close(fd)
    raise
  os.close(fd)
  return ord(word[0])
 
def fat_setattr(filename, attr):
  fd = os.open(filename, os.O_RDONLY)
  word = '%s\0\0\0' % chr(attr)
  try:
    fcntl.ioctl(fd, FAT_SETATTR_IOCTL, word)
  except:
    os.close(fd)
    raise
  os.close(fd)
 
def fat_attrstr(attr):
  bit_to_name = lambda bit: bit &amp; attr and AttrBitName[bit] or '.'
  return ''.join(map(bit_to_name, AttrBits))
 
def fat_strattr(str):
  str_to_bin = lambda x: x[0] == x[1] and '1' or '0'
  bin = ''.join(map(str_to_bin, zip('ADVSHR', str)))
  return int(bin, 2)
 
def fat_dumpattr():
  for cur, dirs, files in os.walk('.'):
    items = dirs + files
    for item in items:
      try:
        filename = '%s/%s' % (cur, item)
        attr = fat_getattr(filename)
        str = fat_attrstr(attr)
        print '%s     %s' % (str, filename)
      except Exception, e:
        print e
 
def fat_loadattr():
  for line in sys.stdin.readlines():
    str = line[:6]
    file = line[6:].strip()
    if posixpath.exists(file):
      newattr = fat_strattr(str)
      oldattr = fat_getattr(file)
      if newattr == oldattr:
        print 'ignore same attribute %s[0x%02x]: %s' % (str, newattr, file)
      else:
        oldstr = fat_attrstr(oldattr)
        fat_setattr(file, newattr)
        print '-%s[0x%02X] +%s[0x%02X] %s' % (oldstr, oldattr, str, newattr, file)
    else:
      print 'ignore not existing file: %s' % file
 
def usage():
  print 'Usage: %s dir_or_file dump|load' % sys.argv[0]
  exit(1)
 
if len(sys.argv) != 3:
  usage()
 
target_dir = sys.argv[1]
old_dir = os.getcwd()
try:
  os.chdir(target_dir)
except:
  print 'Bad directory: %s' % target_dir
  usage()
 
 
op = sys.argv[2]
if op == 'dump':
  fat_dumpattr()
elif op == 'load':
  fat_loadattr()
else:
  print 'Bad option: %s' % op
  usage()
 
os.chdir(old_dir)
Categories: 开源软件 Tags: ,

Office 2007 Mime Types

March 9th, 2009 Comments off

Office 2007编辑的openxml格式的文件,后缀为.docx, pptx, xlsx,这些文件放到Apache2服务器上会认成zip格式,IE另存这类文件的时候会把扩展名都换成zip,非常不方便。

这是因为系统中没有记录openxml格式文件正确的Mime类型。在Debian和Ubuntu系统下,可以直接编辑/etc/mime.types文件,在最后增加以下内容:

application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
application/vnd.openxmlformats-officedocument.presentationml.template potx
application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx

编辑完成之后,重启Apache即可。

Categories: 开源软件 Tags: , ,

debmirror不能镜像当前的Debian Repo

February 27th, 2009 Comments off

不知道何时起,Debian的Repository就不包含Packages文件了,只有压缩版本的Packages.bz2和Packages.gz。同样,Sources.gz和Sources.bz2也完全替代了Sources。导致debmirror无法同步现在的Debian Repo。报的错误类似:“…/Packages failed md5sum check”。

修正方法如下:

  1. 按照下面的patch修改/usr/bin/debmirror
  2. 删除镜像目录下的临时文件目录 rm –r /path_to_local_mirro/.temp
--- debmirror   2009-02-27 04:10:57.000000000 +0800
+++ debmirror.orig      2009-02-27 04:12:45.000000000 +0800
@@ -690,14 +690,14 @@
 foreach my $dist (@dists) {
   foreach my $section (@sections) {
     foreach my $arch (@arches) {
-      #add_bytes("dists/$dist/$section/binary-$arch/Packages");
+      add_bytes("dists/$dist/$section/binary-$arch/Packages");
       add_bytes("dists/$dist/$section/binary-$arch/Packages.gz");
       add_bytes("dists/$dist/$section/binary-$arch/Packages.bz2");
       add_bytes("dists/$dist/$section/binary-$arch/Release");
       add_bytes("dists/$dist/$section/binary-$arch/Packages.diff/Index") unless                                                                               ($pdiff_mode eq "none");
     }
     if ($do_source) {
-      #add_bytes("dists/$dist/$section/source/Sources");
+      add_bytes("dists/$dist/$section/source/Sources");
       add_bytes("dists/$dist/$section/source/Sources.gz");
       add_bytes("dists/$dist/$section/source/Sources.bz2");
       add_bytes("dists/$dist/$section/source/Release");
@@ -706,13 +706,13 @@
   }
 }
 foreach (@extra_dirs) {
-  #add_bytes("$_/Packages");
+  add_bytes("$_/Packages");
   add_bytes("$_/Packages.gz");
   add_bytes("$_/Packages.bz2");
   add_bytes("$_/Release");
   add_bytes("$_/Packages.diff/Index");
   if ($do_source) {
-    #add_bytes("$_/Sources");
+    add_bytes("$_/Sources");
     add_bytes("$_/Sources.gz");
     add_bytes("$_/Sources.bz2");
     add_bytes("$_/Sources.diff/Index");
Categories: 开源软件 Tags: ,

Linux配置IMAP服务器

October 14th, 2008 Comments off

IMAP是移动办公中必备的功能, 上网的地方多了, 上网的设备多了, 用的操作系统多了, 什么时候都需要收邮件, 因此不能像POP3那样把邮件收到本地, 而是要放在"云"里.

学校的邮箱只支持POP3, 不支持IMAP. 如果有条件, 我们可以在Linux上自己架设IMAP服务器, 可以把邮件从POP3邮箱下载下来, 放到本地的IMAP服务器上. 通过自己架设的IMAP服务器, 可以实现邮件的移动办公.

1. 安装fetchmail

fetchmail可以把邮件从服务器上下载到本地, 首先安装

apt-get install fetchmail

然后编辑fetchmail的配置文件/etc/fetchmailrc. 下面的配置文件每隔10分钟就会将pop3.example.com服务器上remoteuser的邮件下载到本地localuser的邮箱中.

set postmaster "localuser"
set no bouncemail
set daemon 60

poll pop3.example.com proto pop3 interval 10
user 'remoteuser' there with password 'remotepass' is localuser here

最后, 确认/etc/default/fetchmail文件中有START_DAEMON=yes这一行. 重启系统之后, fetchmail服务就会启动.

2. 配置Maildir

用fetchmail下载下来的邮件将通过IMAP提供给邮件客户端访问. IMAP支持用户建立多个邮件文件夹, 因此本地用户推荐使用Maildir作为邮件存储方式, 而不是mbox.

运行dpkg-reconfigure exim4-config, 所有其他选项都选择默认. 在Delivery method for local mail选项事, 选择Maildir format in home directory. 此时, fetchmail收下的邮件将存储在用户$HOME/Maildir目录下.

3. 配置dovecot

dovecot提供了Linux下POP3和IMAP服务器的实现, 我们需要安装其IMAP服务器模块. 运行下面命令:

apt-get install dovecot-imapd

Debian默认的配置文件基本上都不需要修改. 但由于我们使用Maildir作为本地邮件存储, 因此需要修改mail_location参数为maildir:~/Maildir. 下面是一个完整的dovecot配置文件的例子(/etc/dovecot/dovecot.conf)

protocols: imap imaps
login_dir: /var/run/dovecot/login
login_executable: /usr/lib/dovecot/imap-login
mail_privileged_group: mail
mail_location: maildir:~/Maildir
auth default:
passdb:
driver: pam
userdb:
driver: passwd

重启系统之后, IMAP服务器就可以登录了. 用户可以配置邮件客户端, 将邮箱服务器设置为IMAP服务器, 地址为Linux服务器的地址, 用户名和密码就是该机器上localuser的用户名和密码.

4. 配置SpamAssassin(可选)

Linux上提供非常丰富的邮件处理功能, 如垃圾邮件识别, 病毒邮件检查等. SpamAssassin就是一款非常出色的垃圾邮件识别引擎.

在此之前, 用户先通过邮件客户端在IMAP帐号里建立一个专门存放垃圾邮件的文件夹, 例如叫Spam. 然后, 在Linux服务器上, 首先安装spamassassin这款软件.

apt-get install spamassassin

为了把spamassassin和Linux邮件系统上的其他组件联动起来, 实现自动的垃圾邮件过滤, 我们需要用到procmail. 首先在用户的$HOME目录下建立一个.procmailrc文件, 其中包括以下内容

PATH=/usr/bin:/bin
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/cur
LOGFILE=$HOME/procmail.log
 
# spam check
:0fw
| /usr/bin/spamassassin
 
# filter out spams
:0
* ^X-Spam-Flag: YES
* ^X-Spam-Level: \*\*\*\*\*
.Spam/cur

此时通过所有fetchmail收下的邮件, 都会自动经过spamassassin的过滤, 评分大于5分的邮件, 不会进入收件箱, 而是放在Spam文件夹下.

至此, Linux下的IMAP服务器已经配置完成了.

Debian下网卡对802.1Q VLAN的支持

October 14th, 2008 Comments off

现在的交换机大部分都支持802.1Q VLAN了, 通过VLAN可以将一个交换机上的不同端口分隔成隔离的链路, 也可以将多个交换机上的端口连接到同一个链路.

有时候, 我们可能希望一台机器同时连入多个VLAN, 最好是通过一块网卡. 也就是说, 让一个网络端口同时属于多个VLAN. 要实现这样的功能, 需要做两个方面的配置:

交换机配置

首先要把该主机对应的交换机端口设置为混合端口, 只有混合端口可以同时加入多个VLAN, 下面是Huawei交换机的配置片段:

interface Ethernet0/1
port link-type hybrid
port hybrid vlan 10 20 tagged
port hybrid pvid vlan 10

上述配置让交换机的1号端口成为混合端口, 并同时加入id号为10和20的VLAN, 主VLAN号是10.

Debian主机配置

首先需要在Debian上安装vlan配置工具.

apt-get install vlan

然后, 我们可以在Debian的网络配置文件中, 配置每个VLAN对应的网卡. 下面是/etc/network/interfaces文件的片段:

auto eth0.10
iface eth0.10 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.254

iface eth0.20 inet static
address 192.168.2.10 
netmask 255.255.255.0

上述配置文件配置的主机, 分别有两块虚拟网卡eth0.10, eth0.20, 对应VLAN 10和VLAN 20所在的网络.

除了配置文件之外, 管理员还可以通过vconfig命令, 增加或者删除VLAN.

Categories: 开源软件 Tags: , , ,

Linux下设置主机的FQDN

October 13th, 2008 Comments off

FQDN是Fully Qualified Domain Name的缩写, 含义是完整的域名. 例如, 一台机器主机名(hostname)是www, 域后缀(domain)是example.com, 那么该主机的FQDN应该是www.example.com.

题外话, 其实FQDN最后是以"."来结尾的, 但是大部分的应用和服务器都允许忽略最后这个点.

Linux允许用户通过hostname命令查看并设置主机名. 用户也可以通过hostname -f命令得到该主机的FQDN. 但是, 却没有直接设置FQDN的命令.

实际上, 设置Linux的FQDN可以通过两种方法实现.

第一种, /etc/hostname + /etc/hosts文件组合

首先在/etc/hostname文件中设置主机名, 假设是

www

然后在/etc/hosts文件中增加一行主机记录, 第一个字段是该主机的IP地址, 第二个字段是你希望设置的FQDN, 最后是刚刚设置的主机名, 如下

A.B.C.D www.example.com www

设置好之后, 通过hostname -F /etc/hostname更新主机名. 这时, 通过hostname -f看到的FQDN就应该是: www.example.com

第二种, /etc/hostname + /etc/resolv.conf组合

如果Linux不能在/etc/hosts文件中找到hostname对应的记录, 就会试图从resolv.conf文件中得到主机的域名后缀(domain name). 例如, 这样的/etc/resolv.conf文件

domain example.com
search example.com
nameserver W.X.Y.Z

根据配置文件中的domain后缀example.com, 加上主机名www, Linux会试图自动拼接成一个候选FQDN: www.example.com. 但这个候选FQDN还需要进一步验证.

Linux通过DNS服务器W.X.Y.Z解析候选FQDN, 如果解析失败, 生成FQDN过程就失败了. 如果解析成功, 则会返回www.example.com这个域名的正式名称. 也就是说, 如果在DNS服务器的记录中, www.example.com这个域名是指向server.example.com的CNAME记录的话, 而server.example.com才是A记录. 返回的FQDN就是server.example.com, 而不是www.example.com.

以上就是Linux下设置FQDN的方法.

Categories: 开源软件 Tags: , ,

grub2和GPT兼容问题

September 2nd, 2008 2 comments

说来挺丢脸的, Debian用了将近8年, 直到前一阵才提交了生平第一个Debian的bug, 关于grub2无法安装至使用GPT分区表硬盘的问题. Debian的package maintainer很热情的询问了关于这个bug的一些问题, 然后告诉我这个bug可能是grub本身的问题, 而不是Debian打包中出现的问题, 建议我报告到upstream maintainer那里去.

后来想想比较麻烦, 我就没再提交. 结果昨天又收到Debian包管理员Robert Millan的来信, 让我试试刚刚上传到experimental的新版本grub2(1.96+20080831-1), 说他认为我的bug已经在这个版本中解决了, 还把理由称述在bug report的注释里面了. 面对这么负责的管理员, 我除了感动, 还能说什么呢.

为了试用在experimental中的软件包, 需要首先修改/etc/apt/sources.list文件, 增加下面一行

deb http://debian.ustc.edu.cn/debian ../project/experimental main

然后安装experimental中的grub2

apt-get update
apt-get -t experimental install grub2

安装好之后, 使用下面的命令把grub2安装到GPT硬盘上, 发现已经可以成功安装了.

sudo grub-install '(hd0)'

Categories: 开源软件 Tags: , ,