# IBM OpenPower Linux

# 安裝 RedHat Linux for Power

機型：IBM Power System S822LC (8001-22C) for big data  
作業系統：RedHat 7.3 for POWER8 Little Endian (NOTE: 此機型只能適用 Little Endian 安裝版本，其他機型適用版本可見附檔區的參考文件:Quick Start Guide for installing Linux on IBM Power System LCservers)

##### 使用心得：

1. 不知為何 Linux 辨識到磁碟代號順序與實機上的位置完全無法做對應。（請見下文的位置對照表）
2. 沒有指令可以識別指定磁碟的實際位置。  
    NOTE: 即使可用 storcli 指令辨識磁碟位置，但它的順序與 Linux 的磁碟順序不一致
3. 雖然內建有 Megaraid 介面卡，卻無法成功建立硬體式的 Raid。  
    NOTE: 使用 storcli 指令新增 raid 失敗，錯誤訊息: Resource already in use

#### 安裝 RedHat Linux

> NOTE: 官方資料顯示支援 RedHat 7.2，但實際上無法安裝此版本，狀況是無法執行光碟開機。

##### 方法：以光碟安裝

連接外接式 USB 光碟機，並置入 RedHat 安裝光碟

主機開啟電源 &gt; Petitboot

畫面的選單上方應該會出現 RedHat 安裝光碟的選項

*\* Install Red Hat Enterprise Linux 7.3 (64-bit kernel)*

移動方向建至該選項，按 Enter 即可進入安裝程序

> TIP: 如過程失敗，參考附檔區文件: Quick Start Guide for installing Linux on IBM Power System LCservers

#### 軟體 Raid 設定

這款機型沒有內建 Raid Adapter，只能使用 RedHat 的 Software Raird。不過在使用與設定上與 x86 機器有許多不同，其中有幾項重點需要注意：

- RedHat for Power 系統開機流程的順序是: BIOS &gt; sda1: PPC PReP Boot &gt; sda2: /boot (GRUB2) &gt; sda3: /
- PPC PReP Boot 這磁區不支援安裝在 Software Raid (注意: 這個爾後可能會造成系統無法正常開機，詳細資訊參閱: 開機磁區複寫至多個磁碟
- /boot 與 / 可安裝在 Software Raid
- 磁區新增如下: 合計 5 顆磁碟 sda, sdb, sdc, sdd, sde 
    1. sda1 = PPC PReP Boot (Power 開機)
    2. sda2 = raid1 /boot (GRUB2 開機)
    3. sda3 = raid6 /
    4. sdb1 = PPC PReP Boot (Power 開機)
    5. sdb2 = raid1 /boot (GRUB2 開機)
    6. sdb3 = raid6 /
    7. sdc1 = raid6 /
    8. sdd1 = raid6 /
    9. sde1 = raid6 /  
        更多詳細資訊可見附檔區
- raid6 的 / 都是 LVM 格式，預設的 VG 名稱是 rhel，LV 名稱是 rhel-&lt;磁區名稱&gt;，例如 rhel-swap
- 設定 raid level 6 時，size policy 建議使用 As large as possible。

> TIP:
> 
> size policy:  
> 預設 Automatic - 這 raid 的 size 是以實際已使用資料量大小為基準，優點是 raid 初始化時比較快速，因此安裝時間也會明顯變短；缺點是未來管理磁碟用量時不是這麼直覺，透過指令檢查 PV 或 VG 的剩餘空間永遠都是 0 - 1 %。  
> As large as possible - 這 raid 的 size 是以包含的所有實體硬碟可用空間做計算，優點是較容易管理整體磁碟空間，透過一般指令就可以控管磁碟用量；缺點是 raid 一開始做初始化，以及爾後需要做 Raid Rebuild 所花費的時間比較久。
> 
> 新增磁區時：  
> 技巧一 - 先移除全部舊磁區，再依序新增 prepboot(sda), prepboot(sdb), /boot, SWAP, /。  
> 技巧二 - 如果多顆磁碟裡存在舊的 PPC PReP Boot 磁區，透過安裝畫面的工具(Anaconda)是無法有效移除，建議方法是先以單顆磁碟做簡單系統安裝，完成後進入系統再以 fdisk 指令一一將不用的開機磁區移除。  
> 技巧三 - 第二顆磁碟上的 prepboot 磁區可能不會正常顯示在畫面上，要確認所有磁區是否新增正確，可以檢視下一頁的 Summary of Changes。  
> 技巧三 - 如果出現訊息: boot loader stage2 device boot is on a multi-disk array but boot loader stage1 sevice sda1 is not ....，可以先忽略它，按下 Done 繼續完成安裝的步驟。  
> 一旦系統完成安裝後，再繼續文章 開機磁區複寫至多個磁碟 的步驟。

#### 安裝後的步驟

關閉 SELinux

```shell
sed -i 's/SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
setenforce 0
```

關閉防火牆

```shell
systemctl stop firewalld.service
systemctl disable firewalld.service
```

##### 硬體監控管理

設定 IPMI (BMC) 網路

網路線連接主機後方的 IPMI Network Port  
主機開啟電源 &gt; Petitboot &gt; Exit to Shell

```
ipmitool lan print 1
ipmitool lan set 1 ipsrc static
ipmitool lan set 1 ipaddr <ipmi-ip-address>
ipmitool lan set 1 netmask <ipmi-ip-netmask>
ipmitool lan set 1 defgw ipaddr <ipmi-ip-gateway>
ipmitool lan print 1 
```

BMC 網頁存取：

> http://ipmi-ip-address/ , 預設登入: ADMIN / ADMIN  
> NOTE: 官方手冊提到的預設帳號與密碼是錯誤的。
> 
> Java 版本是 1.6.0.45 32-bit, Windows 7 64-bit，沒試過其他 Java 版本。

IPMITools 存取：安裝 ipmitool 在 Desktop PC

Ubuntu

```
sudo apt-get update
sudo apt-get install ipmitool
```

以 source 編譯安裝

```shell
wget https://sourceforge.net/projects/ipmitool/files/latest/download
bzip2 -d ipmitool-1.8.15.tar.bz2
tar xvf ipmitool-1.8.15.tar
cd ipmitool-1.8.15
./configure 
```

測試連線

```
顯示所有裝置的 FRU 資訊
ipmitool -I lanplus -H ipmi-ip-address -U ADMIN -P ADMIN fru
```

##### 磁碟名稱與實體位置對應

<table border="1" id="bkmrk-sdb-empty-nvme-empty" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 25%;">sdb</td><td style="width: 25%;">EMPTY</td><td style="width: 25%;">NVMe</td><td style="width: 25%;">EMPTY</td></tr><tr><td style="width: 25%;">sde</td><td style="width: 25%;">sdc</td><td style="width: 25%;">EMPTY</td><td style="width: 25%;">EMPTY</td></tr><tr><td style="width: 25%;">sda</td><td style="width: 25%;">sdd</td><td style="width: 25%;">EMPTY</td><td style="width: 25%;">NVMe</td></tr></tbody></table>

# 建立本地端套件庫主機

( [https://www.ibm.com/support/knowledgecenter/en/SST55W\_4.3.0/liaca/liaca\_config\_os\_yum\_repos.html](https://www.ibm.com/support/knowledgecenter/en/SST55W_4.3.0/liaca/liaca_config_os_yum_repos.html) )

準備一部 FTP/NFS/WWW 主機，將安裝光碟內的所有檔案與目錄上傳到主機，並分享使其他電腦可以存取。

```shell
mount -o loop rhel-server-7.3-ppc64le-dvd.iso /mnt/DVD
cp -r /mnt/DVD/* /mnt/tpeitpfs02_nas/redhat_7.3_ppc64_le/ 
```

本地端套件庫主機建置完成了。

其他 Linux 主機要存取這個套件庫，新增 /etc/yum.repos.d/rhel-media.repo

```
[rhel-media]
name=name=Red Hat Enterprise Linux $releasever - Media
baseurl=ftp://10.10.1.115/LINUX_REPO/redhat_7.3_ppc64_le/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
```

測試連線

```
yum repolist
```

##### 選用: 新增額外的套件至套件庫

如有額外套件要放入套件庫，步驟是：

```shell
mkdir /mnt/tpeitpfs02_nas/redhat_7.3_ppc64_le/optional/Packages
cp your-packages.rpm /mnt/tpeitpfs02_nas/redhat_7.3_ppc64_le/optional/Packages
createrepo /mnt/tpeitpfs02_nas/redhat_7.3_ppc64_le/optional
```

# 開機磁區複寫至多個磁碟

原因：OpenPOWER Linux 開機過程所需的第一個開機磁區 PPC PReP Boot 無法安裝以 Software Raid 型式安裝，雖然在初次安裝系統時不會有任何影響，不過爾後第一顆磁碟因為發生故障，需要更換另一顆完全新的磁碟時，這樣雖然不會立即對系統產生影響，只要系統有做重啟，系統就會無法正常開機，原因是更換後的磁碟並沒有開機磁區。

解決方法就是：使第二顆磁碟也能做開機，步驟如本篇的教學。

> TIP: PPC PReP Boot 這個專屬 IBM Power 機器的開機磁區其作用就像 x86 伺服器的 MBR。

官方教學連結：https://access.redhat.com/discussions/2158911

#### 初次安裝時

確認目前系統可正常運作且第一顆磁碟的磁區狀態如下：

```
# fdisk -l /dev/sda

Disk /dev/sda: 960.2 GB, 960197124096 bytes, 1875385008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000e7231

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048       22527       10240   41  PPC PReP Boot
/dev/sda2           22528     2121727     1049600   fd  Linux raid autodetect
/dev/sda3         2121728  1875384319   936631296   fd  Linux raid autodetect
```

> sda1 Power 開機磁區 (這個需要複寫到第二顆磁碟)
> 
> sda2 Linux 開機磁區 /boot (已做 Raid 1 )
> 
> sda3 LVM 磁區 (已做 Raid6)

複寫 Power 開機磁區至第二顆磁碟 /sdb1

```
dd if=/dev/sda1 of=/dev/sdb1 bs=512 conv=noerror,sync
```

/dev/sdb 磁區清單

```
# fdisk -l /dev/sdb

Disk /dev/sdb: 960.2 GB, 960197124096 bytes, 1875385008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0003819f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       22527       10240   41  PPC PReP Boot
/dev/sdb2           22528     2121727     1049600   fd  Linux raid autodetect
/dev/sdb3         2121728  1875384319   936631296   fd  Linux raid autodetect
```

> sdb 與 sda 的磁區幾乎一樣，主要原因是這兩顆磁碟都被規劃成可開機磁碟。

#### 開機磁碟有更換時

不管是更換 sda 或 sdb 磁碟，更換後都需要手動建立開機磁區以及其他 raid 磁區。

以 /dev/sda 為例

```
fdisk /dev/sda

新增磁區
n > p > 1(default) > 2048(default) > 22527
n > p > 2 (default) > 22528 (default) > 2121727
n > p > 3 (default) > 2121728 (default) > 1875385007 (default)  

設定磁區格式
t > 1 > 41       PPC PReP Boot  
t > 2 > fd        Linux raid 
t > 3 > fd        Linux raid 

設定磁區#1 為開機磁區
a > 1

檢查磁區清單
p

寫入後離開
w 
```

複寫開機磁區從 sdb 到 sda

```
dd if=/dev/sdb1 of=/dev/sda1 bs=512 conv=noerror,sync
```

檢視 Raid

```
# cat /proc/mdstat
Personalities : [raid1] [raid6] [raid5] [raid4]
md126 : active raid1 sdb2[1]
      1049536 blocks super 1.0 [2/1] [_U]
      bitmap: 1/1 pages [64KB], 65536KB chunk

md127 : active raid6 sdb3[1] sdd1[3] sde1[4] sdc[5]
      2809500672 blocks super 1.2 level 6, 512k chunk, algorithm 2 [5/4] [_UUUU]
      bitmap: 1/1 pages [64KB], 65536KB chunk

unused devices: <none>

# mdadm --detail /dev/md126
/dev/md126:
        Version : 1.0
  Creation Time : Mon Feb 20 23:30:01 2017
     Raid Level : raid1
     Array Size : 1049536 (1024.94 MiB 1074.72 MB)
  Used Dev Size : 1049536 (1024.94 MiB 1074.72 MB)
   Raid Devices : 2
  Total Devices : 1
    Persistence : Superblock is persistent

  Intent Bitmap : Internal

    Update Time : Fri Feb 24 19:55:16 2017
          State : clean, degraded
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           Name : localhost.localdomain:boot
           UUID : 1b78d1ea:f5380532:4fe25553:20ef8396
         Events : 44

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       1       8       18        1      active sync   /dev/sdb2

# mdadm --detail /dev/md127
/dev/md127:
        Version : 1.2
  Creation Time : Mon Feb 20 23:30:10 2017
     Raid Level : raid6
     Array Size : 2809500672 (2679.35 GiB 2876.93 GB)
  Used Dev Size : 936500224 (893.12 GiB 958.98 GB)
   Raid Devices : 5
  Total Devices : 4
    Persistence : Superblock is persistent

  Intent Bitmap : Internal

    Update Time : Fri Feb 24 14:42:10 2017
          State : clean, degraded
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : localhost.localdomain:pv00
           UUID : f7a62cb2:b269daa9:29f8025f:6fcef40f
         Events : 4769

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       1       8       19        1      active sync   /dev/sdb3
       5       8       32        2      active sync   /dev/sdc
       3       8       49        3      active sync   /dev/sdd1
       4       8       65        4      active sync   /dev/sde1
```

重建 Raid

```
# fdisk -l /dev/sda

Disk /dev/sda: 960.2 GB, 960197124096 bytes, 1875385008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000e7231

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048       22527       10240   41  PPC PReP Boot
/dev/sda2           22528     2121727     1049600   fd  Linux raid autodetect
/dev/sda3         2121728  1875385007   936631640   fd  Linux raid autodetect

# mdadm /dev/md126 --add /dev/sda2
# mdadm /dev/md127 --add /dev/sda3 
```

# 磁碟管理-StorCLI

這款機器的 Local Disks 都連結在內建的 MegaRAID (MegaRAID SAS-3 3108) 介面上，如果系統已經安裝好 Linux，可以透過指令 lshw 確認這個裝置存在。

> 雖然有 Raid 卡，卻無法建立 Raid，從 Petitboot 指令模式下，使用 storcli 指令新增 Raid 失敗。  
> 錯誤訊息: Resources already in use

##### 下載安裝 StorCLI

下載網址：https://www.broadcom.com/support/download-search/?pg=&amp;pf=&amp;pn=&amp;po=&amp;pa=&amp;dk=storcli

StorCLI for Linux 其實只是一個編譯過的指令 storcli (storcli64 for 64-bit)，官方只是將這指令包裝成 RPM 或 DEB 方便用戶在可以在不同的作業系統版本做安裝；只是筆者從連結下載的壓縮包，解開後找不到 PPC64LE for RedHat，但有看到 PPC64LE for Ubuntu (\*.deb)，所以只要用另一部 Windows 或 Linux 電腦將 \*.deb 解開就會看到一個檔案 `storcli64` 。

將這個檔案複製到已經安裝好的 RedHat Linux 即可使用。

> storcli64 也能用在 Petitboot，直接用 scp 或 wget 從外部電腦複製。

##### 在 Linux 內確認 MegaRAID 裝置

```
# lshw

...
*-raid
   description: RAID bus controller
   product: MegaRAID SAS-3 3108 [Invader]
   vendor: LSI Logic / Symbios Logic
   physical id: 0
   bus info: pci@0001:03:00.0
   logical name: scsi0
   version: 02
   width: 64 bits
   clock: 33MHz
   capabilities: raid pm pciexpress vpd msi msix bus_master cap_list rom
   configuration: driver=megaraid_sas latency=0
   resources: irq:507 memory:3fe080200000-3fe08020ffff memory:3fe080000000-3fe0800fffff memory:3fe080100000-3fe0801fffff
 *-enclosure UNCLAIMED
      description: SCSI Enclosure
      product: SAS3x28
      vendor: LSI
      physical id: 0.8.0
      bus info: scsi@0:0.8.0
      version: 0601
      configuration: ansiversion=5
 *-disk:0
      description: ATA Disk
      product: SDLF1DAR-960G-1H
      physical id: 0.9.0
      bus info: scsi@0:0.9.0
      logical name: /dev/sda
      version: ZH06
      serial: A008676A
      size: 894GiB (960GB)
      capacity: 894GiB (960GB)
      capabilities: 15000rpm partitioned partitioned:dos
      configuration: ansiversion=6 logicalsectorsize=512 sectorsize=4096 signature=000e7231
    *-volume:0
         description: PPC PReP Boot partition
         physical id: 1
         bus info: scsi@0:0.9.0,1
         logical name: /dev/sda1
         capacity: 10MiB
         capabilities: primary bootable boot
    *-volume:1
         description: Linux raid autodetect partition
         physical id: 2
         bus info: scsi@0:0.9.0,2
         logical name: /dev/sda2
         capacity: 1025MiB
         capabilities: primary multi
    *-volume:2
         description: Linux raid autodetect partition
         physical id: 3
         bus info: scsi@0:0.9.0,3
         logical name: /dev/sda3
         capacity: 893GiB
         capabilities: primary multi
 *-disk:1
      description: ATA Disk
      product: SDLF1DAR-960G-1H
      physical id: 0.a.0
      bus info: scsi@0:0.10.0
      logical name: /dev/sdb
      version: ZH06
      serial: A0086638
      size: 894GiB (960GB)
      capacity: 894GiB (960GB)
      capabilities: 15000rpm partitioned partitioned:dos
      configuration: ansiversion=6 logicalsectorsize=512 sectorsize=4096 signature=0003819f
    *-volume:0
         description: PPC PReP Boot partition
         physical id: 1
         bus info: scsi@0:0.10.0,1
         logical name: /dev/sdb1 
...
```