6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ubuntuでソフトウェアRAID1

Last updated at Posted at 2013-08-07

参考

状態の確認

$ sudo mdadm  -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Aug  7 17:54:10 2013
     Raid Level : raid1
     Array Size : 488253248 (465.63 GiB 499.97 GB)
  Used Dev Size : 488253248 (465.63 GiB 499.97 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Wed Aug  7 18:31:49 2013
          State : active, resyncing 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

  Resync Status : 15% complete

           Name : ubuntu:0  (local to host ubuntu)
           UUID : 8ea3f796:8fbde6a7:2e29e863:c9927e23
         Events : 14

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1

リビルドの進行状況

$ cat /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdb1[1] sda1[0]
      488253248 blocks super 1.2 [2/2] [UU]
      [===>.................]  resync = 16.4% (80454976/488253248) finish=217.9min speed=31185K/sec
      
unused devices: <none>

障害時の対応

$ sudo mdadm /dev/md0 --remove /dev/sda1
mdadm: hot remove failed for /dev/sda1: Device or resource busy

sda1を切り離す準備(障害通知を送る)

sdaを障害扱いにする。
$ sudo mdadm /dev/md0 --fail /dev/sda1
mdadm: set /dev/sda1 faulty in /dev/md0
$ cat /proc/mdstat 
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdb1[1] sda1[0](F)
      488253248 blocks super 1.2 [2/1] [_U]
      
unused devices: <none>
  • (F)というマークがついた
  • [2/1] [_U]
faulty
$ sudo mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Aug  7 17:54:10 2013
     Raid Level : raid1
     Array Size : 488253248 (465.63 GiB 499.97 GB)
  Used Dev Size : 488253248 (465.63 GiB 499.97 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Wed Aug  7 18:42:22 2013
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 1
  Spare Devices : 0

           Name : ubuntu:0  (local to host ubuntu)
           UUID : 8ea3f796:8fbde6a7:2e29e863:c9927e23
         Events : 216

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       17        1      active sync   /dev/sdb1

       0       8        1        -      faulty spare   /dev/sda1

sda1を切り離す

$ sudo mdadm /dev/md0 --remove /dev/sda1
mdadm: hot removed /dev/sda1 from /dev/md0

交換のため、HDDの型番確認

smartctl
smartctl -a /dev/sda  | egrep "Device Model|Serial Number"
smartctl -a /dev/sdb  | egrep "Device Model|Serial Number"
これでもなんとなくわかる
$ cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: ST3500418AS      Rev: CC44
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: Hitachi HDS72105 Rev: JP2O
  Type:   Direct-Access                    ANSI  SCSI revision: 05
  • サーバーの電源を落とし、Seagate Barracuda 7200.12 を引っこ抜いて、新しいHDDに交換。

sda1を組み込む

$ sudo mdadm /dev/md0 --add /dev/sda1
mdadm: added /dev/sda1

同期の速度

同期の速度
$ cat /proc/sys/dev/raid/speed_limit_max
20000 #=20M
$ cat /proc/sys/dev/raid/speed_limit_min
1000 #=1M

echo 1000 > /proc/sys/dev/raid/speed_limit_max
echo 20000 > /proc/sys/dev/raid/speed_limit_max

grubをインストール

grub.png

$ sudo dpkg-reconfigure grub-pc
Installing for i386-pc platform.
Installation finished. No error reported.
Installing for i386-pc platform.
Installation finished. No error reported.
Generating grub configuration file ...
Linux イメージを見つけました: /boot/vmlinuz-4.4.49-1-pve
Found initrd image: /boot/initrd.img-4.4.49-1-pve
Linux イメージを見つけました: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64

番外編 切り離したsda

sdaでOS起動できるか確認しました。

GRUBの画面が出るが、その後は画面真っ暗で起動しませんでした。

LiveCDで起動した環境からHDDマウントする方法

  • UbuntuのLiveCDの場合、レスキューモードからRAID設定ができ、そこからマウントやgrubの再インストールが出来、簡単です。

  • 他のLiveCDの場合

$ sudo mdadm --stop /dev/md127
mdadm: stopped /dev/md127
$ sudo mdadm --create /dev/md127 --level=1 --raid-devices=2 missing /dev/sda1
mdadm: /dev/sda1 appears to contain an ext2fs file system
    size=488384512K  mtime=Thu Jan  1 00:00:00 1970
mdadm: /dev/sda1 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Wed Aug  7 08:54:10 2013
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md127 started.
$ sudo mount /dev/md127 /mnt

$ sudo umount /mnt
$ sudo mdadm --stop /dev/md127

RAIDの状態監視で、テストメールを送ってみる

$ sudo mdadm --monitor --test --oneshot --scan
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?