2016年6月1日 星期三

linux tmux install from source

Build from source
~~~~~~~~~~~~~~~

tmux depends on libevent 2.x. Download it from:

 http://www.monkey.org/~provos/libevent/

 
cd libevent/
./configure --prefix=/home/robert/opt
make && make install
 

You may need to modify:
LD_LIBRARY_PATH ="~/opt/lib:$LD_LIBRARY_PATH "
 
# For tmux 2.9a
cd tmux/

export CPPFLAGS='-I/home/robert/opt/include' LDFLAGS='-L/home/robert/opt/lib'
 
autoconf

./configure --prefix=/home/robert/opt

make
make install


Tmux config [~/.tmux.conf]
~~~~~~~~~~~~~

Make it screen-key compatible & vim-like split :

> cat examples/screen-keys.conf examples/vim-keys.conf >~/.tmux.conf

# If using Ubuntu package:
# cat /usr/share/doc/tmux/example_tmux.conf >.tmux.conf

Append to do my customization:

> vi ~/.tmux.conf

############################################
#robert

# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."

# kill pane (overwrite lock-server in screen-keys.conf)
unbind x

bind x kill-pane

# window previous/next/rename
unbind -n F10
bind -n F10 command-prompt "rename-window %%"
unbind -n F11
bind -n F11 previous-window
unbind -n F12
bind -n F12 next-window

# Set status bar
set -g status-bg black
set -g status-fg white
set -g status-left ''
set -g status-right '%H:%M %d/%b/%Y'

# Highlight active window
# before tmux 2.9
#set-window-option -g window-status-current-attr bright
#set-window-option -g window-status-current-bg blue
#set-window-option -g window-status-current-fg yellow
#set-window-option -g window-status-fg red

# after tmux 2.9
set -g window-status-current-style bright,bg=blue,fg=yellow
set -g window-status-style fg=red

# window-status format -- default is ‘#I:#W#F’
set -g window-status-format '#I #W '
set -g window-status-current-format '#I #W '

# new windows and pane split keep your current directory
bind-key c new-window -c "#{pane_current_path}"
bind s split-window -v -c "#{pane_current_path}"
bind v split-window -h -c "#{pane_current_path}"

# swap window with the left/right window
unbind -n F7
bind -n F7 swap-window -t -1
unbind -n F8
bind -n F8 swap-window -t +1




For more STYLES, search STYLES in "tmux man".



Tutorial
~~~~~~~

Help:
CTL-a ?


1. Session

You create a session.

> tmux
> tmux ls
0: 1 windows (created Sat Dec 12 15:04:45 2015) [143x38] (attached)

Detach (but not delete) this session:
CTL-a d

Attach to previous session:
> tmux a


2. Window

You can have multiple windows.
But only one window can show at a time.

Create a new window:
CTL-a c

Go to previous window:
CTL-a p

Go to next window:
CTL-a n       (or space)

Rename a window:
CTL-a A

Kill window:
CTL-a K


3. Pane

You can have many panes in a window.
And panes in a window can show at the same time.

Vertically splitting a window to create a pane:
CTL-a v

Horizontally:
CTL-a s

Move the current pane to a new window:
CTL-a !



5. Server

Kill tmux server:
CTL-a \



Tmux script for project
~~~~~~~~~~~~~~~~~~

My tmux script will 
* create a session
* create several windows


> vi tmux_open.sh

###########################
#!/bin/bash

tmux start-server
tmux new-session -d -s OK

tmux rename-window win1
tmux new-window -n win2 -c ~/work/xx1
tmux new-window -n win3 -c ~/work/xx2 
tmux select-window -t 0

tmux attach



ref:
How to add libraries path to the ./configure command?
http://askubuntu.com/questions/386315/how-to-add-libraries-path-to-the-configure-command
* 進化版screen
http://forum.j2eemx.com/forum44/thread9789.html
* Tmux 教學 + Screen 到 Tmux 的無痛轉換
http://blog.longwin.com.tw/2011/04/tmux-learn-screen-config-2011/
* A sample to customize status bar
  http://dotshare.it/dots/830/
* simple tmux configuration
http://blog.hawkhost.com/2010/07/02/tmux-%E2%80%93-the-terminal-multiplexer-part-2/

2014年3月26日 星期三

Hide GPT partitions from Windows

You want to hide Linux GPT partitions from Windows.

Under Ubuntu:
1. Install GPT tool : gdisk
> sudo apt-get install gdisk

2. Set interested GPT partition attributes to Windows hide and no automount:
> sudo sgdisk -A <part>:set:62 <disk>
> sudo sgdisk -A <part>:set:63 <disk>
(62: hide ; 63: no automount)

As a note, use "-A <part>:clear:<attribute_bit_pos>" to clear a attribute bit.

robert$ sudo sgdisk /dev/sdc -A 5:set:62
The operation has completed successfully.

robert$ sudo sgdisk /dev/sdc -A 5:set:63
The operation has completed successfully.

3. Print the partition#<part> attributes:
> sudo sgdisk -A <part>show <disk>

robert$ sudo sgdisk -A 5:show /dev/sda
5:62:1 (hidden)
5:63:1 (do not automount)




2012年12月24日 星期一

[debian] disable pc beeper

Just append one line to /etc/modprobe.d/blacklist :


> echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist


> reboot


Ref:

http://arsgeek.hubpages.com/hub/How-to-turn-off-the-annoying-system-beep-in-linux-DebianUbuntu

[debian] How to move /etc into ramfs easily


> vi /etc/init.d/rcS

Add these lines before "exec /etc/init.d/rc S":

echo "* Initialize RAM /etc..."
[ ! -d /etc-model ] && mkdir /etc-model
mount --rbind /etc /etc-model
mount -n -t tmpfs none /etc
cp -a /etc-model/* /etc/

> vi /etc-model/init.d/umountfs

Add "/etc" in the line:
case "$MTPT" in |/proc|/dev/|..........|/etc)


基本上它運作的邏輯是: 開機時, rcS會自動把 /etc 掛成RAM,然後把舊的 /etc (位在/etc-model)copy進來。
所以之後要手動改系統預設的設定,都是要改 /etc-model 底下的。

2012年3月27日 星期二

u-boot dhcp request, no ack

In u-boot> dhcp

discover ->
offer <-
request ->

no ack!

discover, offer, request, loop...

While the same board can run dhcp client without problem in Linux.

It turns out that the problem is on dhcp server: some dhcp servers will ignore too fast request.

I found this fix to u-boot:

Just put a short delay (50~100ms) between offer and request.

2012年2月24日 星期五

"route: SIOCDELRT: No such process"

"route: SIOCDELRT: No such process"

this message comes from "route del"

ref:
http://lists.busybox.net/pipermail/busybox/2010-December/074073.html

2012年2月20日 星期一

Invalid FAT entry (uboot)

Did you encounter

Invalid FAT entry

when using fatload or fatls command in uboot?
possibly the filesystem is corrupted (from the view of uboot).
For instance,

U-Boot > fatls mmc 0
2187544 uimage
Invalid FAT entry

1 file(s), 0 dir(s)

Try to format the partition to fat. (mkfs.vfat)
Copy origin files into it and try again.

2011年12月16日 星期五

2011年10月26日 星期三

get free memory size in kernel

Just paste this section to where you want to check:

{
#define K(x) ((x) << (PAGE_SHIFT - 10))
struct sysinfo si; \
si_meminfo(&si); \
printk("free=%lu k\n", K(si.freeram)); \
}

may need to include linux/mm.h

2011年6月26日 星期日

Use vim/cscope/ctags to navigate linux kernel

Install cscope:

sudo apt-get install cscope exuberant-ctags

Generate cscope and ctag file for x86:

##################################

#!/bin/bash
# File name: genctags.sh
# Usage: genctags.sh x86

LNX=.
ARCH=x86

if [ ! -z "$1" ];then
ARCH="$1"
fi

if [ "$2" != "tag" ];then

echo "Gen cscope file for $ARCH ..."
find $LNX \
-path "$LNX/arch/*" ! -path "$LNX/arch/$ARCH*" -prune -o \
-path "$LNX/include/asm-*" ! -path "$LNX/include/asm-$ARCH*" -prune -o \
-path "$LNX/tmp*" -prune -o \
-path "$LNX/Documentation*" -prune -o \
-path "$LNX/scripts*" -prune -o \
-path "$LNX/drivers*" -prune -o \
-name "*.[chxsS]" -print > cscope.files

cscope -b -q -k
fi

echo "Gen ctags file ($ARCH)..."

EXCLUDE_PATH=`find . -path "$LNX/arch/*" ! -path "$LNX/arch/$ARCH*" -prune`
EXCLUDE_PATH2=

for path in $EXCLUDE_PATH
do
EXCLUDE_PATH2="$EXCLUDE_PATH2 --exclude=$path"
done

ctags -R $EXCLUDE_PATH2

###############################################

For vim:


try it:
vim ./init/main.c

move the cursor to a symbol then...

ctrl + ] -- goto definition
[ + d -- show macro definition (if it is a macro)
ctrl + o -- goto previous position
ctrl + i -- goto next position
ctrl + \ s -- list usages
ctrl + shift + space -- list usages and pops a select to a new window (ctrl+w o to close)

search tag "main":
: ta main

search tags including "main":
:ta /main

search tags beginning with "main":
:ta /^main

Ref:

2011年6月9日 星期四

2011年5月19日 星期四

gcc include paths and their order

robert@debian-rbt:~$ `gcc -print-prog-name=cc1` -v -I/home/robert/
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/home/robert/
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.5/include
/usr/lib/gcc/i486-linux-gnu/4.4.5/include-fixed
/usr/include

End of search list.

Ref:

2011年3月1日 星期二

install ubcd to usb disk

1. Mount ubcd503.iso to /mnt
-> sudo mount -o loop ubcd503.iso /mnt

(Read /mnt/ubcd/tools/linux/ubcd2usb/readme.txt)

2. Create mbr:
-> cd /mnt/ubcd/tools/linux/ubcd2usb
-> sudo dd if=mbr.bin of=/dev/sdX

(replacing X with your USB key drive letter)

3. Format your usb disk to fat32
-> sudo mkfs.vfat -F 32 /dev/sdX1

4. Mount your usb disk and copy all files of the extracted UBCD iso to your USB thumb drive
-> sudo mount /dev/sdX1 /usbmnt
-> sudo cp -rf /mnt/* /usbmnt

5. Install bootloader syslinux:
-> cd /mnt/ubcd/tools/linux/ubcd2usb
-> sudo ./syslinux -s -d /boot/syslinux /dev/sdX1
(install syslinux to a directory relative to /boot/syslinux on the device)

6. make the partition bootable:
-> sudo parted /dev/sdX set 1 boot on

Ref:
ubcd-extracted/ubcd/tools/linux/ubcd2usb/readme.txt

2011年2月21日 星期一

java jar signing

以下用top-down的方式講述如何對一個 jar 簽章:

keystore & key 說明:
=============

java 將用來簽章的key存在keystore中,每個key包含private key(密秘)和 public-key certificate(公開)。

一個 keystore檔案就是一個專存這些key的資料庫,而用 alias 來索引其中的一個 key。

keystore檔有一個密碼保護,而其中的每個key也可以有(也可以不設)自己的密碼保護。


簽章操作:
=======

-> jarsigner -keystore my.keystore -storepass 123456 myprogram.jar myprogram

(若這個key有設密碼保護,會再要求輸入密碼;或是直接在 jarsigner 後多加參數-keypass xxxx)

這樣就可以用 my.keystore 中的那個 alias 為 myprogram 的key,對 myprogram.jar 簽章。


如何產生keystore 和 key:
================


-> keytool -genkey -alias myprogram -keystore my.keystore -storepass 123456 -validity 1800 < myprogram.keyconf


(如果沒有先做好myprogram.keyconf,則輸手動輸入key的資訊)
這樣會產生一個 keystore 檔 my.keystore,裡面有一個 alias 叫 myprogram 的 key,此 key 的有效期限為1800天。

Ref:
Signing and Verifying JAR FilesJAR Signing

2011年2月17日 星期四

map dir to msys

Hot to map a dir from host Windows to msys ?
Ans:

Edit msys/1.0/etc/fstab, for example:

f:/mingw /mingw
f:/jdk21 /java

You also need to create the corresponding dir in msys. In this example,
mkdir /mingw
mkdir /java

2011年1月13日 星期四

Run jnlp program as root (sudo)

In Linux, a non-root user usually clicks a jnlp link in a web browser or double-clicks a jnlp file to run a Java Web Start program.
The program has no root privilege.

How to run it as root ?
-> sudo javaws http://your-website/link.jnlp

or download the jnlp file and
-> sudo javaws ~/Test/link.jnlp

Reference:

2010年12月16日 星期四

JNLP and JNI native libraries

Topic: How to use JNLP to load jar files which include native libraries ?

1. Build native libraries
* HelloWorld.dll for Windows
* libHelloWorld.so for Linux (library name must be libXXX.so in Linux !!)

(How to build those native libraries ? see jni book)

2. Pack native libraries into jar

jar -cvf Linux32_lib.jar libHelloWorld.so
jar -cvf Win32_lib.jar HelloWorld.dll

3. Add tags in jnlp
(please replace ( with <)
(resources os="Windows">
(j2se version="1.5+"/>
(nativelib href="native/Win32_lib.jar"/>
(/resources>

(resources os="Linux">
(j2se version="1.5+"/>
(nativelib href="native/Linux32_lib.jar"/>
(/resources>

4. In code, explicitly load the library
System.loadLibrary("HelloWorld");
(windows->HelloWorld.dll ; linux -> libHelloWorld.so)

2010年12月2日 星期四

TCP Keepalive mechanism

RFC1122 says

"Implementors MAY include "keep-alives" in their TCP implementations, although this practice is not universally accepted. If keep-alives are included, the application MUST be able to turn them on or off for each TCP connection, and they MUST default to off." [1]


In C, use setsockopt() to set the following arguments on a specific socket [2]
* SO_KEEPALIVE: enable tcp keepalive
* TCP_KEEPCNT: overrides tcp_keepalive_probes
* TCP_KEEPIDLE: overrides tcp_keepalive_time
* TCP_KEEPINTVL: overrides tcp_keepalive_intvl

These settings are only for the current socket.

In Linux, to see the default values (OS-wide variables) of the later 3 options:
# cat /proc/sys/net/ipv4/tcp_keepalive_time
7200
# cat /proc/sys/net/ipv4/tcp_keepalive_intvl
75
# cat /proc/sys/net/ipv4/tcp_keepalive_probes
9

This means "wait for two hours (7200 secs) before sending the first keepalive probe, and then resend it every 75 seconds. If no ACK response is received for nine consecutive times, the connection is marked as broken." [2]


Ref:

2010年5月11日 星期二

[socket] set read/write timeout values for blocking socket

Set timeout to 10 seconds when doing read () or write () a blocking sock :

#define SOCK_RCV_TIMEOUT 10
#define SOCK_SND_TIMEOUT 10

void set_rw_timeout (int sock, int clear_timeout)
{
struct timeval rw_timeout;

memset (&rw_timeout, 0, sizeof (struct timeval));
rw_timeout.tv_sec = clear_timeout ? 0 : SOCK_RCV_TIMEOUT;

if (setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, &rw_timeout, sizeof (struct timeval))) {
fprintf (stderr, "setsockopt SO_RCVTIMEO failed\n");
}

memset (&rw_timeout, 0, sizeof (struct timeval));
rw_timeout.tv_sec = clear_timeout ? 0 : SOCK_SND_TIMEOUT;

if (setsockopt (sock, SOL_SOCKET, SO_SNDTIMEO, &rw_timeout, sizeof (struct timeval))) {
fprintf (stderr, "setsockopt SO_SNDTIMEO failed\n");
}
}

2010年4月26日 星期一

md5sum a directory

Generate:
find
(your-dir) -type f -print0 | xargs -0 md5sum >> (output-md5sume-file)

Verify:
md5sum -c (output-md5sum-file)


my example:

robert@robert-desktop ~/work/nbd-work/ttt $ ls
first second test

robert@robert-desktop ~/work/nbd-work/ttt $ find -type f -print0 | xargs -0 md5sum >> ~/Test/mydir.md5


robert@robert-desktop ~/work/nbd-work/ttt $ cat ~/Test/mydir.md5
d41d8cd98f00b204e9800998ecf8427e ./second
d41d8cd98f00b204e9800998ecf8427e ./first
7423d8fc12da81d779d0485b3d3fb67d ./test

robert@robert-desktop ~/work/nbd-work/ttt $ md5sum -c ~/Test/mydir.md5
./second: OK
./first: OK
./test: OK

robert@robert-desktop ~/work/nbd-work/ttt $ echo $?
0