/*------------------------------------------------------------------*/
    ANIR制御用計算機uni2(kernel2.6.22+RTAI+bigphysarea)の
                       カーネルアップデートの道

                                           としかわ
                                           2008/06/19
/*------------------------------------------------------------------*/

######################################
●CentOS 5.1をインストール
 *Top画面でEnter

 *CD~はSkip

 *日本語→US internationalのキーボード

 *パーティション分割は
	Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
	/dev/sda3              9920624   4669368   4739188  50% /
	/dev/sda2             19840924    182972  18633812   1% /home
	/dev/sda1               101086     16193     79674  17% /boot
	tmpfs                  1033112         0   1033112   0% /dev/shm

 *フォーマット

 *GRUBブートローダ~はデフォルト

 デフォルトではEmacsと開発系が入ってないので注意
 *CentOSのデフォルトインストール~→今すぐカスタマイズする##超重要##
  アプリケーション→Emacs
  開発系→全部

 以上、設定後インストール開始なり
######################################

######################################
●ネットワークを入れる
#install_v10.60.2.3.tar.bz2の入手,USB等経由で
 cd /root
 mkdir download

#/root/downloadに入れる&解凍
 cd /root/download
 tar jxfv install_v10.60.2.3.tar.bz2

#ドライバのインストール
 cd DriverInstall
 ./install.sh
	1)installation   →選択
	2)
	3)

	1)
	2)Deactive driver→選択
	3)    

 modprobe sk98lin

#GNOMEで
	システム→管理→ネットワーク→デバイス→新規→イーサネット接続
	dhcpを選択、起動

#確認
 /sbin/ifconfig
 #eth0      Link encap:Ethernet  HWaddr 00:1D:92:37:2B:BC  
            inet addr:157.82.121.174  Bcast:157.82.121.255  Mask:255.255.254.0
	    inet6 addr: fe80::21d:92ff:fe37:2bbc/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:80 errors:0 dropped:0 overruns:0 frame:0
            TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:7522 (7.3 KiB)  TX bytes:9846 (9.6 KiB)
            Interrupt:185 Memory:feafc000-0 

#再起動
######################################

######################################
初期設定など
*キーボードの設定
 GNOMEシステム→設定→他の個人設定→SCIM入力メソッドの設定
 フロントエンドの全体設定→ホットキー(開始/終了)
 キーコードをクリックしShift+space→追加

*yum updateによってkernelまでアップデートされないように設定

 emacs /etc/sysconfig/kernel
  #UPDATEDEFAULT=yes→no

*その後アップデート
 yum update
 結構時間がかかる.....
######################################

######################################
●NTPD
gnomeの時間設定ウインドウからntpサーバ問い合わせを有効にする
ntpサーバは天文センター内(platini=157.82.120.101)にする

●サービスの選択

chkconfig --del postfix
#→そのようなファイルやディレクトリはありません
chkconfig --del cpuspeed
chkconfig --del acpid
chkconfig --del cups
chkconfig --del smb
#→そのようなファイルやディレクトリはありません
chkconfig --del iptables
#NFS関連はとりあえず外しておく
chkconfig --del netfs
chkconfig --del autofs
chkconfig --del nfs
chkconfig --level 345 ntpd on
chkconfig --level 345 nfs on
#chkconfig --level 345 smb on
chkconfig --level 345 autofs on

#2008/11/14 追加でサービス停止(本原)
chkconfig --del haldaemon
  # <= これは、定期的なディスクアクセスをしていたので
chkconfig --del gpm
chkconfig --del ip6tables
chkconfig --del restorecond
chkconfig --del pcscd
chkconfig --del rpcgssd
chkconfig --del rpcidmapd
chkconfig --del smartd

●anirのユーザid
less /etc/passwd
で確認すると
anir:x:500:500:Atacama NIR camera:/home/anir:/bin/bash

gidをuniと同じ501に変えたい
userdel -r anir
groupadd -g 501 anir
useradd -c "Atacama NIR" -g 501 -u 500 anir

パスワードの設定
passwd anir

less /etc/passwd
で確認すると
anir:x:500:501:Atacama NIR:/home/anir:/bin/bash

OK!
#######################################

↓

#######################################
(4)カーネル用DIRを作成
cd /usr/src/kernels
mkdir linux2.6.22+RTAI3.6.1/
cd linux2.6.22+RTAI3.6.1/
######################################

↓

######################################
(5)RTAIソースをダウンロード
mkdir download
cd download
https://www.rtai.org/より、のRTAI (rtai-3.6.1)をダウンロード
######################################

↓

######################################
(6)RTAIソースを解凍
cd ..
pwd
/usr/src/kernels/linux2.6.22+RTAI3.6.1

tar jxfv download/rtai-3.6.1.tar.bz2

ls rtai-3.6.1/base/arch/i386/patches/
README                                hal-linux-2.6.19-i386-1.7-01.patch
hal-linux-2.4.34-i386-1.3-04.patch    hal-linux-2.6.20.21-i386-1.12-03.patch
hal-linux-2.4.35.5-i386-1.3-04.patch  hal-linux-2.6.22-i386-1.10-12.patch
hal-linux-2.4.36-i386-1.3-04.patch    hal-linux-2.6.23-i386-1.12-03.patch

以上より、パッチはたくさんある。
linux-2.6.22カーネルにパッチをあてる。
######################################

↓

######################################
(7)カーネルソースをダウンロード
cd /usr/src/kernels/linux2.6.22+RTAI3.6.1/download
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.tar.gz

cd ..
pwd
/usr/src/kernels/linux2.6.22+RTAI3.6.1
tar zxfv download/linux-2.6.22.tar.gz

DIRの名前をかえる
mv linux-2.6.22 linux-2.6.22rtai
cd linux-2.6.22rtai
######################################

↓

######################################
(8)カーネルにRTAIパッチをあてる
pwd
/usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai

patch -p1 -b < /usr/src/kernels/linux2.6.22+RTAI3.6.1/rtai-3.6.1/base/arch/i386/patches/hal-linux-2.6.22-i386-1.10-12.patch
※今回はbigphysareaパッチをあてない
######################################

↓

######################################
(9)カーネルのconfigファイルをつくる
pwd
/usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai

CentOSの.configファイルを利用する
cp /boot/config-2.6.18-53.1.21.el5 ./.config

.configファイルを編集する
make menuconfig

"Processor type and features" -> "Symmetric multi-processing support"   [enabled]
"Processor type and features" -> "Interrupt pipeline"                   [enabled]
"Loadable module support"     -> "Module versioning support"            [disabled]
 →スペースキーでenabled or disabled

また、CPUはPentium Core2Duoなので
"Processor type and features" -> "Processor family" (Core 2/newer Xeon)
にする

Device Drivers  --->  ATA/ATAPI/MFM/RLL support  --->   
│<M> Intel PIIXn chipsets support                                             CONFIG_BLK_DEV_PIIX    SATAで必須
Moduleにすること。そうしないと起動時におこられる(SATA HD使用時)

Device Drivers  --->  SCSI device support  --->  
<*> SCSI device support                                                        CONFIG_SCSI            SATAで必須
<*> SCSI disk support                                                          CONFIG_BLK_DEV_SD      SATAで必須


File systems  --->   

<*> Ext3 journalling file system support
│[*]   Ext3 extended attributes
│[*]     Ext3 POSIX Access Control Lists
│[*]     Ext3 Security Labels

<*> Reiserfs support   
│[ ]   Enable reiserfs debug mode
│[*]   Stats in /proc/fs/reiserfs
│[*]   ReiserFS extended attributes
│[*]     ReiserFS POSIX Access Control Lists
│[*]     ReiserFS Security Labels   

サウンドドライバもはずす
Device Drivers  ---> Sound --->
< > Sound card support 

saveして終了
######################################

↓

######################################
(10)
カーネルをmake
pwd
/usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai

make
ひたすら待つ.....

/*----------------------------------------------------------*/
http://itpro.nikkeibp.co.jp/members/SI/oss/20031024/3/
カーネルをコンパイルする際も,従来必要だったmake depのステップが
必要なくなり,makeコマンドを実行するだけでbzImageやモジュール・
ドライバがコンパイルされるようになった。なお,引数を与えずにmakeを
実行した場合は最低限のメッセージしか表示されない静粛(quiet)モード
になる。従来のように実際に実行しているコマンドを表示させたい場合は
make V=1
のように,V=1オプションを与えて冗長(verbose)モードにする必要がある。
/*----------------------------------------------------------*/
######################################

↓

######################################
(11)構築されたカーネルをインストール
pwd
/usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai

カーネルイメージを確認
ls -la vmlinux
-rwxr-xr-x 1 root root 71200298  6月 13 19:34 vmlinux


カーネルのインストール
make install

エラーが起きるが無視
sh /usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai/arch/i386/boot/install.sh 2.6.22 arch/i386/boot/bzImage System.map "/boot"
WARNING: Couldn't open directory /lib/modules/2.6.22: No such file or directory
FATAL: Could not open /lib/modules/2.6.22/modules.dep.temp for writing: No such file or directory
No modules available for kernel "2.6.22".
mkinitrd failed
make[1]: *** [install] エラー 1
make: *** [install] エラー 2


System.mapとvmlinuzが/bootにコピーされていることを確認。
ls -la /boot/ | grep 6月
-rw-r--r--  1 root root  893071  6月 13 19:38 System.map-2.6.22
-rw-r--r--  1 root root 2069588  6月 13 19:38 vmlinuz-2.6.22
OK!


モジュールのインストール
make modules_install

initrdファイルの生成

/sbin/mkinitrd initrd-2.6.22rtai-0v001.img  2.6.22
mv ./initrd-2.6.22rtai-0v001.img /boot/
######################################

↓

######################################
(12)カーネルファイルの名前を分かりやすく変える

とりあえずまぎらわしいのでリンクファイルを消す
rm -f /boot/vmlinuz
rm -f /boot/System.map

名前をわかりやすくかえる
mv /boot/vmlinuz-2.6.22    /boot/vmlinuz-2.6.22rtai-0v001
mv /boot/System.map-2.6.22 /boot/System.map-2.6.22rtai-0v001
cp .config /boot/config-2.6.22rtai-0v001
######################################

↓

######################################
(13)GRUBを設定+reboot
GRUBを編集

emacs /boot/grub/menu.lst


default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.22 + RTAI3.6.1)
        root (hd0,0)
        kernel /vmlinuz-2.6.22rtai-0v001 ro root=LABEL=/1 rhgb quiet
        initrd /initrd-2.6.22rtai-0v001.img
title CentOS (2.6.18-53.1.21.el5)
	root (hd0,0)
	kernel /vmlinuz-2.6.18-53.1.21.el5 ro root=LABEL=/1 rhgb quiet
	initrd /initrd-2.6.18-53.1.21.el5.img
title CentOS (2.6.18-53.el5)
	root (hd0,0)
	kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/1 rhgb quiet
	initrd /initrd-2.6.18-53.el5.img


再起動
reboot
######################################

↓

######################################
(14)再起動を確認
OK!!
######################################

↓

######################################
(15)rtaiモジュールのmake+install

cd /usr/src/kernels/linux2.6.22+RTAI3.6.1/rtai-3.6.1

ln -s /usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai /usr/src/linux

make menuconfig
設定は変えないで、saveして出る

make
make install


rtaiがハングアップなどで異常終了した場合、rebootすると
/dev/rtf*が消えてしまう場合がある。
これに対応するために、/etc/rc.d/rc.localの最尾に
以下のスクリプトを加える (README.INSTALLより)

emacs /etc/rc.d/rc.local

------------------------------ cut here -------------------------------------
#### for RTAI (added by #21 2008/06/13)

if test \! -c /dev/rtai_shm; then
        mknod -m 666 /dev/rtai_shm c 10 254
fi
for n in `seq 0 9`; do
        f=/dev/rtf$n
        if test \! -c $f; then
                mknod -m 666 $f c 150 $n
        fi
done

#### for RTAI ends here
------------------------------ cut here -------------------------------------


OSのRTAI化を終了
######################################

↓

######################################
★rtaiの動作試験

cd /usr/realtime/testsuite/kern/latency

試験実行
./run

/*--------------------------2008/06/18--------------------------------------*/
## RTAI latency calibration tool ##
# period = 100000 (ns) 
# avrgtime = 1 (s)
# do not use the FPU
# start the timer
# timer_mode is oneshot

RTAI Testsuite - KERNEL latency (all data in nanoseconds)
RTH|    lat min|    ovl min|    lat avg|    lat max|    ovl max|   overruns
RTD|      -1779|      -1790|      -1666|        349|       2016|        616
RTD|      -1782|      -1790|      -1664|       -152|       2016|        616
RTD|      -1774|      -1790|      -1664|       -163|       2016|        616
RTD|      -1787|      -1790|      -1664|        581|       2016|        616
RTD|      -1776|      -1790|      -1664|       -200|       2016|        616
RTD|      -1786|      -1790|      -1664|       -254|       2016|        616
RTD|      -1750|      -1790|      -1668|         53|       2016|        616
RTD|      -1786|      -1790|      -1662|       -235|       2016|        616
RTD|      -1772|      -1790|      -1662|        523|       2016|        616
RTD|      -1743|      -1790|      -1665|       -406|       2016|        616
RTD|      -1771|      -1790|      -1667|       -439|       2016|        616
RTD|      -1782|      -1790|      -1661|        427|       2016|        616
RTD|      -1756|      -1790|      -1668|       -262|       2016|        616
RTD|      -1786|      -1790|      -1666|       -468|       2016|        616
RTD|      -1763|      -1790|      -1664|        499|       2016|        616
RTD|      -1779|      -1790|      -1661|       -275|       2016|        616
RTD|      -1788|      -1790|      -1668|        411|       2016|        616
RTD|      -1777|      -1790|      -1662|        433|       2016|        616
RTD|      -1786|      -1790|      -1666|       -174|       2016|        616
RTD|      -1788|      -1790|      -1664|        347|       2016|        616
RTD|      -1754|      -1790|      -1667|        635|       2016|        616
RTH|    lat min|    ovl min|    lat avg|    lat max|    ovl max|   overruns
RTD|      -1763|      -1790|      -1659|        515|       2016|        616
RTD|      -1777|      -1790|      -1667|       -474|       2016|        616
RTD|      -1783|      -1790|      -1665|        -12|       2016|        616
RTD|      -1763|      -1790|      -1666|        508|       2016|        616
RTD|      -1783|      -1790|      -1662|        401|       2016|        616
RTD|      -1786|      -1790|      -1668|       -197|       2016|        616
RTD|      -1763|      -1790|      -1663|        494|       2016|        616
RTD|      -1746|      -1790|      -1664|       -222|       2016|        616
RTD|      -1779|      -1790|      -1664|       -127|       2016|        616
RTD|      -1779|      -1790|      -1666|        634|       2016|        616
RTD|      -1784|      -1790|      -1661|        367|       2016|        616
RTD|      -1782|      -1790|      -1665|        346|       2016|        616
RTD|      -1785|      -1790|      -1664|        -75|       2016|        616
RTD|      -1790|      -1790|      -1667|        464|       2016|        616
RTD|      -1784|      -1790|      -1663|        408|       2016|        616
RTD|      -1777|      -1790|      -1668|        503|       2016|        616
RTD|      -1788|      -1790|      -1662|       -163|       2016|        616
RTD|      -1788|      -1790|      -1665|       -509|       2016|        616
RTD|      -1780|      -1790|      -1664|       -201|       2016|        616
RTD|      -1774|      -1790|      -1666|        333|       2016|        616
RTD|      -1761|      -1790|      -1663|        513|       2016|        616
RTH|    lat min|    ovl min|    lat avg|    lat max|    ovl max|   overruns
/*---------------------------------------------------------------------------*/


latencyが~1sならよいらしい
0~1800ns程度なのでOK!

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

↓

######################################
/*--------------------------------------------------------*/
               bigphysareaのインストール
/*--------------------------------------------------------*/

(1)パッチの用意

http://www.feise.com/~jfeise/Downloads/zr36120/
よりkernel2.6.22用のbigphysareaパッチをdownload

bigphysarea-2.6.22.6.diff



(2)パッチをあてる

cd /usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai/

cp /root/Desktop/bigphysarea-2.6.22.6.diff /usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai/.

patch -p1 <bigphysarea-2.6.22.6.diff 
  patching file Documentation/bigphysarea.txt
  patching file arch/i386/Kconfig
  Hunk #1 succeeded at 699 (offset 2 lines).
  patching file include/linux/bigphysarea.h
  patching file kernel/kallsyms.c
  patching file mm/Makefile
  patching file mm/bigphysarea.c



(3)カーネルをmake
make menuconfig

bigphysareaを有効に

 Processor type and features  --->
 [*] Support for big physical area reservation

このままmakeするとerrorが起きるのでbigphysarea.cの内容を少し変える。

emacs mm/bigphysarea.c

62行目static struct resource mem_resource = { "Bigphysarea", 0, 0, IORESOURCE_MEM|IORESOURCE_BUSY };
をコメントアウト。(行の最初に//を挿入)
またこの行をコメントアウトした下に、コピーし『"Bigphysarea"→0』に変える。
:wqで終了。

make
ひたすら待つ.....



(4)カーネルイメージを確認

ls -la vmlinux
-rwxr-xr-x 1 root root 71260987  6月 13 20:15 vmlinux



(5)カーネルのインストール
make install

System,mapとvmlinuzが/bootにコピーされていることを確認。OK!
ls -la /boot/ | grep 6月
-rw-r--r--  1 root root  893881  6月 13 20:32 System.map-2.6.22
-rw-r--r--  1 root root 2070996  6月 13 20:32 vmlinuz-2.6.22


(6)モジュールのインストール
make modules_install



(7)initrdファイルの生成
/sbin/mkinitrd initrd-2.6.22rtai-0v002.img 2.6.22
mv ./initrd-2.6.22rtai-0v002.img /boot/



(8)カーネルのイメージなどの名前をわかりやすく変える

とりあえずまぎらわしいのでリンクファイルを消す
rm -f /cboot/vmlinuz
rm -f /boot/System.map

名前をわかりやすくかえる
mv /boot/vmlinuz-2.6.22 /boot/vmlinuz-2.6.22rtai-0v002
mv /boot/System.map-2.6.22 /boot/System.map-2.6.22rtai-0v002
cp /usr/src/kernels/linux2.6.22+RTAI3.6.1/linux-2.6.22rtai/.config /boot/config-2.6.22rtai-0v002



(9)GRUBを設定+reboot
GRUBを編集
emacs /boot/grub/menu.lst


default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.22 + RTAI3.6.1 + bigphysarea)
        root (hd0,0)
        kernel /vmlinuz-2.6.22rtai-0v002 ro root=LABEL=/1 rhgb quiet bigphysarea=36000
        initrd /initrd-2.6.22rtai-0v002.img
title CentOS (2.6.22 + RTAI3.6.1)
        root (hd0,0)
        kernel /vmlinuz-2.6.22rtai-0v001 ro root=LABEL=/1 rhgb quiet
        initrd /initrd-2.6.22rtai-0v001.img
title CentOS (2.6.18-53.1.21.el5)
	root (hd0,0)
	kernel /vmlinuz-2.6.18-53.1.21.el5 ro root=LABEL=/1 rhgb quiet
	initrd /initrd-2.6.18-53.1.21.el5.img
title CentOS (2.6.18-53.el5)
	root (hd0,0)
	kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/1 rhgb quiet
	initrd /initrd-2.6.18-53.el5.img

再起動
reboot



(10)再起動を確認
たちあがった。

bigphysareaがうまく設定されているかを確認

cat /proc/bigphysarea

Big physical area, size 144000 kB
                       free list:             used list:
number of blocks:             1                      0
size of largest block:   144000 kB                   0 kB
total:                   144000 kB                   0 kB

OK!!!


################################
# MTRON 32GB SSDのためのいろいろ #
################################

●/tmpをtmpfsにしてRAM上に展開

cat << EOF >> /etc/fstab
tmpfs                   /tmp            tmpfs   defaults,size=512m      0 0
EOF

●hdparm結果

hdparm -I /dev/sda

#/dev/sda:
#
#ATA device, with non-removable media
#        Model Number:       MTRON MSD-SATA3035                      
#        Serial Number:      0HA1130300260
#        Firmware Revision:  0.17 R1 
#Standards:
#        Used: Reserved 
#        Supported: 7 6 5 4 
#Configuration:
#        Logical         max     current
#        cylinders       16383   0
#        heads           16      0
#        sectors/track   63      0
#        --
#        LBA    user addressable sectors:   62504960
#        device size with M = 1024*1024:       30520 MBytes
#        device size with M = 1000*1000:       32002 MBytes (32 GB)
#Capabilities:
#        LBA, IORDY(cannot be disabled)
#        Standby timer values: spec'd by Vendor, no device specific minimum
#        R/W multiple sector transfer: Max = 1   Current = 1
#        DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 *udma5 udma6 
#             Cycle time: min=120ns recommended=120ns
#        PIO: pio0 pio1 pio2 pio3 pio4 
#             Cycle time: no flow control=120ns  IORDY flow control=120ns
#Commands/features:
#        Enabled Supported:
#           *    SMART feature set
#           *    Power Management feature set
#           *    Write cache
#                Look-ahead
#           *    Mandatory FLUSH_CACHE
#Checksum: correct

●mount オプション
noatimeオプションを付ける

#emacs -nw /etc/fstab

#LABEL=/1                /                       ext3    defaults,noatime	1 1
#LABEL=/home             /home                   ext3    defaults,noatime	1 2
#LABEL=/boot1            /boot                   ext3    defaults,noatime	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-sda5         swap                    swap    defaults        0 0
#tmpfs                   /tmp            tmpfs   defaults,size=512m      0 0

●転送速度チェック。

hdparm -t /dev/sda

#/dev/sda:
# Timing buffered disk reads:  228 MB in  3.01 seconds =  75.66 MB/sec

超速い!!!