#!/bin/bash #---------------------------------------------------- # armbian_hotclone.sh # # Copies the sdcard your Armbian system is running from # to a new sdcard in an USB-attached card reader. # # The new sdcard can be of any size as long as it can hold # the data content of the original card. # # The cloned card should be tested after creation to ensure # it can be used for desaster recovery. # # c) Rodolfo 2016-06-19 enjoy ! #----------------------------------------------------- # ARMBIAN_ORIG=/dev/mmcblk0 ARMBIAN_CLONE="/dev/"$(lsblk -l | grep sd | grep disk | awk '{printf $1}') # Clone partial image of original SDcard ( bootstuff + partition table + start of first partition ) # we just copy 4M to account for strange partition alignment dd if=$ARMBIAN_ORIG of=$ARMBIAN_CLONE bs=1M count=4 # Delete invalid partition of target SDCARD and create/format new ext4-partition umount $ARMBIAN_CLONE"1" echo -e "p\nd\nn\n\n\n\n\np\nw\nq\n" | fdisk $ARMBIAN_CLONE echo -e "y\n" | mkfs.ext4 $ARMBIAN_CLONE"1" # Target mount mkdir /mnt/armbian_clone mount $ARMBIAN_CLONE"1" /mnt/armbian_clone rm -r /mnt/armbian_clone/* # cleanup lost+found # System copy to SDcard time rsync -avSz --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/media/* \ --exclude=/mnt/* --exclude=/run/* --exclude=/tmp/* / /mnt/armbian_clone sync umount $ARMBIAN_CLONE"1" eject $ARMBIAN_CLONE