Monday, July 27, 2009

得到ubuntu的codename

之前一直不知道ubuntu的code name是放在哪里的. 这样就有个麻烦:
* 网上得到的source list当是不同的code name就无法使用.

看了人家的shell脚本才知道: /etc/lsb-release

强的shell:
$ grep 'DISTRIB_CODENAME' /etc/lsb-release | awk -F'=' '{print $2}'

Saturday, July 25, 2009

NSS与PAM的配置

这两种功能在多个方面都有相似性, 所以在把它们放在一起, 容易比较, 加深印象.

回顾:
1. PAM是一种认证类似框架, 使用约定的API可以使程序满足多样, 灵活的认证后端.
2. nss是对信息服务(information service)的glibc函数架构. 使用它可以在不修改现成的程序而实现信息服务后端源的变化.


PAM的配置文件为:
1. /etc/pam.conf
2. /etc/pam.d下对不同服务分开配置文件
nss的配置文件为:
1. /etc/nsswitch.conf

服务与配置文件

使用PAM认证的程序怎么找到自己独有的配置文件?
答案: PAM的服务名, PAM的服务名一般编码到代码中, 对应也/etc/pam.d下的文件名.
如samba的PAM服务名为"samba"(被写到代码中), 所以samba的PAM配置文件是: /etc/pam.d/samba, 服务名必须与文件名相同

怎么知道系统中有哪些可用的PAM后端(modules)?

答案: PAM的后端modules被放置在:/lib/security. 例如ldap的ldap后端在ubuntu下对应于包: libpam-ldap, 它的module是: /lib/security/pam_ldap.so

怎么知道PAM后端(modules)可以使用的参数?
不同的modules有自己的使用参数, 这就要查看modules本身的文档. 在ubuntu下, libpam-ldap的文档位置:
* /usr/share/doc/libpam-ldap
提供man 5 pam_ldap online 文档

怎么知道系统中有哪些可用的后端(modules), 和在哪里指定要使用的后端(modules)?
NSS也与PAM相同, 也有服务名. 如下为nsswitch.conf的一行配置:
hosts:          dns  files

其中, dns与files就是服务名, 同时, 它与modules是的关系如下:
/lib/libnss_SERVICE.so.X
 * 当X是1时,  表示glibc是2.0版本
 * 当X是2时, 表示glibc是2.1版本
SERVICE就是服务名, 同时它也是module名的一部分.

例子:
ubuntu下nss的ldap模块对应的包: libnss-ldap, modules的路径为: /lib/libnss_ldap.so.2 -> libnss_ldap-2.8.so (有与没有X都为同一个文件)

不同的nss的后端(modules)使用的配置文件在哪里?
不同的modules有自己的使用参数, 这就要查看modules本身的文档. 在ubuntu下, libnss-ldap的文档位置:
* /usr/share/doc/libnss-ldap
提供man 5 nss_ldap online文档

Friday, July 24, 2009

系统下的Session

将会涉及到两个概念:
1. session
2. process group

总体关系如下:


Session

关于session的用处:
When a user logs out of a system, the kernel needs to terminate all the
processes the user had running (otherwise, users would leave a slew of
old processes sitting around waiting for input that can never arrive).
To simplify this task, processes are organized into sets of sessions. The session's ID is the same as the pid of the process that created the session through the setsid() system call. That process is known as the session leader
for that session group. All of that process's descendants are then
members of that session unless they specifically remove themselves from
it. The setsid() function does not take any arguments and returns the new session ID.


如下为ssh登陆后, 进程的PID树与session的情况:
会话信息:
$ ps axo user,pid,rgid,session,command | less
.... 截 ....
root     26323     0 26323 sshd: jessinio [priv]
jessinio 26331  1000 26323 sshd: jessinio@pts/0
jessinio 26332  1000 26332 -bash
jessinio 26349  1000 26332 less
jessinio 26357  1000 26332 python test_session.py
jessinio 26358  1000 26332 ps axo user,pid,rgid,session,command
jessinio 26359  1000 26332 less
.... 截 ....


进程树:
$ pstree -p
.... 截 ....
        |-sshd(2051)---sshd(26323)---sshd(26331)---bash(26332)-+-less(26349)
        |                                                                                          |-less(26477)
        |                                                                                          |-pstree(26476)
        |                                                                                          `-python(26357)
.... 截 ....
    
通过ssh登陆时, 是通过sshd运行bash(交互)的. 这时的bash自己成为session leader(这是交互性bash的特点, 并且使用自己的controlling terminal)
 * session被设置成与进程号一样的数字: 因为PID在系统中是唯一的.
 * 在进程不强制使用setsid系统调用的情况下, 是要继承父进程的session号的.
 * 使用setsid系统调用需要一定的要求: This is allowed only when the current process is not a process group leader.
 * 至以为什么sshd(蓝色部分)的第一个进程不退出来, 它的功能还是很有意思的: 至少父进程可以知道子进程的状态
实例说明:

代码:
#!/bin/bash
import os,sys
import time


def SetSession( ):
    os.setsid()
    time.sleep(100)

def CreateChild( ):
    if os.fork() == 0:
        SetSession( )
    else:
        # keep parent process alive!
        # because we will discover by "pstree -p"
        time.sleep(100)
if __name__ == "__main__":
    SetSession()


上面的代码直接在交互的bash下运行是为出现:

Traceback (most recent call last):
  File "test_session.py", line 19, in <module>
    SetSession()
  File "test_session.py", line 7, in SetSession
    os.setsid()
OSError: [Errno 1] Operation not permitted


因为test_session.py程序是交互的bash的第一代, 所以无法使用setsid系统调用.
如果将SetSession()换成调用CreateChild( ) 情况就不同了, 因为fork出的子进程是session leader的第二代!

        |-sshd(2051)---sshd(26494)---sshd(26502)---bash(26503)-+-less(26520)
        |                                                                                          |-less(27847)
        |                                                                                          |-pstree(27846)
        |                                                                                          |-python(27844)---python(27845)
        |                                                                                          `-vim(27694)---{vim}(27695)


上面的python(27844)---python(27845)就是我们要找的, 一个是父进程, 一个是子进程, 查一下子进程的session号:
jessinio@solution:~$ ps axo user,pid,rgid,session,command |grep 27845
jessinio 27845  1000 27845 python test_session.py

可以看出, 子进程的session ID被设置成与PID一样的数字

附: python cookbook上产生daemon进程的代码: http://www.ubookcase.com/book/Oreilly/Python.Cookbook.2nd.edition/0596007973/pythoncook2-chp-9-sect-13.html

其实, 现在版本的linux不会在用户logout后把特定的session进程都杀掉的. 下面还有一段话:


When the connection to a terminal is lost, the kernel sends a signal (SIGHUP; see Chapter 12 for more information on signals) to the leader of the session
containing the terminal's foreground process group, which is usually a
shell. This allows the shell to terminate the user's processes
unconditionally, notify the processes that the user has logged out
(usually, through a SIGHUP), or take some other action (or inaction). Although this setup may seem complicated, it lets the session
group leader decide how closed terminals should be handled rather than
putting that decision in the kernel. This allows system administrators
flexibile control over account policies.

* 这里只是指出foreground process ( group ), 没有提到background 的处理方法.
* 这种处理方法与shell有很大的相关性! 不过的shell可以有不同的处理方法

controlling terminal


Every session is tied to a terminal from which processes in the
session get their input and to which they send their output. That
terminal may be the machine's local console, a terminal connected over
a serial line, or a pseudo terminal that maps to an X window or across
a network (see Chapter 16 for information on pseudo terminal devices).
The terminal to which a session is related is called the controlling terminal (or controlling tty) of the session. A terminal can be the controlling terminal for only one session at a time.



Although the controlling terminal for a session can be changed, this
is usually done only by processes that manage a user's initial logging
in to a system.

* 来自Linux Application Development 一书

一个session, 是使用同一个terminal

process group

实际中, process group常常被用于job control. 本人需求不大

参考文档:
http://www.linuxforum.net/forum/gshowflat.php?Board=linuxK&Number=648409&page=3&o=
http://www.ibm.com/developerworks/cn/linux/l-cn-nohup/
http://www.informit.com/articles/article.aspx?p=397655&seqNum=6
http://en.wikipedia.org/wiki/Daemon_(computer_software)
http://www.win.tue.nl/~aeb/linux/lk/lk-10.html

Thursday, July 23, 2009

linux下密码的放置(shadow suite)

了解/etc/passwd与/etc/shadow的来龙去脉


On a Linux system without the Shadow Suite installed, user information including
passwords is stored in the /etc/passwd file. The password is stored in an
encrypted format. If you ask a cryptography expert, however, he or she will tell you
that the password is actually in an encoded rather than encrypted format because
when using crypt(3), the text is set to null and the password is the key. Therefore,
from here on, I will use the term encoded in this document.

在没有使用shadow suite的情况下, 用户的信息包括密码是存在在/etc/passwd文件的.
 * 所提的shadow suite是否为: sys-apps/shadow
encoded与encrypted两个名词的区别


When a user picks or is assigned a password, it is encoded with a randomly
generated value called the salt. This means that any particular password could be
stored in 4096 different ways. The salt value is then stored with the encoded
password.

使用crypt(3)的特点, 对于上面说的4096种方法, 见man 3 crypt中提到:
       salt is a two-character string chosen from the set [a–zA–Z0–9./].  This string is used to perturb
       the algorithm in one of 4096 different ways.
* 关于salt与encoded是同时存在在/etc/passwd文件中的, 见下面的passwd格式


When a user logs in and supplies a password, the salt is first retrieved from the
stored encoded password. Then the supplied password is encoded with the salt value,
and then compared with the encoded password. If there is a match, then the user is
authenticated.

用户认证的最基本原则

The /etc/passwd file also contains information like user ID's and group ID's that
are used by many system programs. Therefore, the /etc/passwd file must remain
world readable. If you were to change the /etc/passwd file so that nobody can
read it, the first thing that you would notice is that the ls −l command now
displays user ID's instead of names!

/etc/passwd除了密码的认证外, 还被广泛使用.

但是又由于种种安全问题, 如果用户把encoded的hash放在/etc/passwd这种world readable的文件中, 会有问题

The Shadow Suite solves the problem by relocating the passwords to another file
(usually /etc/shadow). The /etc/shadow file is set so that it cannot be read by
just anyone. Only root will be able to read and write to the /etc/shadow file.
Some programs (like xlock) don't need to be able to change passwords, they only
need to be able to verify them. These programs can either be run suid root or you can
set up a group shadow that is allowed read only access to the /etc/shadow file.
Then the program can be run sgid shadow.

于是出现了/etc/shadow文件, 此文件的权限被严格要求

Additionally, the Shadow Suite adds lots of other nice features:
⋅ A configuration file to set login defaults (/etc/login.defs)
⋅ Utilities for adding, modifying, and deleting user accounts and groups
⋅ Password aging and expiration
⋅ Account expiration and locking
⋅ Shadowed group passwords (optional)
⋅ Double length passwords (16 character passwords) NOT RECOMMENDED]
⋅ Better control over user's password selection
⋅ Dial−up passwords
⋅ Secondary authentication programs [NOT RECOMMENDED]

shadow suite引入新的机制, 上面为它的机制
* shadow用于动词时, 为"遮蔽, 或者 使...遮蔽", 如shadowed group passwords

Installing the Shadow Suite contributes toward a more secure system, but there are many other things that can
also be done to improve the security of a Linux system, and there will eventually be a series of Linux
Security HOWTO's that will discuss other security measures and related issues.

引入shadow suite有其它的事需要做


A non−shadowed /etc/passwd file has the following format:
username:passwd:UID:GID:full_name:directory:shell
实例:
username:Npge08pfz4wuk:503:100:Full Name:/home/username:/bin/sh
* Np为salt的值

Once the shadow suite is installed, the /etc/passwd file would instead contain:
username:x:503:100:Full Name:/home/username:/bin/sh
The x in the second field in this case is now just a place holder. The format of the /etc/passwd file really
didn't change, it just no longer contains the encoded password. This means that any program that reads the
/etc/passwd file but does not actually need to verify passwords will still operate correctly.
The passwords are now relocated to the shadow file (usually /etc/shadow file).

The /etc/shadow file contains the following information:
username:passwd:last:may:must:warn:expire:disable:reserved
* field的具体意思见man 5 shadow

回归问题基本: 程序认证时怎么使用/etc/shadow?

/etc/shadow文件的权限:
jessinio@niolaptop /tmp $ ls -l /etc/shadow
-rw------- 1 root root 909 2009-06-26 16:05 /etc/shadow

从各个需要使用/etc/shadow的程序都是通过种种方法得root权限才使用shadow文件的

如下内容是man 3 getspnam中的一段话:

DESCRIPTION
       Long ago it was considered safe to have encrypted passwords openly visible in the password  file.
       When  computers got faster and people got more security-conscious, this was no longer acceptable.
       Julianne Frances Haugh implemented the shadow password suite that keeps the  encrypted  passwords
       in  the  shadow  password  database  (e.g.,  the local shadow password file /etc/shadow, NIS, and
       LDAP), readable only by root.

只能为root才可以处理这种事情

参考文档:
* http://www.tldp.org/HOWTO/Shadow-Password-HOWTO.html


Wednesday, July 22, 2009

NSS及它与PAM的关系

NSS全称: Name Service Switch. 从man手册中, 描述它的来由:

libc函数往往需要一些本地信息, 比如getpwent()参数需要/etc/passwd文件. 再gethostbyname()函数等等, 对于日益增加又健壮的服务(如NIS), 它种服务在libc的函数上被hack, 但不能永远靠hack代码去增加功能的.所以在libc5就加入NSS结构, 结构如下:

所谓的Name Service是如下类信息:
aliases
ethers
group
hosts
netgroup
networks
passwd
protocols
publickey
rpc
services
shadow
* 这些信息都是通过libc的函数去得到的.

C级函数是依靠/etc/nsswitch.conf文件去选择正确的back_end
linux下, back_end是存放在/lib/libnss_*

NSS与PAM

从Name Service提供的信息看, NSS 与 PAM 有些事是相同的. 但是细看, 两者是不一样的.

* NSS返回查询的结果数据

* PAM提供多种灵活的认证方案

在NSS中, 容易与认证扯上关系的, 无非是NSS提供的passwd.  从getpwent函数的手册上看, 本函数是返回一个C结构体的:

           struct passwd {
               char *pw_name; /* username */
               char *pw_passwd; /* user password */
               uid_t pw_uid; /* user ID */
               gid_t pw_gid; /* group ID */
               char *pw_gecos; /* real name */
               char *pw_dir; /* home directory */
               char *pw_shell; /* shell program */
           };
用户程序结果使用返回的信息(密码)与用户的输入信息(密码)是可以实现认证的效果. 但是这样需要用户的程序处理更多的事情(相比程序使用PAM的情况).

对于使用libc的函数去处理认证的情况, 在NSS的结构上, 还可以做到类PAM一样灵活配置的: 因为NSS是从libc函数去调用相应的back_end的. 这样就可以不同的back_end去改变使用不同database而不像PAM一样不影响到(使用libc的)程序本身.

例如, ldap就有一个NSS的back_end, 在ubuntu下叫libnss-ldap. 配置nsswitch.conf去使用本back_end, 就可以使程序把LDAP作为数据源.

修改程序的认证数据源, 需要程序本身使用到如下两种结构基础
1. 使用libc的函数处理认证
2. 使用PAM机制


参考文档: http://docs.hp.com/en/305/uxint.html

系统与PAM认证

本文为如下地址学习笔记: http://fhc2007.blog.ubuntu.org.cn/?p=1155
Linux-PAM (Pluggable Authentication Modules for Linux)

PAM 为了实现其插件功能和易用性,它采取了分层设计思想:让各鉴别模块从应用程序中独立出来,然后通过PAM API作为两者联系的纽带,这样应用程序就可以根据需要灵活地在其中"插入"所需鉴别功能模块,从而真正实现了"鉴别功能,随需应变"。实际上,这一思路 非常符合软件设计中的"高内聚,低耦合"这一重要思想,PAM 的体系如下简图所示:

PAM 在模块层提供
* 鉴别模块外
* 支持帐户管理
* 会话管理
* 口令管理

PAM API

第一类: 调用下层特定模块的接口

这类接口与底层的模块(上面所提的PAM四种功能)相对应
1. 鉴别类接口: pam_authenticate()用于鉴别用户,pam_setcred()用于修改用户的秘密信息。
2. 帐号类接口: pam_acct_mgmt()检查受鉴别的用户所持帐户是否有权登陆系统,以及该帐户是否已过期等。
3. 会话类接口: 包括用于会话管理和记帐的 pam_open_session()和 pam_close_session()函数。
4. 口令类接口: 包括用于修改用户口令的 pam_chauthtok()。

第二类: 对底层模块提供支持以及实现应用程序与模块之间的通信等

1. 管理性接口
2. 应用程序与模块间的通讯接口
3. 用户与模块间的通讯接口: pam_start()函数可以通过会话式的回调函数,让底层模块通过它们读写模块相关的鉴别信息,比如以应用程序所规定的方式提示用户输入口令。
4. 模块间通讯接口
5. 读写模块状态信息的接口

配置文件及其格式

PAM的配置文件:
1. /etc/pam.conf
2. /etc/pam.d
这两种方式的区别在于: pam.conf中一个登记项(每行对应一个登记项)需要标明服务名, 对于/etc/pam.d的方式, 其下面每个文件名其实就是服务名, 无需要在配置文件中标明服务名

什么是服务名?
服务名就是使用PAM认证的服务在自己程序代码中硬编码要使用的pam配置文件. 要修改只能修改程序代码

PAM的API:
int pam_start(const char *service_name, const char *user,
                     const struct pam_conv *pam_conversation, pam_handle_t **pamh);
The service_name argument specifies the name of the service to apply and will be stored as
       PAM_SERVICE item in the new context. The policy for the service will be read from the file
       /etc/pam.d/service_name or, if that file does not exist, from /etc/pam.conf.
 * 来自man 3 pam_start
在samba的source/auth/pampass.c原代码中:
pam_start("samba", user, pconv, pamh);
 * 所以, samba的PAM配置文件为:/etc/pam.d/samba

下面以pam.d下的配置文件为基础说明PAM的配置文件

PAM每一个登记项格式如下:
第一栏: module_type
 * auth表示鉴别类模块
 * account表示帐户类模
 * session表示会话类模块
 * password表示口令类模块
第二栏: control_flag
 * required: 当对应于应用程序的所有带 required标记的模块全部成功后,该程序才能通过鉴别
 * Requisite: 同required, 不同之处在于其一旦失败就不再执行堆中后面的其它模块
 * sufficient: 一旦成功立即返回成功, 失败即等于optional
 * optional: 表示即便该模块失败,用户仍能通过鉴别
第三栏: module_path 模块文件名
第四栏: options 模块传递的选项


总: 当程序支持PAM的认证方式, 系统管理员就可以按需求更换认证方式而不影响到程序.



python的binding: http://ace-host.stuart.id.au/russell/files/pam_python

Saturday, July 18, 2009

vmlinux与bzImage

在编译kernel时, 看了下make help, 发现点不明白的地方:

在产生kernel时, 有两种方式:

一种:
Other generic targets:
* vmlinux         - Build the bare kernel

两种:
Architecture specific targets (x86):
* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)

当make vmlinux时, 会在$SRC目录下产生一个vmlinux文件
当make bzImage时, 会在$SRC/arch/x86/boot目录下产生一个bzImage文件
* 因为本人的机器是x86架构的.

两个文件的大小不同:
jessinio@niolaptop /usr/src/linux $ du -h arch/x86/boot/bzImage
3.9M    arch/x86/boot/bzImage
jessinio@niolaptop /usr/src/linux $ du -h vmlinux
11M     vmlinux

实际上, bzImage是一个被压缩过的kernel(可以运行自解), 在一些资料到提以前的kernel大小是有限制的. 所以需要压缩.
 * wikipedia的信息: http://en.wikipedia.org/wiki/Vmlinux

在make install发生的事

在make install后, 会有三个文件被放到/boot下:
1. vmlinuz-2.6.x.y.z
2. System.map
3. config
4. 为什么我的gentoo没有initrd.img的??
在/usr/src/linux下还有一个vmlinux的方件.

那么/boot下的vmlinux是哪个呢? 如下:

jessinio@niolaptop /usr/src/linux $ diff /usr/src/linux/arch/x86/boot/bzImage /usr/src/linux/vmlinux
Files /usr/src/linux/arch/x86/boot/bzImage and /usr/src/linux/vmlinux differ
jessinio@niolaptop /usr/src/linux $ diff /usr/src/linux/arch/x86/boot/bzImage /boot/vmlinuz

可以看出/boot下的vmlinux是/usr/src/linux/arch/x86/boot/bzImage


随便提一下make内核时的过程:

就常使用的make也过程:
cd /usr/src/linux
make menuconfig
make
make modules_install
make install

注意到上面的一个make是不参数的, 这种情况实际如下:
Execute "make" or "make all" to build all targets marked with [*]

"*"号等于如下:
make vlinux modules bzImage


邮件服务器发件被当spam

自己搞了个服务器, 当通过smtpd发出的email会被spam, gmail对于来信有如下要求:

https://mail.google.com/support/bin/answer.py?answer=81126

不同的邮件服务商有不同的要求. 如21cn只需要DNS与IP对应即可

这方面的知识需要多了解些

CPU不支持, 无法使用KVM

从intel主页中查到T1300不支持intel VT技术

但是从cpuinfo中查到有vmx指令, 对于这种情况, 说法如下:
 * http://www.linux-kvm.org/page/FAQ#How_can_I_tell_if_I_have_Intel_VT_or_AMD-V.3F

使用KVM去虚拟OS时, 会扯到别一个名称:QEMU, 两者的区别:

QEMU and KVM

There are several different virtualization software packages available. Each has its own strengths and weaknesses. For this series of lessons, we'll concentrate on the QEMU and KVM packages. Of the four scenarios that we presented above, these two packages won't help you with the first one, but they can help you with the second, third, and fourth ones.

What's the difference between QEMU and KVM? Well, to simplify things a bit. . .

QEMU provides virtualization purely by means of software, and can be used as a stand-alone package.

KVM--which stands for "Kernel-based Virtual Machine"--provides for hardware-assisted virtualization. It can only be used with newer processors, such as Intel Core 2's or more recent AMD Athlon64's. It must be used in conjunction with QEMU. Also, you'll want to run it with at least kernel version 2.6.20. (That means, you'll want to install it on at least a Feisty Fawn version of the Ubuntu family.)

 


Thursday, July 16, 2009

gentoo下几种安装的chromium的方法

1. 使用deb包
在解决了chrome需要的依赖后, 可以方便从如下地址找到安装的方法:
 * http://blog.andreaolivato.net/open-source/google-chrome-natively-running-on-gentoo-linux.html

2. 使用gentoo源中的chromium, ebuild位置
 * /usr/portage/www-client/chromium-bin/chromium-bin-9999.ebuild (9999表示无限大, 就是最新的意思)
指定安装chromium-9999:
# autounmask www-client/chromium-bin-9999

3. 从源代码中编译:
* 方法可见前面写的blog

Wednesday, July 15, 2009

build newest chromium

在firefox下使用docs上瘾了, 为了使用最高的docs服务, 决定下载最新版本的chromium

取得代码:
http://dev.chromium.org/developers/how-tos/get-the-code
官方推介下载tar包然后再使用gclient sync代码

chromium有自己的build脚本, 需要安装builder工具后才能进行, 可见: http://dev.chromium.org/developers/how-tos/install-gclient

build过程:
http://code.google.com/p/chromium/wiki/LinuxBuildInstructions


chromium的代码浏览地址: http://src.chromium.org/viewvc/chrome

编译了二个小时左右才可以使用, 最心痛的是chromium访问gmail时速度很慢! docs也一样! 为什么? 我哪里还没有设置?

大概是中文字体的问题...呃....不知道怎么搞晚了, 明天再搞一下.

Tuesday, July 14, 2009

google Docs的使用心得

之前没有注意到docs, 因为本人一直把它想像成Word, 又很少使用到Word.

今天注意到, google的docs是一个很好的文档仓库. 它有如下特点:
1. 数据安全. 数据在本人的硬盘中是非常不安全的, 说不准明天就被remove了!
2. 文档有version的概念
3. 分享与协作方便

上面三个功能令本人hight了! 日后全部文档都搬到google服务上了

google docs还有一个令本人高兴的功能: 文档可以发布到blogger(wordpress也可以)

真是hight爆了

Monday, July 13, 2009

VirtualBox的Headless模式

VirtualBox以headless方式启动VM, 有两个程序可以做到这功能:
1. VBoxHeadless
2. VBoxManage

VBoxHeadless可以在启动时改变一些与Headless模式启动的相关参数, 而VBoxManage不行.

VBoxHeadless的启动方法:
# VBoxHeadless --startvm ubuntu

VBoxManage命令去启动(不过此程序不能在启动时改变VM的一些参数):
# VBoxManage startvm ubuntu -type vrdp

VM以Headless方式启动后. 如何连入VM呢? 这时我们并不知道VM使用的IP是多少, 就算是自动分配与static的情况下, 网络出问题呢?

比如: notebook被suspend了, 恢复后怎么连入VM呢?

之前一直被这个问题, 其实, 一切都有明显的答案的:

netjessinio@niolaptop ~ $ netstat -an|grep 3389
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN

VirtualBox会listen机器(指host机器)的全部IP! 包括localhost!

^_^这就可以方便rdesktop了

附上使用VBoxManage对Headless模式的相关参数的修改方法:

1. 是否打开vrdp(default为on):
VBoxManage modifyvm name [--vrdp on|off]

2. 修改vrdp的端口, 方便一台机器多个VM
VBoxManage modifyvm name [--vrdpport default|<port>]

3. 修改vrdp使用的IP(host机器的IP)
VBoxManage modifyvm name [--vrdpaddress <host>]


VBoxHeadless还有一些功能是VBoxManage无法做到的, 请见: VBoxHeadless --help

VirtualBox下VM使用独立IP

为在VirtualBox下的VM使用独立IP, 在内核需要增加如下选项:

Linux Kernel Configuration: 802.1d Support
Networking --->
Networking Options --->
<*> 802.1d Ethernet Bridging

Linux Kernel Configuration: 802.1d Support
Networking --->
Networking Options --->
<*> 802.1d Ethernet Bridging

安装的软件:
app-emulation/virtualbox-bin-2.2.0
app-emulation/virtualbox-modules-2.2.0
net-misc/bridge-utils-1.4

在没有操作前, 有如下正在使用的网络设备:
jessinio@niolaptop /etc/runlevels $ ifconfig -s
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 5283 0 0 0 5444 0 0 0 BMRU
lo 16436 0 2 0 0 0 2 0 0 0 LRU

而共有的网络设备如下:
jessinio@niolaptop /etc/runlevels $ ifconfig -a -s
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 5299 0 0 0 5461 0 0 0 BMRU
lo 16436 0 2 0 0 0 2 0 0 0 LRU
sit0 1480 0 0 0 0 0 0 0 0 0 O
wlan0 1500 0 0 0 0 0 0 0 0 0 BM
wmast 0 0 0 0 0 0 0 0 0
0 [NO FLAGS]


不知道什么跑出了一个sit0的网卡, 用法未知, 只看到IPv6-in-IPv4

现在还没有任何的bridge:
jessinio@niolaptop /etc/runlevels $ brctl show
bridge name bridge id STP enabled interfaces

配置bridge如下:
jessinio@niolaptop /etc $ sudo /sbin/brctl addbr br0
jessinio@niolaptop /etc $ /sbin/brctl addif br0 eth0
jessinio@niolaptop /etc $ sudo /sbin/brctl addif br0 eth0
jessinio@niolaptop /etc $ sudo /sbin/brctl stp br0 on
jessinio@niolaptop /etc $ sudo brctl show
bridge name bridge id STP enabled interfaces
br0 8000.001d606fd392 yes eth0

为br0网络设备分配IP:
jessinio@niolaptop /etc $ sudo dhcpcd br0
br0: dhcpcd 4.0.13 starting
br0: broadcasting for a lease
br0: offered 192.168.0.101 from 192.168.0.1
br0: acknowledged 192.168.0.101 from 192.168.0.1
br0: checking 192.168.0.101 is available on attached networks
br0: lease of 4294967295 would overflow, treating as infinite
br0: leased 192.168.0.101 for infinity

这时在host中测试网络正常, 转到配置VM:
为virtualbox加入Modules:
# modprobe vboxdrv
# modprobe vboxnetflt

加入后, 如下:
jessinio@niolaptop /etc $ sudo lsmod |less
Module Size Used by
vboxnetflt 64888 1
vboxdrv 89000 2 vboxnetflt


这时VM的settings如下:
* NetWork -> Attached to: -> Bridge NetWork, adapter为eth0

这时重启VM, 使用dhclient分配到IP!

这时主机内的网络配置如下:

jessinio@niolaptop /etc $ ifconfig -a -s
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
br0 1500 0 1649 0 0 0 1198 0 0 0 BMRU
eth0 1500 0 9214 0 0 0 8809 0 0 0 BMRU
lo 16436 0 69 0 0 0 69 0 0 0 LRU
sit0 1480 0 0 0 0 0 0 0 0 0 O
vboxn 1500 0 0 0 0 0 0 0 0 0 BM
wlan0 1500 0 0 0 0 0 0 0 0 0 BM
wmast 0 0 0 0 0 0 0 0 0
0 [NO FLAGS]

多出了一个vboxnet0(vboxn)


参考文档:
* http://en.wikipedia.org/wiki/Network_bridge
* http://www.gentoo-wiki.info/VirtualBox
* http://www.gentoo-wiki.info/Bridging

Sunday, July 12, 2009

使用virtualbox创建Linux测试环境

为方便主机与guest机之间通信, 又不想到如下工作:
1. 安装虚拟网卡(bridged 之类的)
2. 安装guest additions之类的

主机与guest机可以ssh就行了(host 与 guest都是linux)

很方便的配置如下选项:

VBoxManage setextradata NameOfYourGuest
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata NameOfYourGuest
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata NameOfYourGuest
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

重启一下virtualbox后, 有如下端口被使用了:
jessinio@niolaptop ~/.stardict $ netstat -an|grep 2222
tcp 0 0 0.0.0.0:2222 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:52626 127.0.0.1:2222 ESTABLISHED
tcp 0 0 127.0.0.1:2222 127.0.0.1:52626 ESTABLISHED

使Virtualbox默默地在后台运行:

VBoxManage startvm ubuntu -type vrdp

备份vdi文件, 再加上rsa公钥, 完美的linux测试环境创建完了

tag: virtualbox bridged network vrdp

Mount时是否需要增加ACL?

配置软件时, 在手册上看到需要为文件系统增加acl的配置:
如:
UUID=d4cfe48c-4332-4357-bcc8-1ed977449e89 / ext3
acl,relatime,errors=remount-ro 0 1

查看mount的手册关于这点的说明:
acl / noacl
Support POSIX Access Control Lists (or not).
这就怪了. linux下的ext3不是默认使用Posix access control的吗, 还要增加才使用的?

为了测试这个是否有区别, 做如下测试:

1. 在没有使用acl的Mount参数时, 即使用默认的参数:

UUID=4da85cc9-48ad-4ab0-947e-13fba2d02684 / ext3
relatime,errors=remount-ro 0

参数tune2fs -l /dev/sda1得到的信息为:
Filesystem features: has_journal ext_attr resize_inode dir_index
filetype needs_recovery sparse_super

2. 使用acl参数时:
sudo mount -o remount,rw,acl /

结果使用acl后的Filesystem features还是与没有使用一样.

总结:
* ext在没有声明去掉acl的情况下, 默认使用acl

tag: tune2fs

Friday, July 3, 2009

[工作] linux下的hibernate

之前一直使用pm-suspend挂起机器的, 从没有理会过hibernate.

昨晚朋友提出了一个hibernate问题, 就随便学习了一把.

他的问题是:
* OS为ubuntu, 本来gnome和pm-hibernate都可以正常
* 但是增加swap区后就只能hibernate而不能恢复了!

系统上有两个包可以做到hibernate的, 如下:
1. sys-power/pm-utils 其中的pm-hibernate
2. sys-power/suspend 其中的s2disk

两者有什么关系呢, 从arch的wiki中看到这样一段话:
However, this is highly likely to fail, because some services could
need to be stopped, some modules unloaded, etc. Thus it is probably
necessary to resort to a userspace tool which calls internally s2disk,
like Pm-utils since version 1.1 (which is now in core) or
hibernate-script.

看来, 是层次的不同.

在自己的电脑上也试了一把pm-hibernate(从来没有使用过), 可以正常hibernate, 就是说,可以正常把RAM内容写入disk了. 但是不能恢复!

其实在hibernate后, 要启动时恢复旧的swap内容, 是需要在内核启动时使用一指令的, 如下:
* resume=/dev/sda5
/dev/sda5为本人notebook的swap, 这就可以正常恢复

自己notebook的问题处理好后, 回归到朋友的ubuntu, 查看了一把/boot/grub/menu.list,
没有发现使用了resume指令, 那之前ubuntu是怎么做到的呢, ubuntu又玩出魔法了, 我顶!

早上打开朋友的notebook, 发现grub Error了. 看来朋友放弃找问题基本的想法了. 那我也算了, 反正gentoo下我了解了,
至以ubuntu的下的魔法, 下次再找吧

BTW: hibernate后, Notebook的硬盘位置很热!! gentoo很清净

[生活] 测试email发布blog

测试tag和文章内容

--
做事要一步一个脚印
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
软件事业部 - 研发管理中心 - SPEG http://trac.rdev.kingsoft.net/kspeg
Mr. Jessinio - 梁庆喜 liangqingxi@kingsoft.com 13427766914
邮编: 519015
地址: 珠海市吉大石花西路62号 F7
电话: 0756-3335688 - 2758
传真: 0756-3335268
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

身体是革命的本钱!!
http://jessinio.blogspot.com