TransWikia.com

Backup Pi onto same SD card, different partition

Raspberry Pi Asked by Bassline Soup on November 11, 2021

I am wondering if it is possible to:

  • Partition an SD card into two (or three including boot partition)
  • Install PiOS on one partition that it boots on
  • Boot the Pi and make various software adjustments on that main partition
  • Backup the main partition to the other partition on the SAME SD card
  • Make further changes to The main partition that results in undesired results
  • Trigger some process that re-flashes the main partition from the backup partition

To be clear I do not want to make just a normal backup, I want it to be on the same SD card. Think of it as a factory reset.

The answer to this other question is NOT what I want to do (although the question itself seems the same/similar)

2 Answers

As far as I understand you want to have a disaster recovery. It is possible to do it with the steps you described and with some scripts. The main problem is that you cannot simply clone the running operating system. The copy takes some time and within this time the OS will change several system files that may result in an inconsistent copy. It is possible that the copy does not work. You have to take additional effort to avoid changes during copy. You can use rsync as described at Can a Raspberry Pi be used to create a backup of itself?.

But I prefer to use the Logical Volume Manager (LVM). With it you can just take snapshots at any time with a one liner sudo lvcreate --snapshot --name current_setup --size 4g rpi_vg/root. Now you can reconfigure your running system until it is broken and does not boot again. You can boot into the snapshot and repair the main logical volume (lv) by mounting it. Or you can just revert the main lv to the current_setup with a one liner sudo lvconvert --merge rpi-vg/current_backup. I always use LVM for my development. There are many other nice things you can do with it, e.g. easy taking backups. Have a look at Easy backups and snapshots of a running system with LVM.

Answered by Ingo on November 11, 2021

You cannot install Raspberry Pi OS into a partition - it needs 2 partitions.

You can copy the root partition into a separate partition (although this requires you to modify the partition layout - which can't be done on a live system) and easily switch between the two (provided they share a kernel).

I have done this, but doubt it makes much sense.

NOTE if you want to do this you need to ensure that the root partition in /etc/fstab is changed (probably -03) and select the partition to boot in cmdline.txt

PARTUUID=b5d2de0f-02  /               ext4    defaults,noatime  0       1

Answered by Milliways on November 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP