healing centos gnome display

May 3rd, 2009

刚刚把昨天由于修改显卡驱动而导致 gnome 无法进入的问题解决了.

我之所以刚放心大胆的修改 Display settings 就是因为之前发现在 gnome 中修改后系统会自动备份一个 xorg.conf.backup 文件, 这次我也成功的还原了改文件, 但仍然无法启动 startx , 之前在网上找到的所有文章都是说什么备份和恢复 xorg.conf , 诸如此类的方法在此时都失效了.

最后才在一个bbs上看到有人把 xorg.conf 删除后显示恢复的事情, 经过试验果然是最正确最有效的方法.

删除 xorg.conf 后不用重启, 直接使用 startx 或 init 5 就可以正常进入 gnome 了, 而且此时并不会在 /etc/X11 下重新生成 xorg.conf 文件, 就算重启之后也不会再生成该文件.

如果想重新生成 xorg.conf 则可以通过任意修改  Display settings 并保持后实现. 但需要注意的是, 在我这里设置分辨率后只会使没有 xorg.conf 文件时得到的正常屏幕高度变得超高, 而且分辨率永远是最大值1920×1200 而无法设置为最适合的 1440×900 了.

故我为了 gnome 屏幕高度能正常显示, 最后又一次把 xorg.conf 文件删除了.

马上在 centos 上用 firefox 浏览了我的博客, 但可惜由于我默认使用的 language English 导致系统中没有中文字体, 所以只能看到一片方块乱码.

使用菜单 Applications – Add/Remove Software (必须联网后才能打开此功能) 中的 Languages – Chinese Support 就可以从网上下载安装中文字体了, 发现还自动安装了 scim 的拼音和五笔输入法, 还有各种繁体输入法和 big5 字体, 以及没有自带词典 需自己下载的翻译软件 StarDict .输入法设置和在windows中差不多, 没啥难度, 我就留下了 Smart Pinyin .

网上所说的切换 KDE 方法有两种, switch kde 和修改什么 rc.d 中的文件, 这些我都反复试验过, 最起码我能确定这些方法在 CentOS v5.3 中是无效的.

我现在找到了方法:

1. 用 init 5 启动到登陆界面, 如果用 startx 则会跳过登录界面直接进入 gnome;

2. 在登录面板下面点击 Session,  就会弹出对话框 Sessions, 看到其中选项( Last session, Default System Session, GNOME, KDE, Failsafe Terminal )我就明白了.

3. 选择 KDE, 并输入密码后就会问你是否要设置成默认的会话.

进入KDE后, 发觉界面效果比GNOME要酷一些, 但就和windows有些接近了, 如果要显示出和windows差别还是用GNOME比较好.

KDE和GNOME应该界面不同, 用的配置文件都是一样的, 因为我发现使用Firefox记录和输入法设置都一样, 就连 Display settings’s bug 都是的.

Study & Work Diary: CentOS 5.3 Setup

May 1st, 2009

Testing Center ODU的负责人 chen zheng 想为其部门建立一个文件信息平台, 之前出于价格考虑我建议他们购买了山特(SANTAK) MT500 的UPS 和强氧( Oxygen ) TS550 服务器, 其配置如下:

CPU: Intel Xeon X335
Memory: 2G ECC DRRII
Chip: Intel 3200
Power: Greatwall 550w
Raid: 0, 1, 5, 10
Storage: SATA 250G * 2(默认配置只有一块硬盘, 另多买了一块250G希捷SATA)

很少有机会使用linux, 这次正好拿来练手. 把从官方网站 centos.org 下载的 i386-dvd.iso 用 ONES 通过笔记本刻录光驱上直接burn在找同事要的dvdr上, 然后用油性记号笔写下” CentOS V5.3 i386 09.04.30″.

第一步当然是把两块做 Raid 1, 这没啥好说的, 几乎每种机型里面的raid界面都不一样, 反正是先上线,然后分组,然后设定为raid 1,最后选择 Accept .

使用一个外接的 Hualu 蓝光光驱来安装系统, 安装过程中意外的发现了一个一个选项 ‘Encrypt System” , 在百度上没看到国内的任何有关说明, 在Google上找到一个 beginlinux.com (令人气愤, 这一个学习linxu的网站也被GFW屏蔽了, 非要麻烦我用代理才能访问)上的一个详细说明, http://beginlinux.com/blog/2009/04/centos-53-encrypted-block-devices/ 详细内容如下:

CentOS 5.3 now comes with disk encryption. When you install the operating system you have the option to encrypt block devices, partitions that you create.  Block device encryption requires a passphrase or key as authentication in order to access the data on that partition.  The advantage of block encryption is that it will enforce the encryption even if the disk is removed from the operating system.  The application is not only valuable for laptops but provides security for disks on servers that may be moved or thrown away.  Having just recently wiped and “hammered” old server disks to protect the company data, it would be nice to know that there is an additional layer of security for that data.

The encryption is done using dm-crypt/LUKS. LUKS or Linux Unified Key Setup, provides the disk format for the data as well as it provides the passphrase/key management policy.  LUKS uses the dm-crypt module which is a kernel mapper subsystem and manages the encryption and decryption for the block device.  This is the same subsystem that is used by LVM so that it has proven itself to be stable. One of the  advantages of LUKS is that the underlying contents of the block device are arbitrary so that you can encrypt your SWAP space. You can encrypt ext3, LVM physical volumes, and RAID arrays with LUKS. A disadvantage of LUKS is that it is not a good choice for file level encryption.

If you choose to encrypt a block device you must be prepared as an administrator that you will need to provide the passphrase when the system boots for access to the block device.  If you wanted to provide better security for a block device you can fill the block device with random data:

dd if=/dev/urandom of=/dev/sdb3

Be sure to choose the correct location for your disk as it will probably not be /dev/sda3.  And of course anytime you fill a disk with urandom all information on that partition will be lost.

You can create encrypted block devices after installation.  Create a partition.

# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         127     1020096   83  Linux
/dev/sdb2             128         254     1020127+  83  Linux

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (255-783, default 255):
Using default value 255
Last cylinder or +size or +sizeM or +sizeK (255-783, default 783): +500M

Command (m for help): p

Disk /dev/sdb: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         127     1020096   83  Linux
/dev/sdb2             128         254     1020127+  83  Linux
/dev/sdb3             255         316      498015   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Run partprobe so the system knows the partition exists.

# partprobe

Format the partition so it is available for the encryption.

# cryptsetup luksFormat /dev/sdb3

WARNING!
========
This will overwrite data on /dev/sdb3 irrevocably.

Are you sure? (Type uppercase yes):
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.

Verify.

# cryptsetup isLuks /dev/sdb3 && echo Sucess
Sucess

Get information about the LUKS partition.

# cryptsetup luksDump /dev/sdb3
LUKS header information for /dev/sdb3

Version:        1
Cipher name:    aes
Cipher mode:    cbc-essiv:sha256
Hash spec:      sha1
Payload offset: 1032
MK bits:        128
MK digest:      4b 35 7f 88 90 0a 8c 7c b1 1e 39 58 07 91 a6 dd ce f8 74 1b
MK salt:        85 00 22 c0 b1 ff 20 20 40 0f a8 92 58 d3 92 4a
b5 d2 0b ff 5f c5 75 b9 53 bc 89 ac 51 26 ec a0
MK iterations:  10
UUID:           d77eb752-8a90-4d94-ae9f-2bec0a22c5d3

Key Slot 0: ENABLED
Iterations:             400623
Salt:                   7b e5 a5 d8 a7 b8 60 20 e7 62 1c 5b a9 da c4 99
7d 04 1b 45 50 fa f4 e5 fd d9 29 60 5b 5e eb aa
Key material offset:    8
AF stripes:             4000
Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED

Check the UUID for the partition.

# cryptsetup luksUUID /dev/sdb3
d77eb752-8a90-4d94-ae9f-2bec0a22c5d3

# cryptsetup luksOpen /dev/sdb3 db
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.

View information about the mapped device with:

# dmsetup info db
Name:              db
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        0
Event number:      0
Major, minor:      253, 1
Number of targets: 1

# mke2fs -j /dev/mapper/db
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
124440 inodes, 497496 blocks
24874 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
61 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

# mkdir /db
# mount /dev/mapper/db /db
# ls /db
lost+found

Add an Entry in /etc/crypttab
You must add an entry in the /etc/crypttab in order for your partition to mount.  Notice the format is the name which contains the string luks followed by the UUID and then the UUID the second time with UUID.  LUKS provides a UUID (Universal Unique Identifier) for each device, just like having an physical volume in LVM.  The advantage of the UUID is that even if you move the disk or add other partitions it will remain constant.

luks-86470780-c8aa-4e5d-ad75-42616b381998 UUID=86470780-c8aa-4e5d-ad75-42616b381998 none
luks-d77eb752-8a90-4d94-ae9f-2bec0a22c5d3 UUID=d77eb752-8a90-4d94-ae9f-2bec0a22c5d3 none

Edit the /etc/fstab
Here again you will use a /dev/mapper reference to teh UUID for the partition.  Note there are two partitions mounted in this example, one block device that was created at install and another that was creatd manually after installation.

LABEL=/                 /                       ext3    defaults        1 1
LABEL=/home             /home                   ext3    defaults        1 2
/dev/mapper/luks-86470780-c8aa-4e5d-ad75-42616b381998 /data                   ext3    defaults        1 2
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda2         swap                    swap    defaults        0 0
/dev/mapper/luks-d77eb752-8a90-4d94-ae9f-2bec0a22c5d3 /db ext3  defaults 0 0

When you reboot the server you will need to provide the passphrase for each partition that you have encrypted.

按照我的理解 centos 从5.3 开始自带了全盘数据加密功能, 可以支持 ext3, lvm, raid , 使用在在系统启动前需要输入一个通行密码, 可以当我用其加密 LVM 重启后 Enter LUKS passphrase 总是提示 Can’t Open Device , 当我再次重装时也会提示输入 passphrase, 这次没有再提示任何错误了, 只要不再选择 “Encrypt System” 就可以取消原先的密码了, 我猜想可能是这个功能刚出来还不完善存在bug导致的, 以后我会在虚拟机上再测试的.

由于安装Gnome, KDE等图像界面, 所以每次centos启动时都会自动到Gnome中, 如果想要启动时默认是文本界面的话, 就需要修改默认的运行等级了:
vim /etc/inittab
将 id:5:initdefault:
改为 id:3:initdefault:

RUNLEVEL FILES

每个通过chkconfig管理的服务在其init.d目录下的角本中都需要两行或多行的注释。第一行告诉chkconfig在默认情况下什么运行级别的服务可以开始,也就是所说的开始或结束的优先级别。如果服务没有默认的级别,建造将在所有运行级别中启动。a – 将用于代替运行级列表。第二个注释行包括对此服务的描述,可以通过反斜线符号扩展为多行。(英文如下)

Each service which should be manageable by chkconfig needs two or more

commented lines added to its init.d script. The first line tells chk-

config what runlevels the service should be started in by default, as

well as the start and stop priority levels. If the service should not,

by default, be started in any runlevels, a – should be used in place of

the runlevels list. The second line contains a description for the

service, and may be extended across multiple lines with backslash con-

还有一个问题就是当我改变LCD后, 不管是 通过菜单 System – Administration – Display 还是通过 /etc/X11/xorg.conf, GNOME的分辨率总是无法更改, 最后才知道是因为SAMSUNG 943NW自己没有刷新导致的(我不明白为了机器重启了LCD还是不自动刷新), 知道原因就简单了, 触摸一下LCD右下角的AUTO 就搞定了(触摸式调节的, 一直都用laptop导致我没注意到现在的lcd都有这种功能了).
在修改xorg.conf时发现modes的第一个值是有效的,
关于X11的一些常识:

X Window系统 (X11或X)是一种 位图 显示的 视窗系统 . X 在 1984年 起始于 MIT 。现在的协定版本,X11,是在 1987年9月 所释出的。该专案是由 X.Org 基金会 所领导;现在的 参考实作 是版本 11 release 6.8.2,且在 MIT 执照 和相似的表示许可执照下是 自由软体 。 “X Window系统”通常简称为”X11″或者”X”。”X Windows”(按照”Microsoft Windows”的风格)一词已经正式废弃,一般也认为并不正确.
GNOME 即GNU网络对象模型环境 (The GNU Network Object Model Environment), 为Unix或者类Unix操作系统构造一个功能完善、操作简单以及界面友好的桌面环境,他是GNU计划的正式桌面。 GNOME计划是1997年8月由Miguel de Icaza和Federico Mena发起,作为KDE的替代品。
X11是X Window System Protocol, Version 11(RFC1013),是X server和X client之间的通信协议。X server是xfree86/xorg驱动下的显示设备鼠标键盘统称,X client通过X11协议和xfree86/xorg实现的X server通信,比如,告诉它画一个左上角坐标为(x,y),宽为w,高为h的窗口,xfree86就让显示器把屏幕上的小灯(像素)打亮,然后你就看到了一个窗口。
为了方便开发人员编写X clients,就有了Xlib来封装协议;Xlib不够方便,于是就有了qt和gtk,提供了很多窗口控件(widgets)。
为了方便用户,就出现了gnome和kde等桌面管理系统。一般来说,linux用户看到的界面就是其中之一了。gnome用的是gtk库,kde用的是qt库。

Linux操作系统桌面环境GNOME和KDE的切换
一、设置GNOME或者KDE为默认的启动桌面环境
方法1:修改/etc/sysconfig/desktop,根据需要将“DESKTOP”后面的内容改为KDE或GNOME。
方法2:在当前用户目录下建立“.xinitrc”这个文件(注意文件名前有一个点号,代表建立的是一个隐藏文件),文件的内容就一行startkde或gnome-session,根据自己的需要选择KDE或GNOME。
二、GNOME和KDE的切换(“#”后面为输入命令)
1、如果需要切换到GNOME:  #switchdesk gnome
2、如果需要切换到KDE:  #switchdesk kde

为了能方便的进行配置, 学会一些VIM基本快捷键很有必要:
h,j,k,l 除了可使用光标键在移动光标外,一种快捷方法
$    光标移动到行尾。
G    光标移动到文档末尾。
H,L    H控制光标移动到当前屏幕头,L控制光标移动到当前屏幕尾。
{,}    {控制光标上移一个段落,}控制光标下移一个段落
i    进入编辑模式
ESC    退出编辑状态
o    在当前位置下插入一空行,进入编辑模式,光标位于空行的最开头。
a    光标后移一个字符,进入编辑模式。
v    这入可视模式,可用高亮的色块选择内容。
x or DEL键    删除当前字符,删除内容保存在缓冲区。
xp    左右字符互换。
dd    删除当前行,删除内容保存在缓冲区。
ddp    上下两行的内容互换。
d$    删除当前光标至行尾的所有内容。
dG    删除从当前行至文件未尾的所有行。
u    undo。
v    进地visual模式,移动光标可选择文本。
y    把当前行复制到缓冲区中。
p    把缓冲区中的文本插入到当前位置。
“ay    把当前行复制到a缓冲区。可用26个字母命名多个缓冲区。
“ap    把a缓冲区中的文本插入当前位置。
J    上下两行合并成一行。
.    重复执行上次命令
:q!    不保存退出vim。
:w    保存文档,但不退出vim。
:x     保存退出vim。
:e filename    编辑/打开一个文件
:s/emacs/vim    在当前行中把第一个emacs替换成vim。
:s/emacs/vim/g    把当前行中所有的emacs替换成vim。
:%s/emacs/vim/g    在全局范围内把emacs替换成vim。
:reg    列出缓冲区内容。
:set all    列出所有参数的配置情况。
:tabe    新建一个标签页。
:tabn or :tabp    切换到下一个\上一个标签页。
:close    关闭当前标签页。
:qa    关闭所有标签页退出。

我看到网上说配置vim来开发php, 需要用到/etc/vim/vimrc文件, 但这个文件似乎只在Debian中, CentOS连vim目录都没有.

还有一些必要的快捷键:
Linux 图形界面和虚拟终端的相互切换命令
ctrl+alt+F1/F2/F3/F4/F5/F6,可以从X切换到terminal。这个命令好久不用,都忘记了。通常Linux会有7个虚拟终端,最后一个是图形界面。
在X死掉的时候,可以切换到命令行虚拟终端,杀掉X,然后再重新启动X。
alt+F7,则是从terminal切换到X。
ctrl+alt+BACKSPACE,则是注销。
GNOME快捷键
Alt + F1 类似Windows下的Win键,在GNOME中打开”应用程序”菜单(Applications)
Alt + F2 类似Windows下的Win + R组合键,在GNOME中运行应用程序
Ctrl + Alt + D  类似Windows下的Win + D组合键,显示桌面
Ctrl + Alt + L  锁定桌面并启动屏幕保护程序
Alt + Tab 同Windows下的Alt + Tab组合键,在不同程序窗口间切换
PrintScreen 全屏抓图
Alt + PrintScreen 当前窗口抓图
Ctrl + Alt + → / ←  在不同工作台间切换
Ctrl + Alt + Shift + → / ← 移动当前窗口到不同工作台
Alt + F4 关闭窗口
Alt + F5 取消最大化窗口 (恢复窗口原来的大小)
Alt + F7 移动窗口 (注: 在窗口最大化的状态下无效)
Alt + F8 改变窗口大小 (注: 在窗口最大化的状态下无效)
Alt + F9 最小化窗口
Alt + F10 最大化窗口
Alt + Space 打开窗口的控制菜单 (点击窗口左上角图标出现的菜单)
应用程序中的常用快捷键
(注: 并不适用于所有程序)
Ctrl+N 新建窗口
Ctrl+X 剪切
Ctrl+C 复制
Ctrl+V 粘贴
Ctrl+Z 撤销上一步操作
Ctrl+Shift+Z 重做刚撤销的一步操作
Ctrl+S 保存

linux指令中区分文件名和目录大小写,让我很不习惯,以下命令是我在看了说明, 并使用后按照自己的理解重新描述的:
who               显示当前tty状态
who  -a        可以显示所有tty终端的登录状态了.
chkconfig  –list | more                                  列出所有的/etc/rc[0-6].d下的符号链接(真实目录在/init.d)所代表的服务配置状态
chkconfig iptables –level 3 off 在第三等级启动时不启动防火墙
service iptables status               查看防火墙的状态
service –status-all | more        查看当前所有系统服务的状态
reboot  重启
halt -f  重启
shutdown -h 0  关机, 如果不加 0 只是关闭所有服务
poweroff   关机
halt -p 关机
su root 切换到root用户
passwd root 修改root用户密码
需要帮助时, 参数一般是–help, 偶尔需要 -?
过滤屏幕内容时, 可以加入 |grep -P 按基本正则表达式 或 |grep -i ‘hello’ 查找hello忽略大小写
例子 grep –help |grep -P ‘b\w+\-\w+set’
|more功能和以前在DOS中一样
|less和more区别, less像是用一个只读的vi在查看, 退出必须用 :q
在编辑文件时错误退出, 再进行vim和vi时都没有看到网上所说的删除swp的选择项, 手动用rm删除
rpm -qa | grep kde  查询是否存在kde安装包

    What I'm Doing...
    • 美国联合钢铁工人工会(United Steelworkers,简称USW)周四向美国贸易官员控诉中国不公平地补贴其清洁能源技术行业,从而在11月的国会选举之前给白宫出了个政治难题。 3 hrs ago
    • 差点忘了,还要准备好燃气卡,顺便也准备图书卡和美食城的餐卡好了,今晚要把那三本书看完,明天还归还。《偶像和英雄——艾森豪威尔传》、《独立与诚实——格罗弗·克利夫兰传》、《重建时代的领袖——拉瑟福德·B.海斯传》 3 hrs ago
    • 明天计划,去看眼科,去看团购,如果确定不下晒衣架和床,就去装饰城,争取今天搞定这两件。然后在家里等待新奥燃气的人员下午两点半来帮忙开通天然气。 3 hrs ago
    • 另外两款脚感比较生硬,听说我选的这款是树脂材料的比那两款好,也不知是不是真话,不过我想肯定不是正品crocs专用塑料制成的。如果在她网店买则要138元,让我以后也说是138买的,帮忙宣传之类的客套话,看起来像小孩,真不像23岁 3 hrs ago
    • 下班后随王银果回了二厂,因为他妹已经把我看中的那三款 #crocs 鞋带来了,经过一番比较我选择了 “crocs卡骆驰 2010世界杯 crocband卡洛班国际限量 意大利 ” 这一款,因为脚感好过另外两款,优惠到100元。 3 hrs ago
    • 只是我们是否有必要把漏洞告诉 #chinasec 的开发公司明朝万达呢? 毕竟知道我详细的破解方法了,他们补上此漏洞还是比较容易的,可以直接禁止查看注册表. 7 hrs ago
    • 而且 #Chinasec 很无耻, 除了之前发现会破坏 #360safe 中的 360ver.dll和360verify.dll 外,就连“高级工具”里德 文件粉碎机 FileSmasher.exe 文件也被破坏. 7 hrs ago
    • More updates...

    Posting tweet...

    Creative Commons License

    Check Google Page Rank