2019年8月19日 星期一

Linux I / O調度器

**  Linux I / O調度器
    Linux I / O調度器是控制內核提交讀寫請求給磁盤的方式。Linux的支持三種I / O電梯調度算法,分別為CFQ,Noop,Deadline三種。簡單介紹下這三種。

    **CFQ(完全公平調度程序)
    完全公平調度器(CFQ)自kernel2.6.18後成為了Linux默認的I / O調度器,它也是大多數Linux發行版的默認調度器。
    CFQ調度器的目的是為所有請求I / O操作的進程提供一個公平的磁盤I / O帶寬分配。
    CFQ調度器為每個進程單獨創建一個同步I / O隊列來管理其同步的請求然後為每個隊列分配訪問磁盤的時間片。
    時間片長度和隊列允許提交的請求數取決於其進程的I / O優先級。以此保證每個進程的I / O資源佔用是公平的。
    CFQ算法的特點是按照I / O請求的地址進行排序,而不是按照先來後到的順序進行響應。這樣減少了不必要的磁盤尋道,提高了吞吐量。
    但也意味著,先來的I / O請求可能不能盡快得到響應,可能出現餓死現象。

    **Deadline調度器主要目的是保證請求的啟動服務時間。它在所有的I / O請求上加上一個期限來防止請求餓死。
    除了本身提供的I / O排隊隊列之外,Deadline額外分為為讀I / O和寫I / O提供了FIFO隊列。排序隊列按照按照扇區數排序,FIFO隊列按照截止時間排序。
    FIFO隊列優先級高於排隊隊列,讀隊列優先級高於寫隊列。排序隊列使用紅黑樹結構,而FIFO使用鍊錶結構。讀FIFO隊列的最大等待時間為500ms,寫FIFO隊列的最大等待時間為5s。
    截止日期算法會在寫隊列沒有發生飢餓的情況下處理讀隊列,在進入讀隊列處理時,會首先檢查FIFO讀隊列查看是否有過期請求,如果有就優先處理它。
    如果前面寫隊列出現飢餓,意即FIFO寫隊列有過期請求,它就會進入寫隊列處理然後處理FIFO中過期的寫請求。
    截止日期本質還是基於CFQ的,只不過加了兩個FIFO隊列來避免餓死問題。
    Deadline調度器更適合用於多線程處理環境和數據庫環境。避免了CFQ調度器的餓死問題。

    **Noop調度器非常簡單,它提供了一個最簡單的FIFO隊列並對請求進行簡單的合併處理。
    當確定不需要根據扇區號來對請求排序時,這個調度器是非常高效的。比較適合在SSD上面應用。
    總的來看,Noop更適合固態硬盤。截止日期適合需要優先保證讀操作且避免餓死的情況如數據庫場景。
    CFQ比較複雜,容易出現餓死問題,但保證了盡可能的公平。推薦固態硬盤下可以考慮把默認的CFQ調度器改為Noop調度器或者Deadline調度器。

    更換Linux I / O調度器
    可以通過如下命令查看你當前的I / O調度器:
    cat /sys/block/sdb/queue/scheduler or
    for i in `ls /sys/block/*/queue/scheduler`; do echo $i;cat $i; done

    如果想修改的話,可以先進入su然後執行:
    echo noop > /sys/block/sdb/queue/scheduler
    把可以noop換位cfq或者deadline。

Linux memory setting.


root@OCTEONTX:/home/horatio# sysctl -a |grep vm
vm.admin_reserve_kbytes = 8192
vm.block_dump = 0
vm.compact_unevictable_allowed = 1
vm.dirty_background_bytes = 0
vm.dirty_background_ratio = 10
vm.dirty_bytes = 0
vm.dirty_expire_centisecs = 3000
vm.dirty_ratio = 20
vm.dirty_writeback_centisecs = 500
vm.dirtytime_expire_seconds = 43200
vm.drop_caches = 0
vm.extfrag_threshold = 500
vm.hugepages_treat_as_movable = 0
vm.hugetlb_shm_group = 0
vm.laptop_mode = 0
vm.legacy_va_layout = 0
vm.lowmem_reserve_ratio = 256   32
vm.max_map_count = 65530
vm.min_free_kbytes = 829120
vm.min_slab_ratio = 5
vm.min_unmapped_ratio = 1
vm.mmap_min_addr = 32768
vm.mmap_rnd_bits = 14
vm.nr_hugepages = 0
vm.nr_hugepages_mempolicy = 0
vm.nr_overcommit_hugepages = 0
vm.nr_pdflush_threads = 0
vm.numa_zonelist_order = default
vm.oom_dump_tasks = 1
vm.oom_kill_allocating_task = 0
vm.overcommit_kbytes = 0
vm.overcommit_memory = 0
vm.overcommit_ratio = 50
vm.page-cluster = 3
vm.panic_on_oom = 0
vm.percpu_pagelist_fraction = 0
vm.stat_interval = 1
vm.swappiness = 60
vm.user_reserve_kbytes = 131072
vm.vfs_cache_pressure = 100
vm.watermark_scale_factor = 10
vm.zone_reclaim_mode = 1

**  手動清除 Linux 記憶體快取
    若寫入 1 會清除 pagecache:
    # echo 1 > /proc/sys/vm/drop_caches
    若寫入 2 會清除 dentries 與 inodes:
    # echo 2 > /proc/sys/vm/drop_caches
    若寫入 3 則有等同於 1+2 的效果,會清除 pagecache、dentries 及 inodes:
    # echo 3 > /proc/sys/vm/drop_caches
   
**  overcommit_memory
    定義接受或拒絕大型記憶體需求的狀況。此參數有三種可用值:
    0 — 預設設定。kernel 會進行探索式的記憶體過度寫入處理,方法是預測記憶體的可用量、並讓公然違規的需求失敗。不幸的是,因為記憶體是以探索式、而非精準的演算法則來分配,因此這設定有時會過度使用系統上的可用記憶體。
    1 — kernel 不進行記憶體過度寫入處理。在此設定下,過度使用記憶體的機會會增加,但對於頻繁存取記憶體的任務來說,效能也會增加。
    2 — kernel 拒絕相等或大於總可用置換空間與實體記憶體比例(於 overcommit_ratio 指定)的記憶體需求。如果您想要降低記憶體過度寫入的風險,這是最佳設定。 

**  vfs_cache_pressure 可以控制系統清除cache的頻率.
    數值設定低會導致內核傾向於保留dentry和inode於記憶體中.
    高就會提高清除重建的頻率.
    cat /proc/sys/vm/vfs_cache_pressure
    sysctl vm.vfs_cache_pressure=50
    sysctl vm.vfs_cache_pressure=10000
   
**  vm.dirty_background_ratio 這個參數主要是降低 Linux 寫檔案(dirty page)的 buffer 大小,
    如果是寫入的量很大的系統建議降低此值,
    這樣會讓寫入更連續而且一致,而不會分批次每次都寫入大量的資料.
    sysctl vm.dirty_background_ratio=1
    您可藉由編輯 /etc/sysctl.conf 檔案來永久性地更改這些參數的值

**  vm.dirty_writeback_centisecs 單位是百分之一秒,這個就是多久要觸發回寫
    sysctl vm.dirty_writeback_centisecs

**  vm.dirty_expire_centisecs = 1000 單位也是百分之一秒,
    這個是表示 dirty page 過了多久之後下次 pdflush kernel thread 醒來時就會被寫回硬碟,
    預設是 3000 也就是 30 秒,一樣可以設低一點讓寫入均勻化,不過太低會一直寫,也不宜太低。

** Zone_reclaim_mode
       該參數只有在啟用CONFIG_NUMA選項時才有效。
       允許某人在區域內存不足時設置或多或少的積極方法來回收內存。
       如果設置為零,則不會發生區域回收。
       將從系統中的其他區域/節點滿足分配
       zone_reclaim_mode用來控制在內存域OOM時,如何來回收內存。
       如果設置為0,則禁止內存域回收,從系統中其他內存域或節點來滿足內存分配請求。
       這個參數可以使用下面的值通過或運算來設置:
        1  = 啟用內存域回收    => OK
        2  = 刷臟頁回收內存
        4  = 通過swap回收內存
      如果檢測到從其他內存域分配內存會造成性能下降,啟動的時候會將zone_reclaim_mode設置為1。
      頁面分配器在從節點分配頁面前,會先回收容易重用的頁面(當前未使用的pagecache頁面)。
      如果系統是用作文件服務器,所有的內存都可以用作緩存磁盤上的文件,這種情況下關閉內存域回收是有好處的,緩存的作用要比數據的局部性作用大。
      通過刷臟頁進行內存域回收,會阻止寫入大量數據的進程在其他節點上產生臟頁。
      如果內存域填滿了,會刷出臟頁釋放內存,因此可以使進程節流。
      這可能會降低單個進程的性能,因為它不能使用系統所有的內存來緩衝寫入的數據,但是使用其他節點的進程不會受到影響。
      通過swap釋放內存可以將分配嚴格限制在本地節點,除非明確使用了特定的內存策略或綁定設置來覆蓋這個設置。

Linux FIO 測試!

Fio  test.fio


**  Fio setting   
[global]

filename=/dev/sdb

ioengine=libaio
#ioengine=sync

#direct=bool
#If value is true, use non-buffered I/O. This is usually O_DIRECT.
#Note that OpenBSD and ZFS on Solaris don’t support direct I/O.
#On Windows the synchronous ioengines don’t support direct I/O. Default: false.
direct=1

time_based
ramp_time=5
refill_buffers
group_reporting
wait_for_previous

#size=200G
runtime=1m

#This option also allows a range of CPUs to be specified
#say you wanted a binding to CPUs 0, 5, and 8 to 15, you would set cpus_allowed=0,5,8-15.
#cpus_allowed=0,1

[JOB1]
bs=1M
rw=read
numjobs=4
iodepth=1

[JOB2]
bs=1M
rw=write
numjobs=8
iodepth=1

#[JOB3]
#bs=4k
#rw=write

#[JOB4]
#bs=32k
#rw=write


root@OCTEONTX:/home/horatio# pstree
systemd-+-agetty
        |-cgmanager
        |-cron
        |-dbus-daemon
        |-dhclient
        |-dnsmasq---dnsmasq
        |-ha_logd---ha_logd
        |-libvirtd---15*[{libvirtd}]
        |-login---bash
        |-multipathd---4*[{multipathd}]
        |-sshd-+-sshd---sshd---bash---sudo---su---bash---fio-+-6*[fio]
        |      |                                             `-{fio}
        |      `-sshd---sshd---bash---sudo---su---bash---pstree
        |-sudo---DTRGuiSrv_64-+-DTRGuiSrv_64
        |                     `-DTRGuiSrv_64---java-+-{C1 CompilerThre}
        |                                           |-2*[{C2 CompilerThre}]
        |                                           |-{Finalizer}
        |                                           |-{Reference Handl}
        |                                           |-{Service Thread}
        |                                           |-{Signal Dispatch}
        |                                           |-{Thread-1}
        |                                           |-{Timer-0}
        |                                           |-{VM Periodic Tas}
        |                                           |-{VM Thread}
        |                                           `-5*[{java}]
        |-systemd---(sd-pam)
        |-systemd-journal
        |-systemd-logind
        |-systemd-timesyn---{sd-resolve}
        |-systemd-udevd
        `-vsftpd

root@OCTEONTX:/home/horatio# pstree -p
systemd(1)-+-agetty(3357)
           |-cgmanager(2898)
           |-cron(2936)
           |-dbus-daemon(2983)
           |-dhclient(3355)
           |-dnsmasq(3601)---dnsmasq(3602)
           |-ha_logd(3095)---ha_logd(3098)
           |-libvirtd(3054)-+-{libvirtd}(3100)
           |                |-{libvirtd}(3101)
           |                |-{libvirtd}(3102)
           |                |-{libvirtd}(3103)
           |                |-{libvirtd}(3104)
           |                |-{libvirtd}(3105)
           |                |-{libvirtd}(3106)
           |                |-{libvirtd}(3107)
           |                |-{libvirtd}(3108)
           |                |-{libvirtd}(3109)
           |                |-{libvirtd}(3113)
           |                |-{libvirtd}(3114)
           |                |-{libvirtd}(3115)
           |                |-{libvirtd}(3116)
           |                `-{libvirtd}(3117)
           |-login(3362)---bash(6028)
           |-multipathd(1664)-+-{multipathd}(1665)
           |                  |-{multipathd}(1666)
           |                  |-{multipathd}(1667)
           |                  `-{multipathd}(1668)
           |-sshd(3072)-+-sshd(6039)---sshd(6048)---bash(6049)---sudo(6578)---su(6579)---bash(6580)---fio(6598)-+-fio(6600)
           |            |                                                                                       |-fio(6601)
           |            |                                                                                       |-fio(6602)
           |            |                                                                                       |-fio(6603)
           |            |                                                                                       |-fio(6604)
           |            |                                                                                       |-fio(6605)
           |            |                                                                                       `-{fio}(6599)
           |            `-sshd(6058)---sshd(6067)---bash(6068)---sudo(6563)---su(6564)---bash(6565)---pstree(6629)
           |-sudo(3075)---DTRGuiSrv_64(3097)-+-DTRGuiSrv_64(3300)
           |                                 `-DTRGuiSrv_64(3301)---java(3302)-+-{C1 CompilerThre}(3316)
           |                                                                   |-{C2 CompilerThre}(3314)
           |                                                                   |-{C2 CompilerThre}(3315)
           |                                                                   |-{Finalizer}(3312)
           |                                                                   |-{Reference Handl}(3311)
           |                                                                   |-{Service Thread}(3317)
           |                                                                   |-{Signal Dispatch}(3313)
           |                                                                   |-{Thread-1}(3545)
           |                                                                   |-{Timer-0}(3546)
           |                                                                   |-{VM Periodic Tas}(3318)
           |                                                                   |-{VM Thread}(3310)
           |                                                                   |-{java}(3305)
           |                                                                   |-{java}(3306)
           |                                                                   |-{java}(3307)
           |                                                                   |-{java}(3308)
           |                                                                   `-{java}(3309)
           |-systemd(6023)---(sd-pam)(6024)
           |-systemd-journal(1660)
           |-systemd-logind(2901)
           |-systemd-timesyn(6240)---{sd-resolve}(6241)
           |-systemd-udevd(2259)
           `-vsftpd(3074)

root@OCTEONTX:/home/horatio# iostat -dx 1
Linux 4.9.0-OCTEONTX_SDK_6_1_0_p3_build_22 (OCTEONTX)   08/19/19        _aarch64_       (24 CPU)

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.05     0.06    0.06    0.14     4.21     3.87    81.94     0.00    5.24    3.22    6.16   1.17   0.02
sdb               0.00     0.05    0.05    2.46     0.25  1253.47   998.82     0.25   98.53    8.95  100.53   0.72   0.18
sdc               0.00     0.00    0.00    0.00     0.02     0.00   141.20     0.00    0.20    0.20    0.00   0.20   0.00


2018年9月3日 星期一

Rebuild kernel with Ubuntu kernel source

##  Ubuntu kernel source
    **  網站支援KERNEL
    **  https://github.com/torvalds/linux
   **  首先看一下自己的内核版本
    **  apt-cache search linux-source
    **  自動抓取相同KERNEL
    **  sudo apt-get install linux-source
    **  sudo apt-get install linux-source-4.4.0


##  Ubuntu 16.04 server rebuild kernel
    **  安裝必要套件
    **  sudo apt-get update
    **  sudo apt-get install libncurses-dev
    **  sudo apt-get install fakeroot build-essential kernel-package ncurses-dev libssl-dev xz-utils
    **  sudo apt-get install fakeroot build-essential kernel-package libncurses5 libncurses5-dev
    **  sudo apt-get install fakeroot build-essential kernel-package libncurses5 libncurses5-dev  bin86 linux-kernel-devel  debhelper modutils
    sudo apt-get install fakeroot build-essential kernel-package libncurses5 libncurses5-dev  linux-kernel-devel  debhelper modutils


##  Complier kernel and update
    **  使用mak3-kpkg安裝
        1.  make-kpkg clean
        2.  fakeroot make-kpkg --initrd kernel_image kernel_headers (complier 相關 .deb)
        3.  sudo dpkg -i linux-image-3.7.2_3.7.2-10.00.Custom_i386.deb
        4.  sudo dpkg -i linux-headers-3.7.2_3.7.2-10.00.Custom_i386.deb
     
    **  標準安裝

##  移除舊核心
    **  dpkg --get-selections | grep linux-image 顯示現有核心
    **  sudo apt-get purge linux-image-2.6.38-10-generic     移除特地核心
    **  sudo update-grub2 

A. 安裝Kernel:
Step1. 搜尋(檢查)想要安裝的kernel版本是否存在
        $ sudo apt-cache search linux-image-*

       或者填入版本號搜尋,將X.X.XX填入版本號
        $ sudo apt-cache search linux-image-X.X.XX-generic

Step2. 開始安裝kernel
        $ sudo apt-get install linux-image-X.X.XX-generic
        $ sudo apt-get install linux-image-4.15.0-33-generic

        如果有其他需求,像是編譯模組,可以連headers都裝上
        $ sudo apt-get install linux-headers-X.X.XX-generic
     
Step3. 安裝後,更新initramfs image,詳細man update-initramfs
        $ sudo update-initramfs -u -k all

       或者使用
        $ sudo update-initramfs -u -k `uname -r`
Step4. 接著更新grub清單
        $ sudo update-grub

Step5. 重開機
        $ sudo reboot

        按ESC鍵進入GRUB選單,選擇安裝的Kernel開機


B.移除Kernel:
Step1. 檢查目前正在用哪個kernel
        $ uname -a
Step2. 或者列出目前系統中已安裝哪些kernel
        $ dpkg --get-selections | grep linux-image
Step3. 移除不要的Kernel,會自動將相關版本的 linux-image-extra-* 也一併移除
        $ sudo apt-get purge linux-image-X.X.XX-XX-generic

    wget https://github.com/torvalds/linux/archive/v4.5.tar.gz
    tar -xvf v4.5.tar.gz
    cd linux-4.5/
 
    sudo apt-get install build-essential ncurses-dev libssl-dev build-essential ncurses-dev xz-utils kernel-package
    sudo make -j 4 clean
    sudo make -j 4
    sudo make modules -j 4
    sudo make modules_install
    sudo make install
   sudo mkinitramfs -o /boot/initrd.img-4.5
   sudo update-initramfs -c -k 4.5
 
    sudo apt update 更新系統的所有存儲庫。
    sudo apt upgrade -y 升級安裝的所有軟件包。
    sudo reboot 重新啟動服務器以確保應用可能安裝的內核更新。
    sudo apt list --upgradeable 現在再次檢查可升級包,並使用以下命令。
 
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.2/linux-headers-4.11.2-041102_4.11.2-041102.201705201036_all.deb
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.2/linux-headers-4.11.2-041102-generic_4.11.2-041102.201705201036_amd64.deb
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.2/linux-image-4.11.2-041102-generic_4.11.2-041102.201705201036_amd64.deb
    dpkg -i *.deb 使用dpkg命令安裝軟件包。
    sudo update-grub 內核程序包安裝完成後,更新grub並重新啟動系統。
    sudo reboot

如果想解壓*.src.rpm格式的包,可以執行rpm2cpio命令。

##  如果想解壓*.src.rpm格式的包,可以執行rpm2cpio命令。

    如下所示,有個*.src.rpm文件:
    [ root@localhost liusu]# ll
    total 1164
    -rw-r--r-- 1 root root 1188824 Nov 15 09:42 openstack-keystone-9.0.0-1.el7.src.rpm
   
    執行rpm2cpio命令來解壓:
    [ root@localhost liusu]# rpm2cpio openstack-keystone-9.0.0-1.el7.src.rpm |cpio -iv
    keystone-9.0.0.tar.gz
    keystone-dist.conf
    openstack-keystone-sample-data
    openstack-keystone.logrotate
    openstack-keystone.service
    openstack-keystone.spec
    openstack-keystone.sysctl
    2331 blocks
   
    如下所示,加壓後得文件列表:
    [ root@localhost liusu]# ll
    total 2352
    -rw-rw-r-- 1 root root 1181342 Nov 15 09:43 keystone-9.0.0.tar.gz
    -rw-rw-r-- 1 root root 263 Nov 15 09:43 keystone-dist.conf
    -rw-r--r-- 1 root root 1188824 Nov 15 09:42 openstack-keystone-9.0.0-1.el7.src.rpm
    -rw-rw-r-- 1 root root 96 Nov 15 09:43 openstack-keystone.logrotate
    -rwxrwxr-x 1 root root 53 Nov 15 09:43 openstack-keystone-sample-data
    -rw-rw-r-- 1 root root 242 Nov 15 09:43 openstack-keystone.service
    -rw-rw-r-- 1 root root 10122 Nov 15 09:43 openstack-keystone.spec
    -rw-rw-r-- 1 root root 201 Nov 15 09:43 openstack-keystone.sysctl
   
##  .tar.bz2
    套件名稱:bzip2。
    壓縮:
    [ jonny@linux ~ ]
    $ tar jcvf FileName.tar.bz2 DirName
    解壓縮:
    [ jonny@linux ~ ]
    $ tar jxvf FileName.tar.bz2
   

embededed system with CentOS boot setting terminal.


##  CentOS boot setting.

    ** CentOS 6.9 boot setting.
    serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
    terminal --timeout=0 serial console
    default=1
    timeout=5
    #splashimage=(hd0,0)/grub/splash.xpm.gz
    #hiddenmenu
   
    title Accusys 1U Switch Core (3nd Generation V2)
            root (hd0,0)
            kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=/dev/sda3  crashkernel=auto  console=ttyS0,115200n8 acscfg=1
            initrd /initramfs-2.6.32-696.el6.x86_64.img
   
    title Accusys 1U Switch Core (3nd Generation V2) Dev
            root (hd0,0)
            kernel /bzImage ro root=/dev/sda3  crashkernel=auto  console=ttyS0,115200n8 acscfg=1
            initrd /initramfs-2.6.32-696.el6.x86_64.img
   
    title CentOS 6 (2.6.32-696.el6.x86_64) Default boot setting
            root (hd0,0)
            kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=4df0d800-6b42-47f8-99da-5b50987f3824 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
            initrd /initramfs-2.6.32-696.el6.x86_64.img


    ** CentOS 5.8 boot setting.
    serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
    terminal --timeout=0 serial console
    default=2
    timeout=5
    title Accusys 1U Switch Core (3nd Generation)
            root (hd0,0)
            kernel /boot/vmlinuz-2.6.18-308.el5 ro root=/dev/sda1 crashkernel=128M@16M console=ttyS0,115200n8 acscfg=1
            initrd /boot/initrd-2.6.18-308.el5.img
   
    title Accusys 1U Switch Core (3nd Generation safe mode)
            root (hd0,0)
            kernel /boot/bzImage ro root=/dev/sda1 crashkernel=128M@16M console=ttyS0,115200n8 acscfg=1
            initrd /boot/initrd-2.6.18-308.el5.img
   
   
    title Accusys 1U Switch Core (3nd Generation Sam Debug mode)
            root (hd0,0)
            kernel /root/bzImage ro root=/dev/sda1 crashkernel=128M@16M console=ttyS0,115200n8 acscfg=1
            initrd /boot/initrd-2.6.18-308.el5.img


##  BIOS/GRUB/Kernel/XEN輸出重定向到串口的配置:

    將BIOS輸出重定向到串口
    這一功能需要主板支援,在BIOS中設置,比如我的設置為:
    Server ManagementConsole RedirectionConsole Redirection設置為”Serial Port A”
   
    將GRUB輸出重定向到串口(Edit /boot/grub/grub.conf)
    serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
    terminal --timeout=5 console serial
   
    grub引導過程中,會將輸出同時發送到終端螢幕和串口. grub引導過程中將在終端和連接到串口的超級終端上提示Press any key to continue,
    每秒鐘提示一次,共5次,可修改menu.lst檔terminal行中的--timeout=10改變提示次數,在這一段時間內,可以在終端的鍵盤,
    或者連接到串口的超級終端中按任意鍵進入grub選擇功能表.如果5秒內沒有在終端和連接串口的超級終端上按任意鍵,
    則grub的選擇功能表將出現在console上,如果希望默認情況下, grub選擇功能表出現在串口上,則可修改grub.conf將console serial修改為serial console.
   
    將kernel輸出資訊輸出到串口(編輯/boot/grub/grub.conf有的為menu.lst)
    增加kernel引導參數如下:
   
    kernel  /boot/vmlinuz-2.6.32-29 root=/dev/hda1 ro console=ttyS0,115200n8 console=tty0
   
    則kernel會將輸出資訊同時輸出到串口(ttyS0即COM1)和終端tty0。
    其中,“ttyS0”表示串口使用COM1;“115200”表示串列傳輸速率為115200bps;“n”表示無校驗位;“8”表示有8位元資料位元
   
##  kernel login message 修正為 Accusys login message
    "cat /etc/issue"
    Accusys PCIE SAN 1U Switch
    Kernel \r on an \m
   
##  To auto login to linux console on boot
    edit /etc/init/tty.conf (但是Switch 是ttys0設定方式不同)

    修正 /etc/init/tty.conf
    "exec /sbin/mingetty $TTY"
    改為
    "exec /sbin/mingetty --autologin root $TTY"
   
    [root@localhost ~]# cat /etc/init/tty.conf
    # tty - getty
    #
    # This service maintains a getty on the specified device.
    #
    # Do not edit this file directly. If you want to change the behaviour,
    # please create a file tty.override and put your changes there.
   
    stop on runlevel [S016]
   
    respawn
    instance $TTY
    #exec /sbin/mingetty $TTY
    exec /sbin/mingetty --autologin root $TTY
    usage 'tty TTY=/dev/ttyX  - where X is console id'
    [root@localhost ~]#

##  To auto login to linux serial console on boot
    edit /etc/init/serial.conf

    修正 /etc/init/serial.conf
    "exec /sbin/agetty /dev/$DEV $SPEED vt100-nav"
    改為
    "exec /sbin/agetty -n -l /usr/sbin/autologin /dev/$DEV $SPEED vt100-nav"
    但是 /usr/sbin 找不到 autologin
    我們要自己準備 autologin.c,  code 如下,

    #include "unistd.h"
    int main()
    {
        execlp( "login", "login", "-f", "root", NULL);
    }
    產生執行檔
    gcc autologin.c -o autologin, 將檔案放在你要存放的位子
   
    [root@localhost ~]# cat /etc/init/serial.conf
    # Automatically start a configured serial console
    #
    # How this works:
    #
    # On boot, a udev helper examines /dev/console. If a serial console is the
    # primary console (last console on the commandline in grub),  the event
    # 'fedora.serial-console-available <port name> <speed>' is emitted, which
    # triggers this script. It waits for the runlevel to finish, ensures
    # the proper port is in /etc/securetty, and starts the getty.
    #
    # If your serial console is not the primary console, or you want a getty
    # on serial even if it's not the console, create your own event e.g.
    # /etc/init/ttyS0.conf with content:
    # # ttyS0 - agetty
    # #
    # # This service maintains a agetty on ttyS0.
    #
    # stop on runlevel [S016]
    # start on runlevel [23]
    #
    # respawn
    # exec agetty -h -L -w /dev/ttyS0 115200 vt102
    #
    # Do not edit this file directly. If you want to change the behaviour,
    # please create a file serial.override and put your changes there.
   
    start on fedora.serial-console-available DEV=* and stopped rc RUNLEVEL=[2345]
    stop on runlevel [S016]
   
    instance $DEV
    respawn
    pre-start exec /sbin/securetty $DEV
    #exec /sbin/agetty /dev/$DEV $SPEED vt100-nav
    exec /sbin/agetty -n -l /root/autologin /dev/$DEV $SPEED vt100-nav
    post-stop exec /sbin/initctl emit --no-wait fedora.serial-console-available DEV=$DEV SPEED=$SPEED
    usage 'DEV=ttySX SPEED=Y  - where X is console id and Y is baud rate'


   

Rebuild kernel with CentOS 6.9 Source code

##  Get CentOS 6.9 Source code

    "yum -y install kernel-devel"  安裝complier tool
    "mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}" 創建一個Build source folder
    "echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros" 指定創建位址
 
    要在 CentOS-6 安裝源代碼套件及工具:

    以 root 的身份安裝 rpm-build、redhat-rpm-config、asciidoc、bison、hmaccalc、patchutils、perl-ExtUtils-Embed、
    xmlto、audit-libs-devel、binutils-devel、elfutils-devel、elfutils-libelf-devel、newt-devel、python-devel 及 zlib-devel 套件:
    "yum -y install rpm-build redhat-rpm-config asciidoc bison hmaccalc patchutils perl-ExtUtils-Embed xmlto"
    "yum -y install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel"
    "yum -y install ncurses-devel newt-devel python-devel zlib-devel"
    "yum -y install openssl-devel"
 
    "yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed pesign xmlto"
    "yum install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel"
    "yum install ncurses-devel newt-devel numactl-devel pciutils-devel python-devel zlib-devel"
 
    從這些地方找尋內核的源代碼套件:
    http://vault.centos.org/6.N/os/Source/SPackages/
    http://vault.centos.org/6.N/updates/Source/SPackages/
    or 直接抓取
    "rpm -i http://vault.centos.org/6.9/updates/Source/SPackages/kernel-2.6.32-696.28.1.el6.src.rpm 2>&1 | grep -v exist"
 
    Build 出 CentOS source code,
    "cd ~/rpmbuild/SPECS"
    "rpmbuild -bp --target=$(uname -m) kernel.spec"
 
    Centos source code in /root/rpmbuild/BUILD/kernel-2.6.32-696.28.1.el6/linux-2.6.32-696.28.1.el6.x86_64
 
    PS. 若發現GCC太舊,請update gcc "yum update gcc"

 
##  安裝網路設定命令工具
    #系統設定套件 - setup 工具包
    yum -y install setuptool
   
    #系統設定套件 - 服務套件
    yum -y install ntsysv
   
    #系統設定套件 - 網路管理
    yum -y install system-config-network-tui
   
    #系統設定套件 - 防火牆設定
    yum -y install system-config-firewall-tui
   
    #系統設定套件 - 安全性設定
    yum -y install system-config-securitylevel-tui