Wednesday, March 11, 2015

Create a RAID using one raspberry pi then transferring it to another

Build the array on a raspberry pi 1 that is already running a raid (level 1) array
  • connect two 2-TB drives via powered USB hub
    • They appear as /dev/sdd and /dev/sde
  • use fdisk to delete the pre-built partitions, create new partitions using defaults that are for linux and fill each disk
  • created array:
mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sdd1 /dev/sde1

mdadm: /dev/sdd1 appears to be part of a raid array:
    level=raid0 devices=0 ctime=Thu Jan  1 00:00:00 1970
mdadm: partition table exists on /dev/sdd1 but will be lost or
       meaningless after creating array
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
mdadm: /dev/sde1 appears to be part of a raid array:
    level=raid0 devices=0 ctime=Thu Jan  1 00:00:00 1970
mdadm: partition table exists on /dev/sde1 but will be lost or
       meaningless after creating array
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.
    • ls /dev/ shows that /dev/md2 is now present
  • check the array:
cat /proc/mdstat

Personalities : [raid1]
md2 : active raid1 sde1[1] sdd1[0]
      1953349440 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.2% (4189568/1953349440) finish=2115.7min speed=15354K/sec
    • above was reported at 2 AM Monday Mar 9 2015, subsequent calls to "cat /proc/mdstat" reported longer finish times / slower speeds
    • round finish time up to 2200 minutes, then expected finish is 2:40 PM Tuesday March 10th
    • wait for it... did not check until 10 PM Tuesday March 10th, but it was finished
  • disconnect the USB hub from the pi
    • just to be paranoid, powered down the pi first
Connect to a raspberry pi 2:
  • the pi2 did not recognize the hub & drives until I pulled out (very slightly) the USB from port on the pi2 - see this other post for details
    • used the command dmesg to determine that the hub and drives were connected to the pi2
  • find / discover the RAID array using mdadm --assemble --scan:
sudo mdadm --assemble --scan

mdadm: /dev/md/raspberrypi:2 has been started with 2 drives.
cat /proc/mdstat

Personalities : [raid1]
md127 : active raid1 sda1[0] sdb1[1]
      1953349440 blocks super 1.2 [2/2] [UU]
   
unused devices: <none>
  • partition the array with:   
sudo fdisk /dev/md127
    • started with warning message:  "Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)"
    • p to print table indicated no existing partitions
    • n to created new partition, used defaults which cause the partition to use all available space
    • w to write and exit
    • afterwards, new entry in /dev:  /dev/md127p1
  • format the partition with
sudo mkfs.ext4 /dev/md127p1
    • ran relatively quickly (< 5 minutes)
Then I mounted and tested the partition by writing "hello world" to a test file - it worked!  Confident that I could transfer the array between systems, I moved it back to the first one and started copying over the contents of the original 1 TB array to the new 2 TB array - transferring 530 GB.

No comments:

Post a Comment