How to convert a single disk to RAID-1 on raspberrypi

  • Purpose
    • Official recommendation is, not to use any RAID and rather setup one hard disk per one node.
      They said, data is already redundant in the network and the space that you waste in a RAID could be used to earn extra money.
    • But, I think if I lose a node, it’s too long to recover for past data capacity.
      Thus it’s clear that I’ll earn smaller income.
    • So, I tried to convert exist single disk to RAID-1 device without dataloss on RaspberryPi and succeeded that.
      If you want to know how to migrate storj disk, please check the below.



  • My Environment
    • Raspberry Pi 4 & 32bit OS
    • WD Elements 12TB * 2ea
    • SD Card 8GB (Boot partition)
  • How-to
    • Prepare new disk
    • Attache new disk and create raid-1 volume without exist disk.

fdisk /dev/sdb
n p 1 enter enter blah blah
mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1
mkfs.ext4 /dev/md0
mkdir /mnt/raid
mount /dev/md0 /mnt/raid

  • Copy data from exist disk to raid volume

screen -R genie
rsync -aAXHv --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/*","/lost+found"} / /mnt/raid/
ctrl a+c

  • Added raid uuid information.

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

  • /etc/initramfs-tools/modules

raid1
md_mod
ext4

  • Create initramfs

mkinitramfs -o /boot/initramfs-raid.gz

  • /boot/config.txt

kernel=kernel7l.img # If you use 64bit os, then kernel8.img or before rpi4, kernel7.img
initramfs initramfs-raid.gz

  • /etc/fstab

/dev/md0 / ext4 defaults,noatime 0 1

  • /boot/cmdline.txt

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root= /dev/md0 rootdelay=15 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait ipv6.disable=1 cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1

  • Stop storagenode

docker stop storagenode && docker rm storagenode

  • Copy once again

screen -r genie
rsync -aAXHv --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/*","/lost+found"} / /mnt/raid/
ctrl a+c

  • Reboot
  • Check root partition is /dev/md0
  • Copy once again((I don’t know why this job is necessary. Copied all data after stop storagenode. but invalid data occurred about *.db)

mount /dev/sda1 /mnt
copy /mnt/[STORAGENODE_DIRECTORY]/storage/*.db [STORAGENODE_DIRECTORY]/storage/

  • Start storagenode

docker start storagenode [YOUR_OPTION] docker logs -f storagenode

  • Update partion information

sfdisk -d /dev/sdb | sfdisk /dev/sda

  • Added destroyed disk to raid device

mdadm /dev/md0 -a /dev/sda1
watch -n 1 cat /proc/mdstat

Because the last rsync must be with --delete to delete missing files. In this case - journals of databases, which are present only if you stop your node ungracefully (or copied on fly like here), but only for storagenode data of course.

2 Likes

Okay, I see. Thank you for your kindness.