2012-01-13

VMWare Player

1. Share folder

Share folder is a better option in order to share files between Windows and virtual machine Linux. It's better than  use Samba. In order to use Share folder, you don't have to have any virtual network.

2. Virtual network:

The host-only network is not necessary. You can use NATed interface to allow the virtual machine to access outside world. Give the host VMnet interface an IP address of the same segment of virtual machine, then the host can access virtual machine. For NATed interface, there's always a special IP address reserved as the gateway for the network segment.

2011-01-20

Understanding /proc (quote)

When it comes down to it, /proc is a filesystem. Although it does not represent any physical device, you can still mount it and unmount it as you please. It contains a multitude of valuable information regarding the processes you are running, as well as the hardware you have hooked up to your computer (although in recent years, /sys has been devised by the Kernel folks to represent the hardware hierarchy and export device information ). You can see which modules you have loaded, how long your system has been up, and the memory usage of processes on your system. In fact, every single process running has an entry, or directory, inside /proc. As you can see, /proc can be a very powerful asset. But before you can use it, you need to mount it.
Note: Many of the examples in this guide require root access to work correctly. If you don't have root access on your Linux box, get it. We'll wait.
{mospagebreak title=Mounting /proc}

Mounting /proc

As mentioned earlier, /proc is a filesystem. And, like all filesystems, you need to mount it. In theory, you could mount it anywhere, but the standard is to mount it in /proc.
Most systems have /proc mounted by default in /etc/fstab, but just in case, make sure that it's mounted by doing:

$ mount

Note: Throughout this guide, $ indicates a command to be run from a normal user's shell, and # indicates something that must be run from a root shell.
If the output contains a line such as:


proc on /proc type proc (rw)

then you are fine. If not, follow the instructions below.
First, make sure that you have a directory called /proc:

# if ! test -f /proc
then
mkdir /proc
fi

Then, add a line to the file /etc/fstab such as this:

proc  /proc proc  defaults  0 0

Now, mount it:

# mount proc

You're now ready to play around with /proc.
{mospagebreak title=Viewing Process Information}
Each time a new process is created, an entry in /proc is created. The name of the directory entry corresponds to the process identification number (PID) of the created process, so, for example, a process with a PID of 8695 will have a corresponding directory entry of /proc/8695/.
nside /proc/8695/ (replace 8695 with a real PID on your system), you'll see something like:

auxv  exe  mem  root  statm
cmdline fd/  mounts seccomp status
cwd  loginuid oom_adj smaps task/
environ maps  oom_score stat  wchan

Note: The entries ending in �/� are directories.
As you can see, a lot of data about each process is stored. Let's go through the basics:
cmdline - This contains information about the actual command line invoked to start this process. This is a down and dirty way to find out what this process is actually doing.
The best way to access this info is by using a tool such as 'strings' which will display any printable information from a binary file:

$ strings cmdline
/opt/OpenOffice.org/program/soffice.bin
private:factory/swriter

cwd - This is a symlink to the working directory from which the process was started. For example, I started OpenOffice.org (PID 8695) in my home directory, so cwd points to /home/akissner.
environ - This file contains the environment of the process, sorted in to key=value pairs. There is no particular order, so for a human readable output, you would want to do something like:

$ strings environ | sort | less

This will sort the output alphabetically, sorted by the key.
exe - 'exe' is another symlink, this time to the actual binary itself. So if you wanted to run another copy of the process, you could do:

$ /proc/8695/exe

fd/ - This is a tricky one. It is a subdirectory of symbolic links to open file descriptors in use by the program. /proc/XXXX/fd/ will always contain, at the very least, the links 0, 1, 2. These correspond to STDIN, STDOUT, and STDERR, respectively.
Using this, you can see what files a program is manipulating. This is one way that you can find out where a browser keeps its cache, or a text editor keeps its temporary files.
loginuid - A little background is required before I can explain this one. This isn't completely technically correct, but it's good enough for a Cliff Notes summary.
Each process is represented in the kernel as a structure of type "task". This task structure keeps track of a lot of information about a process, including the PID, the UID of the user who started it, its children, and countless other things. One such attribute is the field "loginuid". The loginuid shows which account a user gained access to the system with. The /proc/XXXX/loginuid shows this value.
maps - 'maps' is one of the most complicated things inside of the /proc filesystem. Suffice it to say that one must have a basic grounding in the inner workings of the kernel and memory management to fully appreciate the information inside of /proc/XXXX/maps.

08048000-080a1000 r-xp 00000000 08:06 35310321   /opt/OpenOffice.org/program/soffice.bin
080a1000-080a6000 rw-p 00058000 08:06 35310321   /opt/OpenOffice.org/program/soffice.bin
080a6000-084b6000 rw-p 080a6000 00:00 0          [heap]
b0e2d000-b0e3d000 rwxp b0e2d000 00:00 0 
b0e4d000-b0e81000 r--p 00000000 08:06 86555296   /opt/OpenOffice.org/help/en/picture.db
b0e81000-b0ec4000 rw-p b0e81000 00:00 0 
b0ec4000-b0f34000 rwxp b0ec4000 00:00 0 
b0f42000-b0f62000 rwxp b0f42000 00:00 0 
b0f62000-b0f7d000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b0f7d000-b0f98000 r--s 00000000 00:07 21004324   /SYSV00000000 (deleted)
b0f98000-b0fb3000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b0fb3000-b0fce000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b0fce000-b0fe9000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b0fe9000-b1004000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b1004000-b101f000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b101f000-b103a000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b103a000-b1055000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b1055000-b1070000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b1070000-b108b000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)
b108b000-b10a6000 r--s 00000000 00:07 20971555   /SYSV00000000 (deleted)

Shown above is a sample listing for my OpenOffice.org process (PID 8695). As you can see, OpenOffice.org uses a lot of memory!
The first column lists, in hexadecimal, the address range for the mapped memory. The next column lists the permissions on that section of memory. This can either be r, w, x, p, or s, which is read, write, execute, private, and shared, respectively. The third column is the offset, and the fourth column lists the device where the memory is mapped from. The device column is split into major:minor, where major is the corresponding major device number (this has to do with which driver is assigned to which device) and minor number (which has to do with the number of devices a driver is representing). Using information from /proc/devices, you can decipher the device being used. The next column is the inode number of the file from which the memory is being mapped. Last is the pathname of the file.
mem - This cannot be used directly from the command line for anything. You can call the open() and read() system calls on it to read the pages of a process's memory, but most people will go their whole life without ever needing to to this.
mounts - In most cases, this is the same thing as /proc/mounts, which displays mounted filesystem information.
oom_* - These files control the system's behavior if it meets an Out of Memory (OOM) condition. Generally, you won't need to mess with this. The oom_adj file can be used to make a process unkillable during OOM.
root - This is a symlink to the process's root directory. Normally, this will be '/'. But if, for example, a process were started inside a 'chroot jail', then /proc/XXXX/root might point to "/foo/jail".
seccomp - Changing the value in this file from '0' to '1' will send the process in to "seccomp" mode. Seccomp is a sandbox mechanism for the kernel, which restricts a certain process from executing most system calls. This is a security feature, which you will probably never use.
smaps - This file provides detailed memory consumption information for a process.
stat - Like the name suggestions, /proc/XXXX/stat contains information about a process's status. In fact, modern versions of ps (namely those coming from the 'procps' package) use /proc/XXXX/stat for their information. The output is not formatted, and looks like this:

8695 (soffice.bin) S 8666 3234 3180 1025 3224
 8396864 68 0 8 0 27 31 0 0 16 0 1 0 51495018 134680576 8844
 4294967295 134512640 134875180 3216856352 4154390430 582 0
 0 4096 2076206327 0 0 0 33 1 0 0

The best place for information on these fields is the proc(5) manpage.
statm - This file gives memory status information. This file gives information in page-sized blocks. The columns are size (total), rss (resident set size), shared pages, text (the executable code), library code, data/stack size, and dirty pages. The last column is no longer used in the 2.6 kernel series.
status - This file contains the information given in stat and statm, but in a much more human-friendly form. Each row is labeled, and the names are for the most part self-explanatory.
task - task is a directory, containing a directory (with the same name as the PID) that contains all the information inside /proc/XXXX (except for task/). It's a bit of a pointless directory, in my opinion.
wchan - The WCHAN data for a process is the kernel function where the process is currently blocking.
That covers things for this first installment in a multi-part series on understanding the /proc filesystem. Part 2 will cover using /proc to find information about the devices attached to your system.

2011-01-19

Set Eclipse to Find Target Libraries Correctly

When doing remote debug with gdbserver, Eclipse needs to know the location of the libraries of target. There's no direct place to tell Eclipse. This can be done by puting the information in 'gdbinit' file:

  set solib-absolute-prefix /path/to/target/nfsroot

And tell Eclipse to read this file in Debug Configurations dialog tab Debugger -> Main, by item "GDB command file:".
This also resolves some error messages on target reported by gdbserver like below:

# gdbserver 192.168.1.250:10000 ./controller
Process ./controller created; pid = 588
Listening on port 10000
Remote debugging from host 192.168.1.2
gdb: error initializing thread_db library: version mismatch between libthread_db and libpthread
gdb: error initializing thread_db library: version mismatch between libthread_db and libpthread
gdb: error initializing thread_db library: version mismatch between libthread_db and libpthread
gdb: error initializing thread_db library: version mismatch between libthread_db and libpthread
gdb: error initializing thread_db library: version mismatch between libthread_db and libpthread
gdb: error initializing thread_db library: version mismatch between libthread_db and libpthread

2010-10-22

Boot Ubunto into Text Mode

Modify '/etc/default/grub' to replace "quiet splash" with "text" as below:

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX=""
...

Then run command to make it effective:

sudo update-grub

Reboot to check.

2010-10-21

Redirect syslog from busybox system to Ubuntu

Busybox syslogd uses '/etc/syslog.conf' as the configuration file. From this configuration file, can configure syslogd redirect the log messages to remote host.

- Settings of embedded system

  Check '/etc/syslog.conf' file for the configuration:

  * Make sure the 'remote' is included in variable 'DESTINATION'.

  * Make sure the variable 'REMOTE' is defined and put the right IP address of the remote syslog server

  example:

     DESTINATION="remote"
     REMOTE=<ip-of-remote-host>:514

  Restart the syslogd daemon after configuration.

- Settings of Ubuntu

  Note: assuming 'rsyslog' is used as the syslog server.

  Check '/etc/rsyslog.conf' file for the configuration:

  * Make sure rsyslog accepts remote syslog message via UDP and TCP by uncommenting out below lines:

   $ModLoad imudp
   $UDPServerRun 514

   $ModLoad imtcp
   $TCPServerRun 514

  Restart 'rsyslog' on Ubuntu after configuration. Now Ubuntu should be able to accept syslog message from target system.

- Customize the syslog on Ubuntu

1. Use simple log format

  By default, the syslog message on Ubuntu includes timing, host, and application name as prefix. Sometimes it's annoying. Customize to use simple format without these message:

  Change '/etc/rsyslog.conf' file to add a new line like this to define a new format:

   $template SimpleFormat,"%msg:::drop-last-lf%\n"

  Now you can change '/etc/rsyslog/50-default.conf' to use this format.

2. Use separate log file for particular application or host

   You may want to use separate log file for your own application, or for message from particular host. This can be done by adding configure to '/etc/rsyslog/50-default.conf' like this:

      if $programname == 'controller' then /var/log/controller.log;SimpleFormat

      if $HOSTNAME != 'localhost' then /var/log/board.log;SimpleFormat

   The first line makes the rsyslog daemon to use separate file '/var/log/controller.log' for all messages from application named 'controller' using the simple format defined above.

   The second line makes the rsyslog daemon to use separate file '/var/log/board.log' for all message coming from remote machines using the simple format defined above.





2010-10-20

PuTTY + Xming 远程使用 Linux GUI


  在家里的PC上用VMWare做了一个Oracle Enterprise Linux虚拟机做数据库,虚拟机OEL没启用图形界面,因此需要在PC上装一个X Window Server才能使用GUI。
    看Wiki系统地了解了一下X Window System。X Window System(常被简称为X11或X),是一套基于X display protocol的windowing system,X GUI环境的功能包括窗口的绘制、移动,以及与鼠标、键盘等输入设备的交互。X 协议当前版本为MIT在1987年9月制定的11版----这就是X11的来历,最新版则是2008年9月发布的X11R7.4。
    X采用C/S模型:一个X server 和多个应用程序(client)通信。server接收client的请求绘制窗口,并将来自鼠标、键盘等设备的输入传递给client。
    初学X的用户经常被描述如何远程使用Linux GUI环境的文档搞糊涂:Linux主机上的应用程序被称为client,而用户终端计算机被称为server,看上去好像说反了。实际上,X是从程序结构而非用户或硬件环境的角度来描述的,在用户终端上工作的X server为应用程序提供服务,所以被看作server,而Linux主机上的应用程序接受服务,所以被看作client。
    X server和client可以位于同一计算机上,例如在Linux主机上使用KDE等桌面环境就是这种模式。X server也可以通过同构网络、异构网络或Internet与client通信。
    X server与client之间的通信是不加密的,这个问题可以通过SSH解决。SSH是Secure Shell的简称,SSH可以看作是通信被加密压缩版的telnet。我需要用到SSH的forwarding功能,当X server与client所在计算机都支持SSH协议时,X server与client之间不安全的TCP/IP连接可以转送到(forwarding)二者之间建立的SSH连接上。
    说了一堆概念,现在可以挽起袖子干活了。Linux主机(A, IP: 192.168.1.201)和Windows客户机(B, IP: 192.168.1.101)都已经装好了,我要做的就是在 B 上安装一个X server,一个SSH客户端,在A上启用SSH的X11 forwarding。
1 安装配置B上的X server
X server我选择的是Xming,这是一个免费的windows平台上的X server。需要安装两个组件,主程序和字体
  • Xming X server, Xming-6-9-0-31-setup.exe
  • Xming Fonts, Xming-fonts-7-3-0-22-setup.exe
Xming.install.03.png
Xming.install.05.png   
    运行XLaunch配置Xming X server,将配置保存为.xlaunch 文件。使用默认设置即可。
Xming.config.01.png    Display 代表一套 I/O 设备,包括显示、鼠标、键盘;Display Number 就是这套 I/O 设备的代号;同时 Display Number 还决定了 Xming X server 的 TCP 端口,端口号为 6000 + Display Number。Linux 主机上的应用程序通过此端口建立与 Xming X server 的连接。
Xming.config.02.png
Xming.config.03.png
Xming.config.04.png
       将配置保存为Xming.display.0.xlaunch。双击此文件就能启动X server,系统栏里多了一个Xming的图标。
2 安装配置B上的SSH
    SSH客户端使用PuTTY,PuTTY是freeware+greenware,就一个exe文件。
PuTTY.config.01.png
配置 Session:配置主机IP,连接方式为SSH
PuTTY.config.02.png
Connection\Data:保存连接使用的用户名
PuTTY.config.03.png
Connection\SSH\X11:Enable X11 Forwarding,X display Location 为 localhost:0,这里的 0 就是配置 Xming X server 时指定的 Display Number。
PuTTY.config.05.png 
保存设置为 VSERVER01。
3 配置A上的SSH
    要允许Linux主机上的SSH X转发,查看 /etc/ssh/sshd_config 文件,加入以下一行,
X11Forwrding yes
    至此配置完成。在B上使用PuTTY连接到A,输入xclock &,可以看到X server工作的效果了。

参考
【2】SSH
【3】Xming
【4】PuTTY
【5】Putty + Xming 方便的远程Linux GUI
【6】Xming + PuTTY 在Windows下远程Linux主机使用图形界面的程序
http://hi.baidu.com/mooncold/blog/item/8e0dfddc4f29a3a4cd11663a.html

连接ssh缓慢的问题

sshd收到客户端连接请求时默认会做域名反查,反查过程如果慢,用户就会感觉连接慢。
1.最直接的办法是修改sshd的配置,UseDNS项改为0,重启sshd 。
2.修改hosts或resolv.conf , 使得sshd能够快速进行域名反查。