RAID1パーティションのディスクを拡張して容量を増やす(mdadm)

Raspberry PiのUSBメモリパーティション(RAID1)を、より容量の大きいUSBメモリに置き換え、ファイルシステムを拡張することにしたので、作業ログを公開。

作業の前提は、

  • sda1:今回追加するディスク
  • sdb1:既存アレイのディスク1(もともと容量が大きい)
  • sdc1:既存アレイのディスク2(もともと容量がsdb1より小さく、アレイの容量を引きずっていたほう)

まずは、現状の状態を確認

# cat /proc/mdstat
Personalities : [raid1] 
md0 : active raid1 sdc1[2] sdb1[3]
      3909568 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/md0        3.7G  2.1G  1.4G  60% /

fdiskでパーティションを作成し、タイプを0xfd(Linux raid autodetect)へ変更

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-31285247, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-31285247, default 31285247): 

Created a new partition 1 of type 'Linux' and of size 14.9 GiB.

Command (m for help): p
Disk /dev/sda: 14.9 GiB, 16018046976 bytes, 31285248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 31281152 31279105 14.9G 83 Linux


Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'.

Command (m for help): p
Disk /dev/sda: 14.9 GiB, 16018046976 bytes, 31285248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 31281152 31279105 14.9G fd Linux raid autodetect


Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

mdadmでRAID1アレイに新規追加

# mdadm --add /dev/md0 /dev/sda1
mdadm: added /dev/sda1
root@nanga:~# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda1[4](S) sdc1[2] sdb1[3]
      3909568 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

既存のRAID1アレイから片方のディスクを切り離し、アレイから削除

# mdadm --defail /dev/md0 /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md0
# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda1[4] sdc1[2](F) sdb1[3]
      3909568 blocks super 1.2 [2/1] [_U]
      [>....................]  recovery =  1.6% (65600/3909568) finish=6.8min speed=9371K/sec
      
unused devices: <none>
# mdadm --remove /dev/md0 /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md0
# /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda1[4] sdb1[3]
      3909568 blocks super 1.2 [2/1] [_U]
      [=>...................]  recovery =  5.5% (215168/3909568) finish=10.0min speed=6147K/sec
      
unused devices: <none>

ミラーリングが終了するまで待機する。

# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda1[4] sdb1[3]
      3909568 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

ファイルシステムを拡張するまえに、RAIDディスクを拡張する

# mdadm --grow /dev/md0 --size=max
mdadm: component size of /dev/md0 has been set to 7972224K
unfreeze
# cat /proc/mdstat
Personalities : [raid1] 
md0 : active raid1 sda1[4] sdb1[3]
      7972224 blocks super 1.2 [2/2] [UU]
      [=========>...........]  resync = 49.2% (3922624/7972224) finish=30.9min speed=2176K/sec
      
unused devices: <none>

resyncが終わるまで待機する

# cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sda1[4] sdb1[3]
      7972224 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

最後にファイルシステムを拡張する。

# resize2fs /dev/md0 
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/md0 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/md0 is now 1993056 (4k) blocks long.

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/md0        7.5G  2.1G  5.1G  29% /

最後に、mdadm.confを反映

# mdadm --detail --scan >> /etc/mdadm/mdadm.conf

当方環境では、initramfsの再構築まで実施して完了。