Skip to content

Instantly share code, notes, and snippets.

@ryross ryross/
Last active Jul 22, 2016

What would you like to do?
## Instructions to clone odroid external ssd over to a new external ssd
# You shouldn’t see any errors when running this process, if you do. Stop immediately and ask me.
# run lsblk to see all the hard drives. You should see a line starting with mmcblk0 and then 2 more underneath it with
# mmcblk0p1 and mmcblk0p2. That’s the sd card disk and the sd card partitions. You’ll also see a line starting with
# sda (and/or sdb if there are two usb drives). We want to use the sd* one.
#pull out some of the values from lsblk so we can automate the rest of the script
read new_partition new_drive mountpoint <<< `lsblk -e 179 -l -o NAME,PKNAME,FSTYPE,MOUNTPOINT |grep 'vfat\s*/media/odroid' | awk {'print $1" "$2" "$4'}`
# after you run this command, verify that it matches the mount point and partition of the usb drive you identified
# in the first step. if you’re not 100% sure here, ask me.
echo "about to unmount $mountpoint on $new_partition. Disk: $new_drive"
export new_drive="/dev/$new_drive"
export new_partition="/dev/$new_partition"
umount $mountpoint
# if the echo line above outputs "about to unmount on . Disk:" then we couldn't find which disk to use automatically. If you're cloning an SSD to an SSD, the first SSD is most likely /dev/sda and second one is /dev/sdb. You probably want to use the drive /dev/sdb and partition /dev/sdb1.
# to do that uncomment these lines and run them. You'll want to find the partition that's mounted and unmount it. You unmount by running umount (not unmount) and then pass in the mountpoint. If you have trouble finding the mount point, let me know.
# export new_drive="/dev/sdb”
# export new_partition="/dev/sdb1”
# repartition the file ssd
sudo parted --script $new_drive mklabel gpt
sudo parted --align optimal $new_drive mkpart primary ext4 0% 100%
# after running the last command, you may see:
# “Information: You may need to update /etc/fstab.”
# If that’s all you see then that’s fine. If there’s any other output from that command, let me know.
# switch the file system to ext4.
sudo mkfs -F -t ext4 -L rootfs $new_partition
# make a place for the ssd to mount to, and mount it
sudo mkdir -p /mnt/clone
sudo mount $new_partition /mnt/clone
# transfer all the files over from the sd card to the new ssd
sudo rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt/clone
export root_dev=`mount |grep "on / " | awk {'print $1'}`
export current_uuid=`blkid -o value $root_dev | sed -n '2p'`
export new_uuid=`blkid -o value $new_partition | sed -n '2p'`
# update mount the new partition as the root partition
sudo sed -i "s/${current_uuid}/${new_uuid}/" /mnt/clone/etc/fstab
echo "Now clone the SD Card and edit boot.ini to use UUID $new_uuid"
sudo umount /mnt/clone/
# I think that should be it! Now you can safely unplug the clone ssd
# now clone the sd card. Once you do, we'll need to update boot.ini. Hit me up and I'll help you with that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.