Is it possible to create and restore from a full, block-level backup of the Fairphone 5?

As soon as I receive the phone I ordered, one of the first things I’d like to do with it is make a full, block-level backup that I can restore from in the future. On a Linux machine, I would usually do this by booting into it using a live USB and using the dd tool to create bit-perfect copies of the block devices of the machine, which I can then restore from by again using dd. I don’t know of a way to boot into an external OS on Android phones to conduct the backup process, hence this question.

I searched around for information related to this and came across this Stack Exchange thread. Unfortunately, it (as well as other similar threads) seems to indicate that attempting to use dd may not actually work to create full backups, since some phones store data in some kind of hardware-backed keystore that prevent backups of it from being made.

Does this also apply to the Fairphone 5, and if so, what can I do instead to create (and restore from) a full backup? If this isn’t possible to do with dd, would I instead be able to use tools like NeoApplications/Neo-Backup and mrrfv/open-android-backup to create full backups? Ideally I’d like to create the backups without having to install anything on the phone, as I’d like to backup its state when it’s completely new.

1 Like

In which way would your backup differ from a factory reset?

The Qualcomm chip used in the FP4 lists several relevant hardware-based security features:

On-Device: Qualcomm® Mobile Security, Key Provisioning Security, Qualcomm® Processor Security, Qualcomm® Content Protection, Qualcomm® Trusted Execution Environment, Camera Security Secure Camera, Crypto Engine, Malware Protection, Secure Boot, Secure Token

So yes, basically any modern phone has some kind of TPM that is specifically designed to be able to perform cryptographic operations in a secure manner without ever leaking the key. So assuming the Software uses it properly and there are no design flaws in the hardware, it won’t be able to retrieve the encryption key with everyday methods.

A different tool won’t help you if you aren’t able to access the key used to encrypt your device. Let’s just assume you did a bit-by-bit backup of all the data. Now at some point along the way you decide to do a factory reset, which also regenerates and overwrites the encryption key. Once this happens the stuff you backed up is just some garbled, encrypted mess. Even if you write it back bit- by bit the device won’t be able to make use of it, since the encryption key no longer exists.

Just stick to doing backups the ‘regular’ way and resetting the system using a factory reset (of a full flash using a factory image if necessary). You’d need to compromise your own devices security significantly and in ways that are not permitted by Google’s current security policies to make your backup strategy work as far as I can tell.

(Btw, if you encrypt your linux-laptop using a secure TPM you’d have the same problem if the TPM were to be reset somehow.)

Well, if your partitions are damaged or you f’ed up some deep system sh’t (while experimenting with rooted custom ROMs for example), you may need to perform a full flash using a factory image. But that’s usually not necessary. If a backup as described above were to work, it’d come closer to that than a factory reset I guess. Also you would be able to skip some basic setup steps using the backup-method I guess.

Edit: I just noticed you are talking about the FP5, but the argument should still stand.

1 Like

So you’re saying it’s possible to flash a factory image onto the phone? If so, where can I obtain copies of these images? And also, how does flashing the factory images circumvent the problem you mentioned regarding the secure keystore? How are they different to the images that’d be created by dd if it was used?

On PCs, these sorts of backups can restore the system in cases of OS corruption, in a way that factory resets might not fix. As @AndreasChris mentioned, on a phone, these could happen when you do things like flash custom ROMs onto it. I’ve had this happen to me on previous phones before, so I’d like to be more prudent this time around and make full backups if I can before I go modify/break the phone.

@nicoty
backing Linux system on LUKS encryption have master key in same LUKS partition and you unlock it with key in you head, but on phone is decription key in phone secure chip and regenerated when doing Factory reset or full image reflash…

Factory image reflash is different to using DD backup, as is more like reguler Linux install with cleaning and repartioning disk, and starting with clean home :wink:

anyway FP5 Factory Image is here:
https://code.fairphone.com/projects/fairphone-5/factory-package.html

7 Likes

For the Fairphone 5? I think it has not been released yet. See post above.

The Fairphone 4one can be found here:
https://support.fairphone.com/hc/en-us/articles/4405858261777
I expect the FP5 will receive a simila page soon.

Well… it doesn’t. I simplified a bit.
First-off note that new versions of Android no longer permit full disk encryption, but uses file-based encryption. All of the stuff in the /data partition is encrypted on a per-file basis. Not all of the stuff in the other partitions will be encrypted.
Once you flash a new system and start your phone a new encryption key is generated and everything that needs to be encrypted is generated after that and stored using that new key. If you delete everything thats in the /data partition and generate a new encryption key that’s more or less equivalent to a factory reset, restoring your device to the state after the last update.
If you flash a factory image, you will not just override the data partition but much more than that (which includes a clean /data partition, but also the /system partition etc). But creating a backup of that state really doesn’t make any sense, since its basically equivalent to the factory image. And everything that’s created after the first start of the phone (such as manually installed apps and config stuff) cannot be backed up into such an image, since it will live in the encrypted /data partition and will be useless once a new key is generated.
Also if you just used a perfect image created after the first start of the phone chances are it will not just behave as it would after a factory reset if flashed, as the system will try to use the stuff that’s been generated and put in the /data partition during setup, which is encrypted with the old key and hence look like ‘corrupted’ data to the system.

For that usecase the factory image should do just fine. And if it doesn’t a backup won’t help you either. (The cases where it doesn’t are basically those where you bricked the bootloader - which is possible on the FP4 if you aren’t careful with re-locking the bootloader, which is very dangerous in general.)

Also I’m winging it a bit on the specifics a bit. If I’m not mistaken @hirnsushi is rather knowledgable in that topic (judging by his other comments in this forum) as well. So maybe they can answer more of your questions in more detail.

3 Likes

What you are wishing to do seems to be what TWRP does: complete system backup that you can restore nearly identically after a full wipe. Unfortunately this requires:

  • to unlock the bootloader of the phone, with all consequences it implies. This is anyway necessary for any backup solution for apps and the system that isn’t directly baked in the system, such as Google backup or Seedvault.
  • TWRP to be able to decrypt data, which is quite difficult for devs to achieve and isn’t the case on most devices now (but it might be achieved for FP5, I have hope). Nevertheless, I wouldn’t advise you to use TWRP for system backups except if you know well how it works and which partitions it backs up. With my FP2 experience, I had quite a few cases where it was very useful, but also others where it failed.
  • to still have access to recovery, which isn’t always the case when tinkering fails. And then you’d just be able to flash the stock OS from fastboot and that would be the way to go.

These apps require root (best is from Magisk), but this again has security implications and may brick your device to a state to which you’d had wished to restore a full backup.
Then, they only back up your apps’ userdata, nothing else, you won’t have a full system backup.

This seems impossible to me. The best solution if you tinker with your device seems to me to always check if what you are going to do won’t stop you from being able to flash the stock OS from fastboot. Such cases about relocking the bootloader on FP4 without checking you were able to unlock it after led to this (a quick search on the forum should help you find it).

What you seem to wish is that EDL works on FP5. Unfortunately, this requires factory files to be leaked, and isn’t even the case for FP4.

TL;DR: I think you can’t in any way do a full backup of the OS on the device. If some tinkering fails, you should just hope you are still able to flash the stock image from fastboot.

Edit: I see @AndreasChris was a little faster for some of the comments, sorry for repeating :wink:

3 Likes

Amazing, thanks for the explanations everybody! I think all my concerns have been addressed for now; it seems my best option to achieve what I’m after is to essentially grab a copy of the factory image, which @k3dAR has kindly shared (my gratitude also goes out to the Fairphone team for making the factory image available, I’ve not seen many other companies do that). I’ll definitely keep that handy in case I run into issues in the future, so I can flash it onto the phone. Fingers crossed I wouldn’t need to though! :smile:

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.