Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, August 20, 2008

likely/unlikely macros in Linux Kernel

http://kerneltrap.org/node/4705

Ever wondered what the likely and unlikely macros in the linux kernel are ?
The macros are defined as :
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)

The __builtin_expect is a method that gcc (versions >= 2.96) offer for programmers to indicate branch prediction information to the compiler. The return value of __builtin_expect is the first argument (which could only be an integer) passed to it. 

To check it out how it could be beneficial, an excerpt from "info gcc" :
  if (__builtin_expect (x, 0))
  foo ();


  [This] would indicate that we do not expect to call `foo', since we
  expect `x' to be zero. 

Based on this information the compiler generates intelligent code, such that the most expected result is favored.

Let us consider it with a simple example function :

[kedar@ashwamedha ~]$ cat abc.c
int
testfun(int x)
{
  if(__builtin_expect(x, 0)) {
  ^^^--- We instruct the compiler, "else" block is more probable
  x = 5;
  x = x * x;
  } else {
  x = 6;
  }
  return x;
}
 
[kedar@ashwamedha ~]$ gcc -O2 -c abc.c
[kedar@ashwamedha ~]$ objdump -d abc.o
 
abc.o: file format elf32-i386
 
Disassembly of section .text:
 
00000000 :
  0: 55 push %ebp
  1: 89 e5 mov %esp,%ebp
  3: 8b 45 08 mov 0x8(%ebp),%eax
  6: 85 c0 test %eax,%eax
  8: 75 07 jne 11 <>
  ^^^ --- The compiler branches the "if" block and keeps "else" sequential
  a: b8 06 00 00 00 mov $0x6,%eax
  f: c9 leave
  10: c3 ret
  11: b8 19 00 00 00 mov $0x19,%eax
  16: eb f7 jmp f <>


And let us see what happens if we make the "if" block more likely.

[kedar@ashwamedha ~]$ cat abc.c
int
testfun(int x)
{
  if(__builtin_expect(x, 1)) {
  ^^^ --- We instruct the compiler, "if" block is more probable
  x = 5;
  x = x * x;
  } else {
  x = 6;
  }
  return x;
}
   
[kedar@ashwamedha ~]$ gcc -O2 -c abc.c
[kedar@ashwamedha ~]$ objdump -d abc.o
   
abc.o: file format elf32-i386
   
Disassembly of section .text:
   
00000000 :
  0: 55 push %ebp
  1: 89 e5 mov %esp,%ebp
  3: 8b 45 08 mov 0x8(%ebp),%eax
  6: 85 c0 test %eax,%eax
  8: 74 07 je 11 <>
  ^^^ --- The compiler branches the "else" block and keeps "if" sequential 
  a: b8 19 00 00 00 mov $0x19,%eax
  f: c9 leave
  10: c3 ret
  11: b8 06 00 00 00 mov $0x6,%eax
  16: eb f7 jmp f <>


...
Read More

Wednesday, July 23, 2008

screen goes black when use vesafb

When I use vesafb and set vga=xxx as kernel option to change the resolution, the screen goes blank at boot time. I know the system is still booting, nothing is wrong except the screen.

I finally found the solution. I appears the framebuffer module is not loaded with the kernel.

The walkthough is to edit /etc/modules.autoload.d/kernel-2.6   (in Gentoo, other distros may have different path) to add these two lines:

fbcon
vesafb

...
Read More

Saturday, April 19, 2008

wine强制全屏游戏在窗口模式下运行

wine explorer /desktop=1024x768 whatever.exe

...
Read More

Friday, April 4, 2008

HOWTO XDMCP in Gnome

XDMCP stands for "X Display Manager Control Protocol" and is a network protocol. It allows a way of running X-Terminal on your PC (or Mac) and uses the X Server to provide a client/server interface between display hardware (the mouse, keyboard, and video displays) and the desktop environment while also providing both the windowing infrastructure and a standardized application interface. The X-Terminal can be displayed with an individual window or multiple windows, based on your X window system's software capabilities and setup.


On your X-Server, you must tweak the configuration of your graphical login manager (displaymanager).

for GDM, you need to change the [xdmcp]-section in your configfile:
/etc/X11/gdm/custom.conf

[xdmcp]
Enable=true

Depending on how your gdm.conf/custom.conf is set up, you might also need to add or change the [greeter] section as shown below. Without this, you will not be able to XDMCP in to your server.

[greeter]
Browser=true


How to use XDMCP

on the remote machine you can either use Xnest or simply X:
$ X -ac -query servername :1
or
$ Xnest -ac -query servername :1

where servername is your servername or IP. :1 is the display number. (:0 should be your running X-Server)

To change screen resolution of Xnest, use "geometry" option:
$ Xnest -geometry=1280x800 -ac -query servername :1

...
Read More

Friday, March 28, 2008

Java程序和X程序无法调用scim输入的解决办法

最近发现Java程序无法输入中文按ctrl+space出scim

然后发型纯X程序像xterm一样症状而gtkqt程序没问题

上网了解到java程序和x程序一样用xim引擎进行输入而qt/gtk用scim因此觉得配置文件写错

检查下/etc/X11/xinit/xinitrc.d/xinputrc文件果然把XMODIFIERS小写@im=scim小写敏感现在正确内容如下

XMODIFIERS=@im=SCIM
XIM="scim"
XIM_PROGRAM="scim"
XIM_ARGS="-d"
GTK_IM_MODULE="scim"
QT_IM_MODULE="scim"

export XIM XIM_PROGRAM XMODIFIERS GTK_IM_MODULE QT_IM_MODULE

# start xim server
$XIM_PROGRAM $XIM_ARGS &

...
Read More

Thursday, March 20, 2008

HOWTO Editing Gnome/KDE Menus

Introducion

You know the menu that's shown if you start the kde-menu, gnome-menu, xfce-menu or something else. There's no real name for this kind of menu (it's also often called "root-menu"), but the menu is saved in a Freedesktop-Standard. 

Where are the files saved?

The menus are made out of a "Main file" (.menu file). The file is written in XML, and it contains a kind of links to the Applications (.desktop files). 

The Main file detailing system-wide default menu structure might be located in one of the followings directorys: 
/etc/xdg/menus/ 
User-specific menu edits: ~/.config/menus/ 
If you have not found your file yet, search for it: find / -iname *.menu 

System-wide Menu entries (.desktop files) are stored in many places, for example: 
/usr/share/applications/ 
/usr/share/applink/
Gnome applications:
/usr/share/gnome/apps/
KDE applications: 
/usr/kde/3.5/share/applications/
User-specific applications: 
~/.local/share/applications/

Or search for the files: find / -iname *.desktop

...
Read More

Monday, March 17, 2008

HowTo: Mount Bin/Cue files in Linux

* Method 1: Use CDEmu.
cdemu 0 pro.cue
mount -t iso9660 /dev/cdemu/0 /mnt/temp

* Method 2: Convert to ISO.
Convert BIN/CUE to ISO:
bchunk -v acrobat6pro.bin pro.cue pro

* Just mount the ISO by executing as root.
mount -o loop,ro -t iso9660 .iso
mount -o loop pro01.iso /mnt/temp

* Method 3: Use AcetoneISO2.

...
Read More

Saturday, March 15, 2008

【转】JDK6中文乱码完美解决之雅黑版

JDK6在LINUX环境下不支持中文,以下是解决办法。

实验环境:Ubuntu7.04,JDK6
路径说明:1、字体文件路径/usr/share/fonts/yahei/msyh.ttf
2、JAVA_HOME=/usr/lib/jvm/jdk
(请根据你的实际路径修改变命令内容)

解决AWT外的乱码:
1、cd /usr/lib/jvm/jdk/jre/lib/fonts
(进入jre的fonts文件夹)
2、sudo mkdir fallback
(创建文件夹fallback,文件名必须是"fallback",这是设置文件中指定的)
3、cd fallback
(进入fallback文件夹)
4、sudo ln -s /usr/share/fonts/yahei/msyh.ttf
(建立msyh.ttf字体文件的软连接)
5、sudo mkfontscale
(建立fonts.scale文件)
6、sudo mkfontdir
(在fonts.scale的基础上建立fonts.dir文件)

如果使用中不涉及AWT中文显示,问题已解决,针对AWT的乱码问题,必须实施以下步骤:

1、cd /usr/lib/jvm/jdk/jre/lib/fonts
(进入jre的fonts文件夹)
2、sudo cat ./fallback/fonts.dir >> fonts.dir
(把/fallback/fonts.dir的内容添加到fonts.dir文件的结尾,可以手动复制,目的是把雅黑字体的相关内容添加进jre的fonts.dir里)
3、cd ..
(返回上一级目录,即/usr/lib/jvm/jdk/lib)
4、sudo mkdir fontconfigs
(建立fontconfigs文件夹,fontconfigs可以随便命名)
5、sudo mv fontconfig.* ./fontconfigs
(把lib文件夹内的fontconfig开头的文件剪切到fontconfigs文件夹下,因为这些设置文件是应用于不同系统的,按一定顺序查找,如果不把它们移走,不能保证执行我们将要建立的文件fontconfig.properties)
6、sudo gedit fontconfig.properties
(创建并打开文件fontconfig.properties,文件名必须是默认查找顺序列表中的一个,fontconfig.properties就是其中之一)
7、复制以下内容到fontconfig.properties,并保存:


# @(#)linux.fontconfig.Ubuntu.7.04.properties 1.2 07/10/02
#
# Copyright 2007 ganjinghong, Inc. All rights reserved.
#

# Version

version=1

# Component Font Mappings
serif.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
serif.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
serif.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
serif.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0

serif.plain.latin-1=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.bold.latin-1=-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1
serif.italic.latin-1=-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1
serif.bolditalic.latin-1=-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1
sansserif.plain.latin-1=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bold.latin-1=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.italic.latin-1=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.latin-1=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
monospaced.plain.latin-1=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bold.latin-1=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.italic.latin-1=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.latin-1=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialog.plain.latin-1=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bold.latin-1=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.italic.latin-1=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.latin-1=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialoginput.plain.latin-1=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.latin-1=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.latin-1=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.latin-1=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1


# Search Sequences

sequence.allfonts=latin-1,chinese-cn

# Exclusion Ranges

# Font File Names

8、无需重启,问题已解决。

其他字体设置方法:
把fontconfig.properties文件中的microsoft-microsoft yahei替换为你所用字体的名称。
TIPS:
1、名称获取方法:可以在字体文件同级目录下执行:sudo mkfontscale,然后打开生成的fonts.scale,里面就有相关的名称。
2、必须把你所用中文字体的fonts.scale的相关内容添加到/lib/fonts/fonts.dir

...
Read More

Sunday, June 10, 2007

Gentoo下man c++标准库的方法

以前用ubuntu的时候装一个libstdc++-doc包就可以man std::iostream等标准库函数,用gentoo后不知道怎样装。现在发现,gentoo下大部分包的文档是用 USE=doc 标记的,于是在 /etc/portage/package.use 中添加
sys-devel/gcc doc
再重新emerge gcc
于是就有文档了。

...
Read More

eva版本号过低无法登陆QQ的解决办法

该死的腾讯总是喜欢封杀第三方QQ,不过他只是靠拒绝低版本号QQ登陆来实现的。
因为第三方QQ更新得比较慢(eva,luma),所以经常会出现登陆不上的情况,这时只好自己动手,丰衣足食了。

以eva为例:
emerge -f eva //下载eva的源码包
将 /usr/portage/distfiles/eva-0.4.1.tar.bz2 包解出来
修改 eva/src/libeva/evadefines.h 文件中的 QQ_CLIENT_VERSION 常量
改为 const int QQ_CLIENT_VERSION = 0x0E1B; 这个版本号可以想办法找到最新的(比如看看珊瑚虫的设置)
然后把修改过的源码重新打包,放回 /usr/portage/distfiles/ 目录
然后
cd /usr/portage/local/layman/gentoo-china/net-im/eva
ebuild eva-0.4.1.ebuild digest
否则emerge时会重新下载,做的修改就白费了。

然后就可以
emerge eva
安装修改过的eva了。装完了以后成功登陆QQ。

...
Read More

Wednesday, June 6, 2007

Opera字体终结解决方案

cd ~/.opera/styles/user/
touch user.css
vi ~/.opera/styles/user/user.css

加入如下内容:
html,body,*{
font-family:”simsun”!important;
}

注意:simsun这个地方的字体可以随便换成喜欢的。

打开opera浏览器,然后view—->style—–>manage modes—->display,然后在my style sheet那一栏选择刚才编辑的user.css文件即可。

...
Read More

Tuesday, June 5, 2007

终于装上显卡驱动了

在gentoo下装ATI的显卡驱动真不容易,前段时间xorg-server更新以后一直和ati-drivers冲突。这两天ati把linux驱动更新到了8.37.6,终于解决了这个冲突,我也顺利装上了驱动,进X终于是宽屏的了,顿时眼前一亮,不用再忍受拉长的桌面了。

安装方法参照gentoo wiki
http://gentoo-wiki.com/Ati

...
Read More

Monday, May 28, 2007

改用Gentoo了

好久没写东西了,这段时间太忙了,但这段时间挺多东西值得记一记的,就慢慢来吧。

现在我开始用gentoo了,也算是早有预谋吧,但主要原因是我把ubuntu搞坏了。
前一阵子在windows下格了一个分区,重启以后居然grub坏了,于是用ubuntu的livecd引导,打算用grub-install恢复。因为不清楚grub-install的参数,就随便试了试,没想到它的杀伤力还挺大,直接把ubuntu的\分区搞坏了。我真是痛心疾首啊,我的ubuntu好不容易才配得让我满意的。现在也没办法了,只好重装,正好我也久闻gentoo大名,最近又出了gentoo 2007.0,于是把心一横,装起gentoo来了。

不得不说gentoo真是太复杂了,光是安装就花了我两个晚上。而且我还不是stage 3安装的,是直接用livecd的installer安装的(也就是非编译安装,直接拷二进制文件)。我直到装完了以后,才认识到gentoo的正统安装方式就是stage 3,基于网络和命令行的安装。这个图形的安装程序真的是非常非常烂(我就没见过这么烂的),不过这也不能怪他,毕竟gentoo的老用户都对这种图形安装没有需求。另外这张livecd也是一张budy cd,费了好大力气才把gentoo装上,一如所料的进不了X,把驱动改成vesa后进去一看,真叫一个丑,其实这就是gnome的标准界面,这时有点怀念ubuntu了,人家确实是花了工夫取悦用户的眼球的,而以gentoo的风格,肯定是不会管这种事情的。

gentoo最大的特点就是它几乎所有的软件都是用源码编译安装的(不开源的当然除外),同时它又有一套相当好的包管理系统——portage,相当于ubuntu的apt。这套系统不但给用户提供了最大的可定制性,而且还帮用户解决了恼人的依赖关系(想想看,源码安装的依赖关系比二进制包的依赖关系更复杂),真的丝毫不比apt逊色。用linux的总是免不了要安装源码,我以前在ubuntu下也装过几个,感觉太繁了,因为ubuntu没有源码管理的东西,安装的时候少了哪个库只能自己从网上找,装这个库的时候可能又少了那个库,如果同时用apt装了一个包,又用源码装同一个包,可能还会出些问题。反正在非源码安装的发行版下安装源码总是不太方便了。gentoo这样完全源码安装的很合我的胃口,虽然编译的时间比较久,但源码安装的好处还是很多的。比如说我编译了一把内核,现在启动速度明显快了很多。

目前还有好些问题没有解决,主要是一些比较底层的问题。比如显卡驱动装不上(直接导致支持不了宽屏),laptop-mode启动不了,声卡驱动没装,字体也不好看。这些问题以后再慢慢搞,现在至少可以在控制台下写程序了。

...
Read More

Friday, May 4, 2007

关于tab路径补全失效

ubuntu 7.04
路径中带空格的,用sudo就没法tab补全下一级。
比如 sudo cd /media/hda7/Program\ Files/< tab > 无效
但不用sudo则没问题。

解决办法:
把 /etc/bash_completion 中 _command 函数里的

# split current command line tokens into array
COMP_WORDS=( $cline )

改成
# split current command line tokens into array
for (( i=1 ; i<=COMP_CWORD ; i++)); do
    COMP_WORDS[i]=${COMP_WORDS[i+1]}
done

...
Read More

Wednesday, May 2, 2007

原来Ubuntu的源里就有MS的字体

以前我还专门从windows下拷过几个英文字体到ubuntu,没想到ubuntu的源里就有。真想不明白为什么会有这种事,难道这些字体没有版权吗?不管了,反正我是中国人。
这个包叫msttcorefonts,顾名思义,都是ms的truytype英文字体,包括times new roman,courier new等等。

sudo apt-get install msttcorefonts

这个包只有400K好像,但实际上它是装完了再从sourceforge上wget字体文件的,还好我有直通车。

字体装好以后马上就能用了,我试了一下,效果都不错,但AA字体我都不喜欢,因为看起来发虚,容易眼疲劳,因此桌面的英文字体我还是用文泉驿的点阵字,但装了新字体毕竟就多了新的选择,说不准哪天会用上。

而终端下用的等宽字体,以前我一直没找到很满意的,这回有了Courier New,真是亲切呀,这可是经典的编程字体呀。我试了一下,Courier New不如Courier 10 Pitch好看,而Bitstream Vera Sans Mono也挺好看的,这两者挺不好决择的。

对比一下。
这是Bitstream Vera Sans Mono


这是Courier 10 Pitch


最后还是决定用Courier 10 Pitch啦,一是因为它太经典啦,二是因为它看起来一点也不发虚(虽然它也是AA字体),可能是因为字体比较粗的缘故吧。而Sans Mono放桌面上看还不错,但是在终端这种高尚的地方(在终端下coding更是一件神圣的事),不免显得太俗气,难登大雅之堂。

另外就是觉得装完这个包以后各种AA字体都不怎么发虚了,不知道真是这个包的作用,还是心理作用,也可能是看久了习惯了。

...
Read More

Tuesday, May 1, 2007

关于Ubuntu的待机问题

Ubuntu的待机问题好像是个普遍问题,台式机笔记本都无法幸免,好像和显卡有关。而且这方面的问题多种多样,我碰到的有下面两个,这两个应该也是待机问题中最常见的两种了。
一是无法待机(suspend),二是待机了无法唤醒(resume)。

1. 无法suspend的解决办法
这多是由于没有开启laptop_mode造成的。关于如何开启laptop_mode,参见
启用laptop-mode的方法
当然,在这之前最好检查一下acpi是否正确配置。确保 /etc/default/acpi-support 中有下面几条
ACPI_SLEEP=true
ACPI_HIBERNATE=true
ACPI_SLEEP_MODE=mem
我没开laptop_mode时无法待机,开了以后可以待了,但是待完了起不来。解决方法如下。

2. 无法resume的解决办法
我的症状是唤醒的时候屏幕黑屏,按什么键都没用(包括power),但据硬盘灯推测此时系统已经resume了,只是屏幕无显示。这显然跟显卡方面有关,在网上找了一篇解决这个的,主要要干三件事:

  1. In /etc/acpi/sleep.sh, as second line, add the line sudo chvt 1. This forces a switch to the text console before standby.
  2. Likewise, in add to the very end of the file /etc/acpi/resume.sh the line sudo chvt 7.
  3. Finally, the perhaps most important change goes into /etc/default/acpi-support. Change the line POST_VIDEO=true to read POST_VIDEO=. This was the point when it started working on my system.

经我尝试,第3条才是关键,前两条都在我这没必要做。 我把 /etc/default/acpi-support 的 POST_VIDEO=true 的true去掉就可以正常resume了。

附:一些背景知识。
来源:http://kw-gift.com/blog/index.php?entry=entry060928-105807
linux的ACPI定义了不同的睡眠状态,常用的有
S1:STOPGRANT
供给停止,CPU Halts,由CPU停止而引起的相关组件一起停止运作,相当于WINDOWS的Standby[待机]
S2:类似于S3,系统保留状态,当前并没起用此状态。
S3:Suspend to RAM
挂起到内存,相当于WINDOWS的Sleep[睡眠],注S3当前不支持 Kernel 2.4.x。
S4:Suspend to Disk
挂起到硬盘,相当于WINDOWS的Hibernate[休眠],注S3当前不支持 Kernel 2.4.x。
S5:Soft Off
关闭系统,相当于WINDOWS的Shut Down[关机]
关于SlEEP状态 的更多祥情请参况:http://acpi.sourceforge.net/documentation/sleep.html

怎样查看自已的laptop支持那种睡眠状态?
方法1:cat /proc/acpi/sleep(kernel 2.4系列适用)
在我的laptop返回如下结果 :S0 S3 S4 S5
方法2:cat /sys/power/state(kernel 2.4系列适用)
在我的laptop返回如下结果:mem disk
说明我的laptop绝对支持支持S3,S4状态

...
Read More

Monday, April 30, 2007

启用laptop-mode的方法

确保laptop-mode已经安装:
sudo apt-get install laptop-mode-tools

查看laptop-mode是否启动:
cat /proc/sys/vm/laptop_mode
如果结果为零(0)则说明系统并没进入laptop_mode模式,结果非零则为laptop_mode模式。

启用laptop_mode模式:
sudo vi /etc/default/acpi-support
更改ENABLE_LAPTOP_MODE=true,如果你是ATI的RADEON系统显卡,可同时更改RADEON_LIGHT=true,如果你的laptop支持ACPI挂起,请启用ACPI_SLEEP=true设置。

默认情况下UBUNTU会在你切换电源到电池供电时启动laptop_mode,如果你现在就想启动laptop_mode模式,请
sudo laptop_mode start

如果你想停用laptop_mode模式:
sudo laptop_mode stop

重启laptop_mode模式:
sudo laptop_mode restart

修改laptop_mode的配置文件:
sudo vi /etc/laptop-mode/laptop-mode.conf

如果发现laptop_mode不随系统启动,用sysv-rc-conf修改系统服务,把laptop_mode勾上。(*这点很重要)

...
Read More

Sunday, April 29, 2007

关于QT程序的界面

一直觉得QT程序的界面非常难看,比如qtunet,qterm,用qtconfig也设不好。但最近装eva,附带装了一堆kde的库,装完了以后qtunet居然变好看了,惊讶之余再打开qterm看看,也变好看了。于是推断是这几个库之一(也可能不只一个)的结果。先记下这些库,以后再研究。
===================================
下列【新】软件包将被安装:
eva kdelibs-data kdelibs4c2a libavahi-qt3-1 liblua50 liblualib50
libopenexr2c2a libpcre3
===================================
估计是那个名字带qt3的比较有可能。先不管了。贴张图。




另外说起eva,上次装的eva老是容易崩掉,而且好友没有被分组。这回装的居然运行了很久都没有挂,而且能正确下载好友分组了。可能是应为上回装的时候ubuntu7.04还是beta不稳定把。再观察一段时间,要是eva好使的话就基本上不用回windows了。

...
Read More

Ubuntu连教育网直通车的方法

首先是在/etc/ppp/peers下建立一个连接脚本,比如叫ztc,内容如下:
-----------/etc/ppp/peers/ztc-------------------
pty "pptp lns_bj.vip.edu.cn --nolaunchpppd"
name
remotename ztc
file /etc/ppp/options.pptp
ipparam ztc
----------------------------------------------
第一行是说把与直通车之间的pptp连接作为pppd的子进程(或者伪终端),这样,当pppd在后台运行时,应用程序产生的IP数据包先被pppd用ppp协议封装,注意这里ip源地址是local peer地址(58.207.XXX.XXX),然后该包被子进程pptp用pptp协议封装成TCP数据包后用eth0发送出去,这里外层包的源地址即eth0的ip地址(59.66.132.XXX),目的地址为直通车pptp服务器的地址(lns_bj.vip.edu.cn),包到达服务器后,服务器用他的pppt进程抽取出内层IP数据包,然后根据目的地址进行转发.逆向过程与此类似.

第二行是你直通车用户名,第三行是该ppp连接的名称,可随意指定.第四行运行自带的用于vpn的默认配置脚本,最后一行是将该ztc脚本作为参数传给/etc/ppp/ip-up脚本.ip-up在于直通车成功建立连接后运行,相应地,断开时会运行ip-down.

接下来修改 /etc/ppp/options.pptp,将mppe required,stateless注释掉就可以了,直通车不对ppp包加密.我的经验是尽量多注释,以保留最少的条目为原则.现在我的options.pptp里只有lock,noauth,nobsdcomp,nodeflate这几条.

然后修改或新建/etc/ppp/chap-secrets存放你的密码:
----------------------------------------------
# Secrets for authentication using CHAP
# client server secret IP addresses
  ztc   *
----------------------------------------------
这里server名必须与ztc脚本中的remotename相同.到这里vpn就配置好了,下面用pon连接:
>sudo pon ztc debug dump logfd 2 nodetach
ztc参数指定了配置脚本,debug用于观察协商过程,logfd 2使debug信息输出到控制台,nodetach让pppd像tunet那样在前台运行. dump输出你在ztc和options.pptp中的具体配置内容,回车后应会有如下输出:
----------------------------------------------
pppd options in effect:
debug # (from command line)
nodetach # (from command line)
logfd 2 # (from command line)
dump # (from command line)
noauth # (from /etc/ppp/options.pptp)
name *** # (from /etc/ppp/peers/ztc)
remotename ztc # (from /etc/ppp/peers/ztc)
                 # (from /etc/ppp/options.pptp)
                 # (from /etc/ppp/options.pptp)
pty pptp lns_bj.vip.edu.cn --nolaunchpppd # (from /etc/ppp/peers/ztc)
crtscts # (from /etc/ppp/options)
       # (from /etc/ppp/options)
asyncmap 0 # (from /etc/ppp/options)
lcp-echo-failure 4 # (from /etc/ppp/options)
lcp-echo-interval 30 # (from /etc/ppp/options)
hide-password # (from /etc/ppp/options)
ipparam ztc# (from /etc/ppp/peers/ztc)
proxyarp # (from /etc/ppp/options)
nobsdcomp # (from /etc/ppp/options.pptp)
nodeflate # (from /etc/ppp/options.pptp)
noipx # (from /etc/ppp/options)
using channel 9
Using interface ppp0
Connect: ppp0 <--> /dev/pts/4
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfReq id=0x1 ]
sent [LCP ConfAck id=0x1 ]
rcvd [LCP ConfAck id=0x1 ]
sent [LCP EchoReq id=0x0 magic=0x6400380b]
rcvd [CHAP Challenge id=0xf5 , name = "pptpd"]
sent [CHAP Response id=0xf5 <4223f091a3casdewrg810abd1e3b3b5e3f94b7cc1a0e538f357ee1fa45b866a630a04e87>,name = ***]
rcvd [LCP EchoRep id=0x0 magic=0x7fa9ac2c]
rcvd [CHAP Success id=0xf5 "S=0E7BFEBE3C66665792219C0ABF01469E16B808F3"]
CHAP authentication succeeded
sent [IPCP ConfReq id=0x1 ]
rcvd [CCP ConfReq id=0x1 ]
sent [CCP ConfReq id=0x1]
sent [CCP ConfRej id=0x1 ]
rcvd [IPCP ConfReq id=0x1 ]
sent [IPCP ConfAck id=0x1 ]
rcvd [IPCP ConfRej id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [CCP ConfAck id=0x1]
rcvd [CCP ConfReq id=0x2]
sent [CCP ConfAck id=0x2]
rcvd [IPCP ConfNak id=0x2 ]
sent [IPCP ConfReq id=0x3 ]
rcvd [IPCP ConfAck id=0x3 ]
Cannot determine ethernet address for proxy ARP
local IP address 58.207.136.150
remote IP address 58.207.255.18
Script /etc/ppp/ip-up started (pid 3116)
Script /etc/ppp/ip-up finished (pid 3116), status = 0x0
----------------------------------------------
local IP和remote IP在每次连接时可能会不一样.
此时查看接口会发现多了一个ppp0:
----------------------------------------------
>ifconfig
eth0 Link encap:Ethernet HWaddr 00:0A:E4:C0:C4:F4
inet addr:59.66.132.118 Bcast:59.66.255.255 Mask:255.255.0.0
inet6 addr: fe80::20a:e4ff:fec0:c4f4/64 Scope:Link
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:50735 errors:1 dropped:0 overruns:0 frame:0
TX packets:5897 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5212480 (4.9 MiB) TX bytes:694373 (678.0 KiB)
Interrupt:169
                         
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:187 errors:0 dropped:0 overruns:0 frame:0
TX packets:187 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:18740 (18.3 KiB) TX bytes:18740 (18.3 KiB)
                         
ppp0 Link encap:Point-to-Point Protocol
inet addr:58.207.184.166 P-t-P:58.207.254.18 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1178 (1.1 KiB) TX bytes:66 (66.0 b)
----------------------------------------------
到这里就已成功建立连接,但别急着连国外网.由于路由表的default路由仍是59.66.132.1,数据包并不走ppp0这条路.下面修改路由表.此时路由表大概是这样:
>route -e
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
58.207.255.18 * 255.255.255.255 UH 0 0 0 ppp0
59.66.0.0 * 255.255.0.0 U 0 0 0 eth0
default * 0.0.0.0 U 0 0 0 eth0
----------------------------------------------                        
我们要改default路由为ppp0.由于ppp0是虚接口,所以必须保证从你的机器到服务器的网路畅通,因此改变默认路由前一定要维护tunet服务器(166.111.8.10)和pptp服务器的原路由.
>sudo route add -net 59.66.0.0 netmask 255.255.0.0 dev eth0
>sudo route add -net 166.111.0.0 netmask 255.255.0.0 dev eth0
>sudo route add -net 58.207.0.0 netmask 255.255.0.0 dev eth0
>sudo route add default dev ppp0
----------------------------------------------
现在路由表变为这样
>route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
58.207.255.18 * 255.255.255.255 UH 0 0 0 ppp0
166.111.0.0 * 255.255.0.0 U 0 0 0 eth0
59.66.0.0 * 255.255.0.0 U 0 0 0 eth0
58.207.0.0 * 255.255.0.0 U 0 0 0 eth0
default * 0.0.0.0 U 0 0 0 eth0
default * 0.0.0.0 U 0 0 0 ppp0
-----------------------------------------------------------
由于新加入的default起作用,现在除了59.66.*.*和166.111.*.*的数据包都会走ppp0了.断开连接Ctrl-c就行了,当然还得把路由表恢复原状,为省事,可将路由设置和恢复命令分别写到ip-up和ip-down中.这样就不必每次连接都手动配置路由表了,这是我/etc/ppp/ip-up末尾几句:
-------------------------------------------------------------
#add for ztc
route add -net 59.66.0.0 netmask 255.255.0.0 dev eth0
route add -net 166.111.0.0 netmask 255.255.0.0 dev eth0
route add -net 58.207.0.0 netmask 255.255.0.0 dev eth0
route add default dev ${PPP_IFACE}

-------------------------------------------------------------
/etc/ppp/ip-down 末尾的几句:
#add for ztc
route del default ${PPP_IFACE}
route del -net 59.66.0.0 netmask 255.255.0.0 eth0
route del -net 166.111.0.0 netmask 255.255.0.0 eth0
route del -net 58.207.0.0 netmask 255.255.0.0 eth0

-------------------------------------------------------------

最后可以写将sudo pon vip debug dump logfd 2 nodetach写成shell script,就可以像tunet那样用了.如, ztc.sh里写一行
sudo pon vip debug dump logfd 2 nodetach
再改权限
>sudo chmod a+x ztc.sh
>sudo chown root:root ztc.sh
>sudo chmod +s ztc.sh
以后运行ztc.sh就连上直通车了.

...
Read More

Wednesday, April 25, 2007

关于ubuntu无法在启动时mount ntfs-3g的问题

以前在 /etc/fstab 中把ntfs分区改为用ntfs-3g以后不生效,boot时提示不认得ntfs-3g模块,现在终于解决这个问题了。

首先ntfs-3g依赖于fuse模块,一般来说现在的内核都编译了fuse-module。可作如下检查:
modprobe -l fuse
正常情况应返回:/lib/modules/2.6.20-15-generic/kernel/fs/fuse/fuse.ko
否则就要想办法装fuse模块了。

然后,写 fstab 也是有讲究的。以前boot时无法自动 mount ntfs-3g,但启动完了以后可以手动mount或 mount -a。现在发现原因是这样:我在 fstab 中把 ntfs-3g 的分区写在 /usr 分区之前,于是启动时还没 ntfs-3g 需要的模块,于是 mount 不成功。 现在把 ntfs-3g 的分区写在最后,就可以 mount 成功了。 现在的 /etc/fstab 内容如下:
# /etc/fstab: static file system information.
#
# -- This file has been automaticly generated by ntfs-config --
#
#

proc /proc proc defaults 0 0
# Entry for /dev/sda10 :
UUID=4bb3f927-e5cd-4218-b6c0-068fbb5f14f3 / xfs defaults 0 1
# Entry for /dev/sda12 :
UUID=93015402-af07-4cc9-894c-924f8f644f37 /boot ext3 defaults 0 2
# Entry for /dev/sda11 :
UUID=bea69ead-ff4d-410b-b0aa-71f873c72695 /usr xfs defaults 0 2
# Entry for /dev/sda9 :
UUID=c79799e4-3a11-40d1-8bd0-28674be553a7 none swap sw 0 0
# Entry for /dev/sda1 :
UUID=320D-180E /media/hda1 vfat defaults,codepage=936,umask=007,gid=46 0 1
# Entry for /dev/sda5 :
UUID=12E42A32D9985B49 /media/hda5 ntfs-3g defaults,locale=zh_CN.GBK 0 1
# Entry for /dev/sda6 :
UUID=4B90A8CB66616D24 /media/hda6 ntfs-3g defaults,locale=zh_CN.GBK 0 1
# Entry for /dev/sda7 :
UUID=AA057C6FE66428E1 /media/hda7 ntfs-3g defaults,locale=zh_CN.GBK 0 1
# Entry for /dev/sda8 :
UUID=01EB842D27CE8190 /media/hda8 ntfs-3g defaults,locale=zh_CN.GBK 0 1
/dev/hdb /media/cdrom0 udf,iso9660 user,noauto 0 0

...
Read More
 
/* google analytics */