Skip to content

Instantly share code, notes, and snippets.

@velenux
Created January 11, 2011 13:56
Show Gist options
  • Save velenux/774430 to your computer and use it in GitHub Desktop.
Save velenux/774430 to your computer and use it in GitHub Desktop.
Build and verify a raid1 array from a single disk
# format disk1, partition type fd
cfdisk /dev/vda
# copy partition table from disk1 to disk2
sfdisk -d /dev/vda | sfdisk /dev/vdb
# check partitions
fdisk -l 2>/dev/null | grep -B1 '^\/dev'
# build array with only disk1
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/vda1 missing
# check array
cat /proc/mdstat
# format array
mkfs.ext4 /dev/md0
# create array mount point
mkdir /mnt/raid
# mount array
mount /dev/md0 /mnt/raid
# save data to array
date > /mnt/raid/current-date
# check data
cat /mnt/raid/current-date
# save array conf
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
# umount array
umount /dev/md0
# stop array
mdadm -S /dev/md0
# check if array is stopped
cat /proc/mdstat
# create single disk mount point
mkdir /mnt/single
# mount single disk
mount /dev/vda1 /mnt/single -t ext4
# check if data is there
cat /mnt/single/current-date
# umount single disk
umount /mnt/single
# restart array
mdadm --assemble /dev/md0
# check if array is up
cat /proc/mdstat
# add disk2 to array
mdadm --add /dev/md0 /dev/vdb1
# check if array is rebuilding itself
watch cat /proc/mdstat
# mount array
mount /dev/md0 /mnt/raid
# check if data is there
cat /mnt/raid/current-date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment