Skip to content

Instantly share code, notes, and snippets.

@crazyquark
Forked from ryross/odroid_to_ssd.sh
Last active May 10, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyquark/ae40132d0e69915aeee1b4cbdc8fe0b3 to your computer and use it in GitHub Desktop.
Save crazyquark/ae40132d0e69915aeee1b4cbdc8fe0b3 to your computer and use it in GitHub Desktop.
Move Odroid filesystem to SSD
## Instructions to switch odroid over to 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.
lsblk
#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 /dev/$new_partition"
export new_drive="/dev/$new_drive"
export new_partition="/dev/$new_partition"
umount $mountpoint
# 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. You might need to approve this manually
sudo mkfs -t ext4 -L rootfs $new_partition
# make a place for the ssd to mount to, and mount it
sudo mkdir /mnt/ssd
sudo mount $new_partition /mnt/ssd
# 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/ssd
# get current partition
export current_uuid=`blkid -o value /dev/mmcblk0p2 | sed -n '2p'`
# get the new UUID
export new_uuid=`blkid -o value $new_partition | sed -n '2p'`
# backup the boot.ini just in case
sudo cp /media/boot/boot.ini /media/boot/boot.ini.bak
# update boot partition so that the kernel knows to boot off of the new HD
sudo sed -i "s/${current_uuid}/${new_uuid}/" /media/boot/boot.ini
# update mount the new partition as the root partition
sudo sed -i "s/${current_uuid}/${new_uuid}/" /mnt/ssd/etc/fstab
# We're done. Check /mnt/ssd/ includes all the files you would expect it to and reboot
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment