Skip to main content

開機磁區複寫至多個磁碟

原因: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