Skip to content

Instantly share code, notes, and snippets.

@LizhangX
Last active May 11, 2020 05:19
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 LizhangX/7cd29e78af8ffe89ce5881aa3f5a3ebd to your computer and use it in GitHub Desktop.
Save LizhangX/7cd29e78af8ffe89ce5881aa3f5a3ebd to your computer and use it in GitHub Desktop.
My steps to worry-free/robust backup raspi 4 micro SD card with OMV5. (Using .img)

Description:

These are my steps to completely backup raspi 4 micro SD card without worrying about what is needed or what is not. In my opinion, it is more robust and Linux noob friendly. It will backup everything in the sd card for easy future restore with balenaEtcher to a new sd card. I choose this sd card -> Lexar high performance 633x microSDHC UHS-1 V10 A1 U1 from EC's video https://youtu.be/YUResed38uo for it's high iops which is great for SBCs.

Prerequisites:

Linux/Mac(either one), Windows machine, external hard drive/usb, new micro sd card.

Backup:

  1. Make sure all processes running are stateless, or it would need to be stopped before backup.

    • Most of my processes are running in docker, where the app configs are mounted in an external hard drive which is also my drive for smb.
    • Reason is that once everything are restored from backup, all the apps can start within no time.
  2. Shutdown Pi and pull out the micro sd card.

    • I tried https://github.com/lzkelley/bkup_rpimage to backup while pi is running. After restore, all docker containers are coming back up and running. But only omv5 is not working. Didn't spend enough time to figure out why.
    • Although I want to leave the sd card in my Pi while doing backup. Right now it doesn't seem to work without looking at the above script to check which part/mount is not backed up for omv5.
    • I did check out dd and using fsarchiver provided by omv-extra. But it seemed to just backup the root mount. I would like to backup the whole sd card for my pi. Will do more research later regarding dd, fsarchiver and rsync.
    • Tried clonezilla but it doesn't seem to support raspi.
  3. Plug the micro SD card in a windows machine and use Win32DiskImager to make an image out of the micro sd card

    • I used an external ssd to store the image for step 4 & 5 since a linux/mac machine is needed.
    • Download from https://sourceforge.net/projects/win32diskimager/
    • Choose a location to store the image and the name of image under Image File section.
    • Choose the correct device drive to your micro sd card.
    • Click Read to create the image. This will take sometime.
    • Click Verify Only to make sure no corrupted data introduced during the image creation. This will also take sometime.
  4. Use PiShrink to shrink the image to a much smaller size (Highly recommended)

    • Easier to transfer and store with smaller size.
    • Different brand sd cards might have different sizes even-though they stated capacity, it will cause problem if the image is slightly larger than the new sd card.
  5. Links to use PiShrink

Restore:

  1. Use balenaEtcher to write the image to the new sd card.

  2. Plug in the new sd card to the Pi. Power on and let it start.

    • ssh to the pi
    • run sudo raspi-config
    • go to option 7-Advanced Options
    • choose option A1 to expand the file system to make use of all the available space of the sd card, otherwise the mount would be the size of the image.

Enjoy :)

P.S. It may take sometime to backup and restore, also it will have some downtime while creating the backup image. But it gives me peace of mind that I have everything backed up and all I need is a cheap 6 dollar micro sd card if things go wrong. I don't need to spend time to figure out what went wrong and what to restore.

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