1

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)

  • What type of backup? You can run sudo dd if=/dev/mmcblk0 of=/some/file/name/here if the /some directory is on a second partition that'll work. But I don't know how useful that willl be as when the SDCard fails the back will also fail. – Dougie Jul 15 at 10:06
1

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.

| improve this answer | |
  • Thanks, this sounds great, I will give it a try, probably next week, and report back. I don't necessarily need to dynamically create backups, the backups will be a static version (e.g. release version1), then we might later install some updates remotely (e.g. version 2) but if there are issues, the end user (or us) can always restore version 1 – Bassline Soup Jul 22 at 11:05
0

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
| improve this answer | |
  • So, could I create three partitions: boot, OS1 and OS2. Switch from OS1 to OS2, overwrite OS1 with a new image (from an external network source), edit the contents of boot and then reboot back into the updated OS1? – Bassline Soup Jul 15 at 13:38
  • @BasslineSoup Yes, it it possible, but it's another question. – Ingo Jul 21 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.