bkup_rpimage icon indicating copy to clipboard operation
bkup_rpimage copied to clipboard

Backup a USB HD partition

Open AlbertoLopSie opened this issue 5 years ago • 2 comments

Hi,

I've just set up mi RPi to boot from SD (mmcblk0) and innmediatelly mount the rootfs from a USB HD as described in HOWTO: Move the filesystem to a USB stick/Drive. I also added a couple of additional partitions to mount /var/log, /data and a /backup mountpoints

I want to schedule daily backups of /boot (on SD) and / (on USB HD) and store the images on /backup in order to be able to burn a new SD and boot from it in case of HD failure.

Your script assumes the source partitions are on /dev/mmcblk0 and use that device to get partition sizes and types to create the target image. However, it then rsync's from / and /boot, that in my system are in the USB HD /dev/sdc.

How do I tell the script to take those params from the proper places? (/dev/mmcblk0 and /dev/sdc2)

I'm also planning as the next step to boot directly from the USB /boot partition (/dev/sdc1 in my case) and remove the SD card from the RPi. I guess that in that case, the bkup_image script will have trouble to get the image geometry from an inexistent SD card.

Any hint? Thanks!

AlbertoLopSie avatar Apr 07 '19 00:04 AlbertoLopSie

This script is not intended to make backups from any other source as the sdcard. Your usecase /boot on another device as / is a little special. In case this would work you will have a single file containing two filesystems from different devices.

But feel free to rip the relevant functions from this script. You have to

  • create a loopback device so /boot and / from the source will fit
  • create a dos partition and a filesystem for /boot (size as /boot on source)
  • create a ext4 partition and filesystem for / (big enough to hold the contents of / on source)
  • rsync /boot to the corresponding filesystem in the loopback device
  • rsync / to the corresponding filesystem in the loopback device
  • enshure the PARTUUID of / in the loopback device matches the PARTUUID in /boot/cmdline.txt

The resulting file can be transferred with dd to a SD card and should be bootable. BTW: The geometry of the SD card does'nt matter in this usecase.

dolorosus avatar Apr 14 '19 18:04 dolorosus

I have another proposition: if you cannot or don't want to use full USB boot (no SD card at all) you can try the bootcode.bin method, where you can keep the SD only to hold that single file, and then it will search for the first available USB drive for a boot partition containing a cmdline.txt: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/

That way you have /boot and / on same drive and can use this tool with no hassle, just like I do.

ephestione avatar Jul 20 '19 11:07 ephestione