[General Questions and Answers] LongWeekend32:
I’d be much obliged for your guidance, gentle people.

## The issue

My device (a TWRP’d, Magisk’d Samsung Galaxy A6) boots into Android 10, but can be relied on to reboot every 3 minutes thereafter. Call it a long bootloop, if you like.

## The error message

I’m not sure if this is relevant, but booting into TWRP and running a factory reset results in the following message:

Factory reset complete​

Failed​

Failed to mount ’/data’ (invalid argument)​

Unable to recreate /data/media folder.​

Updating partition details…​

Failed to mount ’/data’ (invalid argument)​

…done​

Unable to mount storage​

Failed to mount ’/data’ (invalid argument)​

Full SELinux support is present.​

Unable to mount /data/media/TWRP/.twrps​

MTP Enabled​

Failed to mount ’/data’ (invalid argument)​

Formatting Cache using make_ext4fs…​

Updating partition details…​

Failed to mount ’/data’ (invalid argument)​

…done​

Unable to mount storage​

## How did I get here?

Here’s a short version of the story. I:

(1) Downloaded stock firmware with Samloader.

(2) Flashed the firmware (with heimdall-frontend, leaving the repartition option unselected), but not all of it: only the files in

AP (substituting a TWRP recovery.img for the stock one),

CP, and

HOME_CSC,

i.e. omitting the files in BL.

(3) Used TWRP to Wipe > Format data.

(4) Still using TWRP, installed zips for RMM_bypass and no-verity-opt-encrypt, and rebooted.

## And what did I do before that? And why?

Until recently, I’d been running the factory-installed OS, Android 8. I figured it was time for a firmware update, but the modifications I’d made (as mentioned above, Magisk and, presumably more to the point, TWRP) meant that I wasn’t getting OTA updates.

So I started following some instructions [1] for getting an OTA update installed on a Magisk’d device.

## Uninstalling Magisk

The first step was to open Magisk Manager and tap Uninstall > Restore Images. Without really understanding what I was doing, or if there were any risks involved, I did that.

## Firmware update: first try

The next step was to install the OTA update: “Head over to Settings > System > System Update > Download and install the latest available OTA.” Well, that didn’t work. Said the popup: “The operating system on your device has been modified in an unauthorised way, etc., etc.“ Ah yes, that’s why I haven’t been getting updates in the first place.

So what to do now? As already mentioned, I used Samloader to download the latest stock firmware for my model and region. I decrypted and unzipped the .zip.enc4 file, to find tar.md5 files with the prefixes BL, AP, CP, HOME_CSC and CSC.

Now, topjohnwu’s instructions for installing Magisk on Samsung devices include the following warnings:

And:

So I attempted to follow his instructions, adb-pushing the AP_...tar.md5 file to the device and then asking Magisk Manager to patch it. But Magisk Manager failed to patch the file. I got an error message saying "device not connected”, or something like that. (This didn’t make any sense to me, but at the time I guessed that it was perhaps a result of having already tapped on Uninstall > Restore Images.)

## Short bootloop and factory reset

I carried on regardless. My next step was to reboot the device. I suppose I wanted to know what the effect of Uninstall > Restore Images was going to be; voilà, it was, perhaps predictably, a (short) bootloop (Samsung/Knox/Android splash screen only).

But I could still boot into recovery, so firstly I tried to restore the old backup I’d made with TWRP when I first installed it. The attempt was not successful – the system partition was mounted read-only, it said, a situation which I did not attempt to alter.

Instead I tried a Wipe > Factory reset (data, cache, Dalvik cache). This appeared to succeed, but it didn’t solve my bootloop problem.

## Partial firmware flash

Finally I untar’d the firmware (*.tar.md5) files, which produced numerous .img and .bin files, a .pit file, and a few other bits and pieces, and prepared to flash the new firmware, as described above (”short version“).

At this point I faced a puzzling conflict of authorities:

modest_mandroid’s Definitive Guide to Bricking: Avoid flashing bootloader components [BL] if your device has (a) working bootloader(s). If something goes wrong while flashing the bootloader, you’ll end up with a hard brick. [3]

topjohnwu: “Never just flash only AP, or else Odin can shrink your /data filesystem. Flash full AP + BL + CP + HOME_CSC when upgrading.” [2]

Unwilling to end up like Buridan’s ass, I had to choose one of the alternatives. You already know the end of the story: I went with modest_mandroid, so a partial flash, followed by the RMM_bypass and no-verity-opt-encrypt, and then found that Android 10 would boot, but also that the device was then stuck in a long bootloop.

Android 10 seems to work ok. I went through the setup wizard. I’m not sure where to look from within Android to examine /data; I presume that’s not identical with

Internal Storage > Android > Data

. Which is accessible from within Android via the Samsung file manager, and seems to be quite mounted when accessed in that way.

The only troubleshooting step I’ve tried is to reboot into TWRP again and try both a factory reset and an Advanced wipe on ’data’ only. That’s when I noticed the error message quoted above.

The only other thing I’ve noticed is that Android now seems to operate in an inconsistent way. Sometimes when it boots up, it seems to work fine. At other times swiping at the lock screen will clear the time and date and the phone/camera icons but fail to unlock the screen. Sometimes the power off icon seems unresponsive. I never had either of these issues before. But perhaps they’re unrelated to the bootloop.

## Questions

I’d be interested in hearing people’s responses to any of these:

What are you actually doing when you tap Uninstall > Restore images in Magisk Manager? Could this have led to the initial, short bootloop I experienced?

Is the failure to mount /data likely to be a result of the Magisk Manager Uninstall or of the partial firmware flash, or of something else?

Is it likely to be related to the long bootloop?

What does repartitioning with heimdall do?

What should I do now? Full flash (AP + BL + CP + HOME_CSC)? Or just AP + CP + CSC? Repartition with heimdall? Something else?

## Sources

[1] https://www.droidwin.com/install-ota-rooted-android/

[2] https://topjohnwu.github.io/Magisk/install.html#samsung-system-as-root

[3] https://xdaforums.com/t/definitive-guide-to-bricking.1049294/