Skip to content

Instantly share code, notes, and snippets.

@ryross
Last active July 2, 2023 22:10
Show Gist options
  • Save ryross/8f7665e17953535c9006eb599b85145e to your computer and use it in GitHub Desktop.
Save ryross/8f7665e17953535c9006eb599b85145e 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
@ryross
Copy link
Author

ryross commented Aug 29, 2022

I can’t remember. I worked on this a number of years ago. Sorry!

@pat222tyry
Copy link

pat222tyry commented Feb 9, 2023

Hi Ryross, thanks a lot. The script is not working on my Odroid XU4, but, as written by Jammon, I used it to undertstand concepts.
And to solve an issue I had: randomly after some days my odroid turns off if the rootfs moved to SSD.
My "migration to SSD" method is similar to yours but with a difference: in yours what makes the difference is the usage of GPT instead of MBR.
My SSD size is < 2TB so also MBR can be used, but probably not so stable as GPT.
After I passed to GPT my Odroid is stable and no more turns off. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment