MOve from md->btrfs to btrfs-raid1
#!/bin/bash -e
# stop at any error
DEV=( $(ls /sys/block/md1/slaves/) )
[ $? -ne 0 ] && echo "/dev/md1 not found ot other error" && exit 1
if [ ${#DEV[@]} -ne 2 ] ; then
echo "something wrong with the raid, or raid not found"
echo "manual intervention required"
exit 1
fi
# this script is only for cpu nodes where on manual intervention has been done on FS level
for i in ${DEV[@]} ; do
if ! parted -m /dev/${i/4} print | grep -E '^5:' > /dev/null 2>&1 ; then
if [ "$( parted -m /dev/${i/4} print | awk -F: '/^4:/{print $3}')" = "32.2GB" ] ; then
echo parted /dev/${i/4} -s set 4 raid off name 4 sys mkpart sys2 btrfs 32.2G 100%
else
echo "/dev/${i/4} has a different partitioning scheme as anticipated, bailing"
exit 1
fi
else
echo "# /dev/${i/4} has a 5th partition, make sure you verify"
fi
done
# break raid
echo mdadm /dev/md1 --fail /dev/${DEV[1]}
echo mdadm /dev/md1 --remove /dev/${DEV[1]}
echo mdadm --zero-superblock /dev/${DEV[1]}
# Add partition
echo btrfs device add /dev/${DEV[1]} / -f
# remove MD dev (all data form md1 is copied to sdx4
echo btrfs device remove /dev/md1 /
# when finished , delete md device
# sometimes this goes to fast, because it's an ioctl
# les's wait a little
echo sleep 2
# ok
echo mdadm --stop /dev/md1
echo mdadm --zero-superblock /dev/${DEV[0]}
# add underlying partition back in btrfs
echo btrfs device add /dev/${DEV[0]} / -f
# now convert to raid1
echo btrfs balance start -mconvert=raid1 -dconvert=raid1 /
# That's all Folks