Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
The boot partition cannot be RAIDed on an rPi.
#!/bin/bash -e
#
# The boot partition cannot be RAIDed on an rPi. We can periodically sync it, and if the primary card
# fails, we are then able to just swap the the cards around.
#
FIRST_SD_CARD=/dev/mmcblk0
FIRST_BOOT_PARTITION=${FIRST_SD_CARD}p1
#FIRST_ROOT_PARTITION=${FIRST_SD_CARD}p2
#FIRST_APP_PARTITION=${FIRST_SD_CARD}p3
SECOND_SD_CARD=/dev/sda
SECOND_BOOT_PARTITION=${SECOND_SD_CARD}1
#SECOND_ROOT_PARTITION=${SECOND_SD_CARD}2
#SECOND_APP_PARTITION=${SECOND_SD_CARD}3
echo "Are we superuser?"
[[ $EUID -eq 0 ]]
echo "OK"
# assume FIRST_BOOT_PARTITION is already mounted
echo "Is partition $SECOND_BOOT_PARTITION not mounted?"
if df | grep --quiet "$SECOND_BOOT_PARTITION"
then
umount "$SECOND_BOOT_PARTITION"
fi
echo "OK"
echo "Copy files over."
BOOT_MOUNT=/tmp/boot
mkdir --parents "$BOOT_MOUNT"
mount "$SECOND_BOOT_PARTITION" "$BOOT_MOUNT"
rsync --archive --exclude="/lost+found" /boot/ "$BOOT_MOUNT"
umount "$BOOT_MOUNT"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment