Sharing

顯示具有 Ubuntu 標籤的文章。 顯示所有文章
顯示具有 Ubuntu 標籤的文章。 顯示所有文章

2013年10月9日 星期三

Rebuild Ubuntu Package

Reference

http://manpages.ubuntu.com/manpages/precise/man1/dpkg-buildpackage.1.html
http://www.debian.org/doc/manuals/maint-guide/index.en.html
http://debian-handbook.info/browse/stable/debian-packaging.html
http://askubuntu.com/questions/28372/how-do-i-get-the-source-code-of-packages-installed-through-apt-get
http://www.debian.org/doc/debian-policy/
http://debian-handbook.info/browse/stable/sect.becoming-package-maintainer.html


Rebuild Flow Example


Download Source Code


最簡單的方式是利用 apt-get source

$ sudo apt-get source python-twill
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Picking 'twill' as source package instead of 'python-twill'
NOTICE: 'twill' packaging is maintained in the 'Svn' version control system at:
svn://svn.debian.org/python-modules/packages/twill/trunk/
Need to get 255 kB of source archives.
Get:1 http://free.nchc.org.tw/ubuntu/ precise/universe twill 0.9-3 (dsc) [1,367 B]
Get:2 http://free.nchc.org.tw/ubuntu/ precise/universe twill 0.9-3 (tar) [242 kB]
Get:3 http://free.nchc.org.tw/ubuntu/ precise/universe twill 0.9-3 (diff) [11.5 kB]
Fetched 255 kB in 3s (64.5 kB/s) 
gpgv: Signature made Sun 04 Dec 2011 11:29:49 PM CST using DSA key ID 5E3619D3
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on ./twill_0.9-3.dsc
dpkg-source: info: extracting twill in twill-0.9
dpkg-source: info: unpacking twill_0.9.orig.tar.gz
dpkg-source: info: unpacking twill_0.9-3.debian.tar.gz
dpkg-source: info: applying 01_fix_history_path.patch
dpkg-source: info: applying 02_remove_ext.patch
dpkg-source: info: applying 03_no_setuptools.patch
dpkg-source: info: applying 04_fix_deprecated_ClientForm.patch
dpkg-source: info: applying 05_fix_missing_imports.patch

$ ll
total 268
drwxr-xr-x  3 eric_chen pjack   4096 Oct  9 15:39 ./
drwxr-xr-x 63 eric_chen pjack   4096 Oct  9 14:33 ../
drwxr-xr-x  9 root      root    4096 Oct  9 15:39 twill-0.9/
-rw-r--r--  1 root      root   11494 Dec 17  2011 twill_0.9-3.debian.tar.gz
-rw-r--r--  1 root      root    1367 Dec 17  2011 twill_0.9-3.dsc
-rw-r--r--  1 root      root  242291 Feb  9  2009 twill_0.9.orig.tar.gz

如果有 dsc 檔, 裡面含有 Link 時, 也可以用 dpkg-source 指令下載

$ dpkg-source -x twill_0.9-3.dsc 
gpgv: Signature made Sun 04 Dec 2011 11:29:49 PM CST using DSA key ID 5E3619D3
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on ./twill_0.9-3.dsc
dpkg-source: info: extracting twill in twill-0.9
dpkg-source: info: unpacking twill_0.9.orig.tar.gz
dpkg-source: info: unpacking twill_0.9-3.debian.tar.gz
dpkg-source: info: applying 01_fix_history_path.patch
dpkg-source: info: applying 02_remove_ext.patch
dpkg-source: info: applying 03_no_setuptools.patch
dpkg-source: info: applying 04_fix_deprecated_ClientForm.patch
dpkg-source: info: applying 05_fix_missing_imports.patch

Modify ChangeLog


$ sudo apt-get install devscripts
$ cd twill-0.9
~/twill-0.9/$ dch -v twill-0.9-3ubuntu1
# 或是用這個指令也可
~/twill-0.9/$ dch -i  # Increment the final component of the Debian release number

twill (0.9-3ubuntu1) precise; urgency=low

  * test rebuild

 -- eric_chen   Wed, 09 Oct 2013 15:40:31 +0800

twill (0.9-3) unstable; urgency=low

  * Add debian/patches/04_fix_deprecated_ClientForm.patch as ClientForm
    is now shipped with mechanize.
    + debian/rules:
      - Drop Depends on python-clientform.
    + debian/control:
      - Bump python-mechanize Depends to >= 0.2.0~.
  * debian/patches/02_remove_ext.patch:
    + Fix tests as well.
  * Add debian/patches/05_fix_missing_imports.patch.
  * debian/control:
    + Bump Standards-Version to 3.9.2. No changes needed.
  * Switch from now deprecated pysupport to dh_python2.
    + Drop debian/pyversions and debian/pycompat.
    + debian/rules:
      - Remove DEB_PYTHON_SYSTEM.
    + debian/control:
      - Add X-Python-Version field.
      - Bump python and cdbs versions.

Rebuild Package


先把需要的 package 裝一裝

$ sudo apt-get build-dep python-twill 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Picking 'twill' as source package instead of 'python-twill'
The following NEW packages will be installed:
  cdbs debhelper dh-apparmor dh-translations docbook-xml docbook-xsl html2text intltool python-scour xsltproc
0 upgraded, 10 newly installed, 0 to remove and 2 not upgraded.
Need to get 1,701 kB/2,781 kB of archives.
After this operation, 16.5 MB of additional disk space will be used.
Do you want to continue [Y/n]? y

開始 rebuild

~/twill-0.9$ debuild -us -uc
 dpkg-buildpackage -rfakeroot -D -us -uc
dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor): -D_FORTIFY_SOURCE=2
dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functions -Wl,-z,relro
dpkg-buildpackage: source package twill
dpkg-buildpackage: source version 0.9-3
dpkg-buildpackage: source changed by Arnaud Fontaine 
 dpkg-source --before-build twill-0.9
dpkg-buildpackage: host architecture amd64
 fakeroot debian/rules clean
...


$ ll
-rw-r--r--  1 eric_chen pjack  68498 Oct  9 15:42 python-twill_0.9-3ubuntu1_all.deb
drwxr-xr-x 10 eric_chen pjack   4096 Oct  9 15:42 twill-0.9/
-rw-r--r--  1 eric_chen pjack  17480 Oct  9 15:43 twill_0.9-3ubuntu1_amd64.build
-rw-r--r--  1 eric_chen pjack   1252 Oct  9 15:42 twill_0.9-3ubuntu1_amd64.changes
-rw-r--r--  1 eric_chen pjack  11468 Oct  9 15:42 twill_0.9-3ubuntu1.debian.tar.gz
-rw-r--r--  1 eric_chen pjack   1149 Oct  9 15:42 twill_0.9-3ubuntu1.dsc

2013年8月25日 星期日

How to know if running in virtual machine


有個好用的小工具可以

$ sudo apt-get install virt-what


# 如果是在 virtualbox 內
$ sudo virt-what
virtualbox

# 如果是在 vmware 內
$ sudo virt-what
vmware

# 如果是 Physical Machine, 就沒有任何 output
$ virt-what

2013年7月30日 星期二

apt-get update fail!

最近為了 apt-get update 老是失敗很苦惱, 會遇到以下幾個 error

Case 1:
W: Failed to fetch http://eu-west-1.ec2.archive.ubuntu.com/ubuntu/dists/precise-backports/multiverse/i18n/Index  No Hash entry in Release file /var/lib/apt/lists/partial/eu-west-1.ec2.archive.ubuntu.com_ubuntu_dists_precise-backports_multiverse_i18n_Index

Case 2:
Err http://ppa.launchpad.net precise/main i386 Packages
  404  Not Found

Case 3:
Get:56 http://free.nchc.org.tw precise-security/main TranslationIndex [726 kB]                                   E: Unable to parse package file /var/lib/apt/lists/partial/free.nchc.org.tw_ubuntu_dists_precise-security_main_i18n_Index (1)   

Case 4:
78% [62 Packages bzip2 0 B] [66 Packages 212 kB/1,640 kB 13%]                                                              469 kB/s 5sbzip2: (stdin) is not a bzip2 file.

網路上也有人遇到類似的問題, 但因為時間不同, 原因也不一定相同, 不過玩多了總會有心得
               
1. 原來的 repository 不太穩, 造成下載有問題, 可以試試看換另一個 respository

2. 公司內的 proxy cache 作怪
     i. 把 proxy 關掉
         /etc/apt/apt.conf
         /etc/apt/apt.conf.d/80proxy
     ii. 把 repository server 換成 ftp protocol ex: ftp://ftp.csie.chu.edu.tw/Ubuntu/archive/

3. 你新增的 ppa link 有問題
    把這個目錄下的檔案內容都先用 "#" mark 起來, 再一個一個開啟, 試試看那一個打開後就會讓 apt-get update 失敗
    /etc/apt/source.list.d/

4. 你所在的網路就是十分不穩, 加上一個 proxy 可能會有幫助
    在這個檔案內 /etc/apt/apt.conf.d/80proxy, 加上下面這行

    Acquire::http::Proxy "http://:8080";

    8080 是 proxy server 的 port number, 一般是 8080, 視情況改掉

5. apt-get 的內容亂掉了, 那就請參考

https://help.ubuntu.com/community/PackageManagerTroubleshootingProcedure
https://answers.launchpad.net/ubuntu/+source/update-manager/+question/207473
https://help.ubuntu.com/community/AptGet/Howto


另外把一般修復的流程寫成 script, 最後一行 dist-upgrade 視個人需要打開, 打開後會主動更新 linux kernel
#!/bin/bash
sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available
sudo rm -rf /var/lib/dpkg/updates/*
sudo rm -rf /var/lib/apt/lists
sudo mkdir /var/lib/apt/lists
sudo mkdir /var/lib/apt/lists/partial
sudo apt-get clean
sudo apt-get update
sudo dpkg --clear-avail
sudo dpkg --configure -a
sudo apt-get install -f
sudo apt-get update
#sudo apt-get dist-upgrade


2013年6月25日 星期二

DenyHosts: Remove / Delete an IP address


原來 Ubuntu 裡面有一個 service 叫 DenyHost, 會主動更新 /etc/hosts.deny
相關文章如下

http://www.cyberciti.biz/faq/linux-unix-delete-remove-ip-address-that-denyhosts-blocked/
http://denyhosts.sourceforge.net/faq.html

cron-apt


今天為了找一個 dpkg 被 lock 的問題,意外發現系統有裝 cron-apt
平時如果想要自動做 update/upgrade package, 就可以使用這個,

apt-get install cron-tab

安裝好之後,會發現在 /etc/cron.d 下多了一個 cron-apt 檔案, 內容就是每天 4 點鐘自動執行 cron-apt

#
# Regular cron jobs for the cron-apt package
#
# Every night at 4 o'clock.
0 4     * * *   root    test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt
# Every hour.
# 0 *   * * *   root    test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt /etc/cron-apt/config2
# Every five minutes.
# */5 * * * *   root    test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt /etc/cron-apt/config2

另外可以看一下 /etc/cron-apt/action.d, 就知道 cron-apt 做了那些事
預設是只做 update repository list 以及 download new packages

/etc/cron-apt/action.d$ ls
0-update  3-download

/etc/cron-apt/action.d$ cat 0-update
update -o quiet=2

/etc/cron-apt/action.d$ cat 3-download
autoclean -y
dist-upgrade -d -y -o APT::Get::Show-Upgraded=true

相關的 log 可以看 /var/log/cron-apt/log

CRON-APT RUN [/etc/cron-apt/config]: Tue Jun 25 04:00:01 BST 2013
CRON-APT SLEEP: 2274, Tue Jun 25 04:37:55 BST 2013
CRON-APT ACTION: 0-update
CRON-APT LINE: /usr/bin/apt-get -o quiet=1 update -o quiet=2
CRON-APT ACTION: 3-download
CRON-APT LINE: /usr/bin/apt-get -o quiet=1 autoclean -y
Reading package lists...
Building dependency tree...
Reading state information...
CRON-APT LINE: /usr/bin/apt-get -o quiet=1 dist-upgrade -d -y -o APT::Get::Show-Upgraded=true
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  ruby-rgen
The following packages will be upgraded:
  cpan-libnet-http-perl facter libpython2.7 libvirt0 nodejs puppet
  puppet-common puppetmaster puppetmaster-common python python-dev
  python-django python-minimal python2.7 python2.7-dev python2.7-minimal
  uwsgi-core uwsgi-plugin-carbon uwsgi-plugin-cgi uwsgi-plugin-corerouter
  uwsgi-plugin-http uwsgi-plugin-psgi uwsgi-plugin-python
  uwsgi-plugin-rack-ruby1.8 uwsgi-plugin-rack-ruby1.9.1
25 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/49.3 MB of archives.
After this operation, 5977 kB of additional disk space will be used.
Download complete and in download only mode


Reference:

http://www.the-art-of-web.com/system/cron-apt-wheezy/#.UckR2hoW1Xo
http://www.debianadmin.com/automatic-update-of-packages-using-cron-apt.html
http://www.techrepublic.com/article/automatically-update-your-ubuntu-system-with-cron-apt/6310660

2013年6月13日 星期四

Problem: How to manage python package from apt-get?

目前 pip&distibute 解決了大部份  python package 的 installation 時遇到的 dependency 問題.
http://pythonhosted.org/distribute/
http://guide.python-distribute.org/


但如果遇到和外界的 c library 有 dependency 時, ex: pyzmq --> libzmq3  或是 pymysqldb --> libmysqlclient, 就無法在 python 的世界裡解決了, 必須要跳脫出來. 我想這也是為什麼 Ubuntu 在 python package 之外經常要再包一層看似沒做什麼事情的 .deb 檔.  ex: python-zmq, python-crypto, 透過 .deb 檔可以讓 python package 和其它 c library 建立起關係. 並且有時候可以做更多的事情, 比方說在 /etc/ 下建立 .conf 檔案, 在 /etc/init.d/ 下建立這樣一來 python package 和 OS 的關係


但問題又來了,  precise 內建的 python-crypto 是 2.4 版, 如果我要裝 2.6 版要怎麼做?

$ pip install pycrypto==2.6 
$ dpkg -l | grep python-crypto
ii  python-crypto                                       2.4.1-1ubuntu0.1                                    cryptographic algorithms and protocols for Python
$ pip freeze | grep pycrypto
pycrypto==2.6

用 pip 直接安裝是最快速的方式, 但會讓 apt/dpkg 內的資訊不一致, 這在 management 以及 deployment 有時會造成麻煩
目前還沒有找到直接的解法, 先紀錄下來, 未來有找到解法時再更新

相關 material:

http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/

http://www.pyinstaller.org/

http://stackoverflow.com/questions/4700178/should-i-bundle-c-libraries-with-my-python-application

http://www.debian.org/doc/packaging-manuals/python-policy/ch-python.html

http://developer.ubuntu.com/packaging/html/
http://developer.ubuntu.com/packaging/html/python-packaging.html
http://askubuntu.com/questions/90764/how-do-i-create-a-deb-package-for-a-single-python-script
https://wiki.ubuntu.com/PackagingGuideDeprecated/Python









2013年6月2日 星期日

DevOp 的好朋友 Multiple connection manager & screen

Gnome Connection ManagerByobu 聯合起來一起用, 之前也寫了一篇介紹 GCM
利用 GCM 可以快速的開啟每個 Node 的連結
利用 Byobu 可以在每一點同時做很多事, 又不必開新的 Tab, 而且 Byobu 特性是即使不小心斷線, 下次再連進去也可以接上原有的 session, 不必擔心正在跑的 program 被中斷, 甚至從不同機器連進去也可以看到同樣的畫面. (偶而還被我拿來當 Share Screen, 和遠端的同事接力 Debug)

所以兩個結合起來真是太贊了!


2013年5月27日 星期一

Postfix


Introduction

簡單版
https://www.digitalocean.com/community/articles/how-to-install-and-setup-postfix-on-ubuntu-12-04

超級專業版
https://help.ubuntu.com/community/Postfix

Installation

$ sudo apt-get install postfix
$ sudo apt-get install mailutils


Configuration

/etc/postfix/main.cf 的內容
# 改成你的 hostname, 在安裝時應該就會主動抓到目前的 hostname, 所以不用修改
myhostname = pjack-VirtualBox
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
# 預設 mail server 在本地, 但如果有其他的 mail server, 請修改 mydestination
#mydestination = pjack-VirtualBox, localhost.localdomain, , localhost
mydestination = xxx.tw.yyy.org
# 預設是空的, 有需要可以加上去
relayhost = xxx-mailrelay.tw.yyy.org


Verification


不管執行那一種, 不久後應該就會收到信了!
# 第一種測試
$ echo "test content" | mail -s "test subject" pjack.chen@gmail.com

# 第二種測試
$ sendmail sample-email@example.org
hihi
^D

2013年5月9日 星期四

System-wide environment variables in Ubuntu


要怎麼新增一個 system-wide global environment 可參考以下這篇

https://help.ubuntu.com/community/EnvironmentVariables

  • /etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.
Not recommended:
  • /etc/profile - This file gets executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads. This is probably the file you will get referred to when asking veteran UNIX system administrators about environment variables. In Ubuntu, however, this file does little more than invoke the /etc/bash.bashrc file.
  • /etc/bash.bashrc - This is the system-wide version of the ~/.bashrc file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.


如果加在 /etc/bash.bashrc 內, sudo xxxx, 的時候不會發揮作用, 因為沒有真的 login
有些時候希望sudoer 能繼承自己的 local variable, 可以使用以下方式, 把 env_reset 換成 env_keep

# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

#Defaults       env_reset
Defaults        env_keep+="PERL5LIB"

2012年5月31日 星期四

Install Ubuntu 12.04 on USB by VMware

上一次有提到 bootable USB 要怎麼做, 可以利用 Unetbootin 這個工具來做

http://unetbootin.sourceforge.net/

但我今天試著用這個工具做出來的 USB, 雖然的確可以開機, 但結果就和開機光碟一樣, 會進入安裝模式, 即使進入 command line 模式, 也因為工具太少, 而做不了什麼事, 所以就找了一下別人是怎麼做 LiveUSB.

https://help.ubuntu.com/community/Installation/FromUSBStick#From_Ubuntu_Linux
http://mintarticles.com/read/operating-systems-articles/how-to-install-portable-linux-ubuntu-on-a-bootable-usb-flash-drive-from-sun-virtualbox,13641/

大至上就是真的把 Ubuntu 裝一次, 但裝在 USB 上面, 做法你可以真的拿一台機器來裝, 但文章中都提到使用 VirtualBox 來裝, 也就是虛擬機器. 我對 VirtualBox 不太熟, 反而對 VMware Player 比較熟一點, 所以就試著用它來裝裝看

首先創造一個 Virtual Machine, 安裝 iso 檔就以 Ubuntu 12.04 server amd64 為例


到最後一個畫面時, 把 "Power on this virtual machine after creation" 勾選去掉, 先不要讓他開機


接下來把剛剛新加入的 VM 打開來, 把 Hard Disk 砍掉


接下來第一個光碟的 "connect at power on"  也不要勾選, 他會讓 Virtual Machine 自動安裝


USB 的部份, 則是把 "Show all USB input devices" 勾選起來


接下來就可以開機了, 第一次開機會用光碟開機, 因為要安裝 Ubuntu 12.04, 趁他開機的時間記得把 USB 接上去, 在右下角其中有一個 icon 代表著 USB, 把 Connect 按下去後, 他就會把 USB 轉接到 VM 上面去



因為沒有硬碟, 你唯一看到的就是 16G 的 USB, 就裝上去吧!


裝好之後, 要試驗一下他是否真的能開機, 但比較麻煩的是,  VMware Player 的虛擬主機版很舊, 所以無法用 USB 開機, 但有厲害的人做好另一個開機光碟可以間接讀取 USB

http://theholyjava.wordpress.com/2010/06/10/booting-from-a-usb-stick-in-vmware-player/


把 plpbt 下載下來後, 裡面有一個 plpbt.iso 檔, 我們就把它掛戴到第一個光碟機, 並且把 "Connect at power on" 勾選起來



開機的畫面如下, 就可以選 USB 開機囉!





2012.06.01 補:
如果要把 USB 做成 .img 檔,  Linux 上可以直接用 dd,  window 上可以用 usbit 這個小工具
http://www.alexpage.de/usb-image-tool/

2012.06.01 補:
結果今天前輩告訴我... 如果只是要做一個 linux-like 的 liveCD 不用這麼麻煩...
到這個網站下載就可以了, 而且還是 iso 檔... Orz
http://www.sysresccd.org/SystemRescueCd_Homepage

2012年5月30日 星期三

xrdp/mstsc in Ubuntu12.04


http://www.liberiangeek.net/2012/05/connect-to-ubuntu-12-04-precise-pangolin-via-windows-remote-desktop/

pjack@ubuntu04:~$ sudo apt-get install xrdp
pjack@ubuntu04:~$ echo "gnome-session --session=ubuntu-2d" > ~/.xsession

下面兩行我不知道是否必要.. 但因為不小心我就裝了
pjack@ubuntu04:~$ sudo apt-get install gnome-shell
pjack@ubuntu04:~$ sudo apt-get install gnome-session-fallback

之後就可以用 window 的遠端連線(mstsc) 連上去了


不過試了一早上, 想要解決在 windows/linux 之間不能 copy/paste 的問題, 但仍試不出來
試著裝 autocutsel 也無法解決, 最後就放棄了.. 如果有人知道要怎麼弄再和我說吧~

另外發現如果裝了 tightvncserver, vnc 連線會一直有問題, 連了之後, 只要打開任一個 App, 就會 crash
也不知道是怎麼一回事 :(

2012年5月8日 星期二

Oracle Java 7 on Ubuntu 12.04



方式一
pjack@ubuntu:~$ sudo apt-get update sudo add-apt-repository ppa:webupd8team/java
pjack@ubuntu:~$ sudo apt-get update
pjack@ubuntu:~$ sudo apt-get install oracle-java7-installer
pjack@ubuntu:~$ mkdir -p ~/.mozilla/plugins
pjack@ubuntu:~$ ln -s /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

方式二
# Download jdk-7-linux-i586.tar.gz or jdk-7-linux-x64.tar.gz
# And then unzip to /usr/lib/jvm
pjack@ubuntu:~$ sudo mkdir -p  /usr/lib/jvm/ 
pjack@ubuntu:~$ sudo mv java-7-oracle/ /usr/lib/jvm/
pjack@ubuntu:~$ sudo add-apt-repository ppa:nilarimogard/webupd8
pjack@ubuntu:~$ sudo apt-get update
pjack@ubuntu:~$ sudo apt-get install update-java
pjack@ubuntu:~$ sudo update-java
# 選擇你的版本
pjack@ubuntu:~$ ln -s /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins/





Reference:
http://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7
http://askubuntu.com/questions/56104/how-can-i-install-oracle-java-jre-7
http://jackden-diary.blogspot.com/2012/05/install-oracle-java-7-on-ubuntu-1204-by.html

2012年3月13日 星期二

Network 指令收集

KVM Installation

https://help.ubuntu.com/11.10/serverguide/C/virtualization.html
http://bojack.pixnet.net/blog/post/29040863-%E3%80%90linux%E3%80%91%E5%9C%A8-ubuntu-11.04-%E4%B8%8A%E5%AE%89%E8%A3%9D-kvm

wistor@wistor-003:~$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

wistor@wistor-003:~$ lsmod | grep kvm
kvm_intel             137721  3
kvm                   407077  1 kvm_intel

wistor@wistor-003:~$ sudo modprobe -l | grep kvm
kernel/arch/x86/kvm/kvm.ko
kernel/arch/x86/kvm/kvm-intel.ko
kernel/arch/x86/kvm/kvm-amd.ko

wistor@wistor-003:~$ sudo apt-get install kvm libvirt-bin

wistor@wistor-003:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto br0
iface br0 inet static
        bridge_ports eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off
        address 172.16.123.83
        network 172.16.0.0
        netmask 255.255.0.0
        gateway 172.16.1.254

auto br0:1
iface br0:1 inet static
    address 192.168.123.83
    netmask 255.255.255.0

wistor@wistor-003:~$ ifconfig
br0       Link encap:Ethernet  HWaddr 00:26:2d:0a:36:7e
          inet addr:172.16.123.83  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::226:2dff:fe0a:367e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:186911 errors:0 dropped:5837 overruns:0 frame:0
          TX packets:79278 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:136435680 (136.4 MB)  TX bytes:8542559 (8.5 MB)

br0:1     Link encap:Ethernet  HWaddr 00:26:2d:0a:36:7e
          inet addr:192.168.123.83  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0      Link encap:Ethernet  HWaddr 00:26:2d:0a:36:7e
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:278356 errors:0 dropped:10 overruns:0 frame:0
          TX packets:91634 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:176265990 (176.2 MB)  TX bytes:9623004 (9.6 MB)
          Memory:fbea0000-fbec0000

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:98 errors:0 dropped:0 overruns:0 frame:0
          TX packets:98 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9439 (9.4 KB)  TX bytes:9439 (9.4 KB)

virbr0    Link encap:Ethernet  HWaddr 52:6b:4e:82:ba:f8
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)



wistor@wistor-003:~$ groups
wistor adm dialout cdrom plugdev lpadmin sambashare admin libvirtd

wistor@wistor-003:~$ virsh -c qemu:///system list
 Id Name                 State
----------------------------------

wistor@wistor-003:~$ sudo iptables -t nat -L -n
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  tcp  --  192.168.122.0/24    !192.168.122.0/24    masq ports: 1024-65535
MASQUERADE  udp  --  192.168.122.0/24    !192.168.122.0/24    masq ports: 1024-65535
MASQUERADE  all  --  192.168.122.0/24    !192.168.122.0/24


wistor@wistor-003:~$ sudo apt-get install virtinst
wistor@wistor-003:~$ cat build_vm.sh
HOSTNAME=vm3
MEMORY=512
CPUS=1
DISK_SIZE=10000
IP=172.16.123.84


sudo virt-install \
-v \
-n $HOSTNAME \
-r $MEMORY \
--disk path=$HOSTNAME.img,bus=virtio,size=4 \
-c ubuntu-11.10-server-amd64.iso \
--accelerate \
--network bridge=br0 \
--connect=qemu:///system \
--virt-type=kvm \
--graphics vnc,listen=0.0.0.0
wistor@wistor-003:~$ sudo ./build_vm.sh
wistor@wistor-003:~$ virsh vncdisplay vm3
:0






2012/03/14 補: 用一個 image 當作 base, 然後 create 出來其他 image 檔
http://jamyy.dyndns.org/blog/2012/02/3594.html

wistor@wistor-001:~$ sudo qemu-img create -b iscsi-server-base.qcow2 -f qcow2 wistor-004.qcow2
Formatting 'wistor-004.qcow2', fmt=qcow2 size=4294967296 backing_file='iscsi-server-base.qcow2' encryption=off cluster_size=0


2012/03/14 補: 把.img 轉成 qcow2

wistor@wistor-001:~$ sudo qemu-img convert -O qcow2 iscsi-server-base.img iscsi-server-base.qcow2

2012/03/15 補: 如何直接 mount qcow2

wistor@wistor-003:~$ modprobe nbd
wistor@wistor-003:~$ sudo kvm-nbd -c /dev/nbd0 ~/kvm/ubuntu-11.10-3.2-base.qcow2
wistor@wistor-003:~$ sudo mount /dev/nbd0p1 /mnt/kvm
wistor@wistor-003:~$ sudo umount /mnt/kvm
wistor@wistor-003:~$ sudo kvm-nbd -d /dev/nbd0

2012/03/16 補: 如何 boot from network

# 記得要先安裝這個套件
wistor@ubuntu:~/kvm$ sudo apt-get install kvm-pxe
[sudo] password for wistor:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  kvm-pxe
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 128 kB of archives.
After this operation, 201 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ oneiric/universe kvm-pxe all 5.4.4-7ubuntu3 [128 kB]
Fetched 128 kB in 2s (58.7 kB/s)
Selecting previously deselected package kvm-pxe.
(Reading database ... 71450 files and directories currently installed.)
Unpacking kvm-pxe (from .../kvm-pxe_5.4.4-7ubuntu3_all.deb) ...
Setting up kvm-pxe (5.4.4-7ubuntu3) ...

# 在  內加上 network 選項, 如果需要 bootmenu 就再加上設定
wistor@ubuntu:~/kvm$ sudo cat /etc/libvirt/qemu/ubuntu-11.10-3.2-base.xml | grep -A 10 os
  
    hvm
    
    
    
  





Reference:
http://www.howtoforge.com/virtualization-with-kvm-on-ubuntu-10.10


Console problem
http://serverfault.com/questions/338770/kvm-on-ubuntu-console-connection-displays-nothing

Kdump on Ubuntu11.10


Reference:
http://www.dedoimedo.com/computers/kdump.html
http://www.mjmwired.net/kernel/Documentation/kdump/

Kdump 的介紹就看上面兩個連結, 基本上如果是在 Ubuntu 上 cpu =1 的狀況下, 可以直接使用原本的 kernel 來當 Crash Kernel, 根據上面的文件來看, 即使 cpu > 1 的狀況下, 應該也可以正常運作, 只要加上 maxcpus=1 即可, 然而實際測試過後卻無法成功, 不太確定是什麼環節出了問題, 所以就使用最傳統的方式, 另外準備一個專門的 Crash Kernel, 至於怎麼 Build Kernel 就參考這篇文章以及上述的連結來做設定

Build Linux Kernel 3.2

Crash Kernel 安裝好之後, 就可以安裝 kdump


wistor@wistor-001:~$ sudo apt-get install kdump-tools

wistor@wistor-001:~$ cat /etc/default/kdump-tools
# 設成 1
USE_KDUMP=1
# 設成安裝進去的 package
KDUMP_KERNEL="/boot/vmlinuz-3.2.0-17-crashdump32"
KDUMP_INITRD="/boot/initrd.img-3.2.0-17-crashdump32"
KDUMP_CMDLINE="BOOT_IMAGE=/boot/vmlinuz-3.2.0-17-crashdump32 root=UUID=b1a569f8-8046-416f-96d6-ef9012d922b0 ro"

# 設定好之後重啟 kdump
wistor@wistor-003:~$ chkconfig kdump on
wistor@wistor-003:~$ sudo service kdump restart
wistor@wistor-003:~$ sudo service kdump-tools restart
 * unloaded kdump kernel
Could not find an installed debug vmlinux image and
DEBUG_KERNEL is not specified in /etc/default/kdump-tools
 * makedumpfile may be limited to -d 1
setup_linux_vesafb: 640x480x32 @ fa000000 +130000
 * loaded kdump kernel
# 有可能看到他會警告你沒有設定 crashkernel, 但不用理他, 重開機後應該就會正確
# 檢查一下 command 有沒有正確, 沒問題的話就重開機一下
wistor@wistor-003:~$ cat /var/crash/kexec_cmd
/sbin/kexec -p --command-line="BOOT_IMAGE=/boot/vmlinuz-3.2.0-17-crashdump32 root=UUID=b1a569f8-8046-416f-96d6-ef9012d922b0 ro irqpoll maxcpus=1 nousb" --initrd=/boot/initrd.img-3.2.0-17-crashdump32 /boot/vmlinuz-3.2.0-17-crashdump32

# 可以利用這個指令來測試
wistor@wistor-003:~$ echo c > /proc/sysrq-trigger

# 理想的狀況下, 應該在 /var/crash 內產生 dump
wistor@wistor-003:/var/crash$ ll
total 32
drwxrwxrwt  7 root root 4096 2012-03-09 13:23 ./
drwxr-xr-x 13 root root 4096 2012-03-09 12:56 ../
drwxr-xr-x  2 root root 4096 2012-03-08 12:01 201203081152/
drwxr-xr-x  2 root root 4096 2012-03-08 17:35 201203081735/
drwxr-xr-x  2 root root 4096 2012-03-09 12:48 201203091241/
drwxr-xr-x  2 root root 4096 2012-03-09 13:15 201203091306/
drwxr-xr-x  2 root root 4096 2012-03-09 13:23 201203091323/
-rwxr-xr-x  1 root root  231 2012-03-09 13:22 kexec_cmd*




2012年3月10日 星期六

Ubuntu 11.10 中文輸入法倉頡問題


預設是安裝英文版, 但要加入中文輸入法要怎麼辦呢?

Dash Home -> System Setting -> Language Support -> Install / Remove Language -> Chinese (Traditional)

Dash Home -> Keyboard Input Method -> turn on ibus -> 接下來就可以安裝注音或是倉頡輸入法

不過我遇到了很神奇的事, 就是打出來的字都是簡體中文, 網路上找了很久才找到解法

http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=202508

vi /usr/share/ibus-table/engine/table.py

search get_chinese_mode
search the followings

    def get_chinese_mode (self):
        '''Use LC_CTYPE in your box to determine the _chinese_mode'''
        try:
            if os.environ.has_key('LC_CTYPE'):
                __lc = os.environ['LC_CTYPE'].split('.')[0].lower()
            else:
                __lc = os.environ['LANG'].split('.')[0].lower()

            if __lc.find('zh_') == 0:
                # this is a zh_XX
                __place =__lc.split('_')[1]
                if __place == 'cn':
                    return 0
                else:
                    return 1
            else:
                if self.db._is_chinese:
                    # if IME declare as Chinese IME
                    # 這行改成回傳 1
                    return 1
                else:
                    return -1
        except:
            return -1



2012年1月12日 星期四

Ubuntu Orchestra 筆記


Highlighted Components
Experience of provisioning
    1. Rack a server
    2. Turn on a server
    3. Server netboots and 'registers' itself with the Orchestra provisioning server (cobbler)
    4. Server shuts down
    5. (WAIT)
    6. When server is required, it is Wake'd on Lan via powerwake and installs a base Ubuntu server with cloud-init installed.
    7. Juju customizes the install to be as required.

    http://blog.dustinkirkland.com/2011/08/formal-introduction-to-ubuntu-orchestra.html

    What is SOAP?

    是一種 Protocol, 用在使用 Web Service 之間的溝通, 格式是 XML, 架構在 HTTP or SMTP 之上


    What is WSDL?



    • A WSDL description of a web service (also referred to as a WSDL file) provides a machine-readable description of how the service can be called, what parameters it expects and what data structures it returns.
    • It thus serves a roughly similar purpose as aMethod signature in a programming language
    意思就是傳統 programming language 的  header file,用來描述這個 web service 怎麼使用


    What is UDDI?

    意思就是當你在網路上想要找到特定的 web service 來使用,那你怎麼知道要去那裡找? UDDI 就是一個提供查找的 "機制"  或是一個 "組織",你可以透過它去拿到 WSDL 然後知道怎麼使用這個  web service




    What is REST?


    老實說,看完後還是無法抓到到底怎麼樣的架構才能符合 REST,但至少明白他是在定義了一種 client-server 的軟體架構。


    What is RESTful web service?



    • A RESTful web service (also called a RESTful web API) is a simple web service implemented using HTTP and the principles of REST
      • the base URI for the web service
      • The Internet media type of the data supported by the web service.  This is often JSONYAML
      • the set of operations supported by the web service using HTTP methods (e.g., GET, PUT, POST, or DELETE).
      • The API must be hypertext driven
    目前很多 web service 都宣稱他們是 RESTful,基本上只代表能簡易透過一個 URL 再加上  GET/PUT/POST/DELETE 來操作網路上的物件或是使用他提供的 service,而格式目前我常看到的是  JSON

    What is Service Choreography?
    http://en.wikipedia.org/wiki/Web_Service_Choreography
    http://en.wikipedia.org/wiki/Service_choreography


    • XML-based business process modeling language that describes collaboration protocols of cooperating Web Service participants
    • Dancers dance following a global scenario without a single point of control
    • Each participant in a service choreography executes its part of it (i.e. its role) according to the behavior of the other participants
    感覺就是各跳各的呀~ 


    What is Service Orchestration?

    有一個總帥.. 但仍各司其職


    Different between Choreography and Orchestration

    實在太難懂了.. 到底在寫什麼 @@


    Choreography
    Orchestration
    Point of View
    the logic of the message-based interactions among the participants are specified from a global perspective
    the logic is specified from the local point of view of one single participant, called the orchestrator.
    Message exchange
    a protocol for peer-to-peer interactions
    specifies an executable process that involves message exchanges with other systems, such that the message exchange sequences are controlled by the orchestration designer
    Control
    a distributed system which operates according to rules but without centralized control
    central control of the behavior of a distributed system


    2011年10月27日 星期四

    Ubuntu 上增加新使用者


    pjack@ubuntu64-33-7:~$ sudo adduser wistor
    [sudo] password for pjack:
    Adding user `wistor' ...
    Adding new group `wistor' (1001) ...
    Adding new user `wistor' (1001) with group `wistor' ...
    Creating home directory `/home/wistor' ...
    Copying files from `/etc/skel' ...
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    Changing the user information for wistor
    Enter the new value, or press ENTER for the default
            Full Name []:
            Room Number []:
            Work Phone []:
            Home Phone []:
            Other []:
    Is the information correct? [Y/n] y
    pjack@ubuntu64-33-7:~$ sudo adduser wistor admin
    Adding user `wistor' to group `admin' ...
    Adding user wistor to group admin
    Done.
    
    


    如果在執行 sudo 時不想需要密碼,要在 /etc/sudoers.d 內新增檔案, 內容加上 NOPASSWD

    root@ubuntu1104-64-5:/etc/sudoers.d$ ls
    pjack  README  www-data
    root@ubuntu1104-64-5:/etc/sudoers.d$ cat pjack
    pjack   ALL=(ALL:ALL) NOPASSWD: ALL
    

    Install GUI on Ubuntu Server 11.10 and Remote Control from Windows



    Solution 1: Install GNOME desktop

                     sudo apt-get install ubuntu-desktop

    Solution 2: install GNOME desktop without recommend software

                     sudo apt-get install --no-install-recommends ubuntu-desktop

                     [這個怪怪的.. 會開不了機, 卡在 PulseAudio configured for per-user sessions]

    Solution 3: install light weight desktop xfce

                     sudo apt-get install xubuntu-desktop

    Solution 4: install KDE desktop

                     sudo apt-get install kubuntu-desktop

    最後再安裝 xrdp, 就大功告成啦~

    install xrdp

    補: 透過 xrdp , 按 d 的時候, 會把所有的視窗小

    Now in order to get the proper keyboard map and theme in GNOME, you need to make a modification:
    Open gconf-editor either by typing that in a console, or in the Alt+F2 window.
    Inside gconf-editor, navigate to /apps/gnome_settings_daemon/plugins/keyboard and set “active” to false.
    or do the following steps
    gconf-editor ->app->metacity->global_keybindings
    Change the assigned keystroke for show_desktop from "d" to "d" or "d" or "disabled"
    But this changes are only for the active user.
    To set this option for all Users do the following:
    Right click on "show_desktop" and choose  set Mandatory or set it as default. You can check this option if you choose File --> New Mandatory Window. See also this page for more informations.
    補: 透過 xrdp, 有些 icon 會不見, 也無法 logout 我後來改用 gnome-shell 就沒問題

    sudo apt-get install gnome-shell
    sudo nano /etc/lightdm/lightdm.conf             # 把 user-session=ubuntu-2d