[MOD] Storage Expansion for S4 Mini (microSD for /data)

Search This thread

tM&M

Member
Feb 6, 2020
30
13
------
TLDR
---
As most people know, 8GB is not enough for modern smartphones. With this mod, I provide a modified 'fstab' file and instructions on how to expand '/data' to install apps without root and in a universal way. All apps will install as if in internal storage.
Furthermore, given the old age of these phones, internal eMMC will progressively degrade until the phone dies completely. I have experienced going from 10MB/s writes, to 5, to 2 and then a completely dead phone. This extends the life of eMMC by only writing Android updates to eMMC and will improve responsiveness in phones with very worn eMMC flash.

This is work in progress (some slowdowns occur depending on the card), but I have been daily driving this mode for two months now. I have made adjustments so that the microSD stalls less than stock 'fstab' and EXT4 filesystem.

Example of 64GB card, w/ backup partition (p2) created, still 26GiB free for apps:

IMG_20220630_193309.jpg

---

THIS MAY DELETE YOUR DATA OR SOFT-BRICK YOUR PHONE. Be careful beforehand and backup your data to another microSD card.
IF YOUR PC HAS eMMC DRIVE, /dev/mmcblk1 MAY BE YOUR OS. Check before doing anything and after each reboot, as sometimes Linux reassigns them on machines with eMMC + card reader.

---
TODO/BUGS
---
- Used space will be messed up if you use more than one partition (can't be mounted as removable storage) but free space will be correct.

- Sometimes I have experienced reboots, with no data loss that I can find. I don't think it is related to this ROM mod.

- F2FS is still experimental and has no way to recover from a corrupted drive/card. If something goes wrong, your only option is to dump the files with PhotoRec software and try to recover what you can.
The data will be there but F2FS can't seem to recover from a damaged superblock.
I have used on one phone without issues for 3+ years but when there is SB corruption it can't recover.

- Push this to a 16.0 ROM, which is lighter on the RAM and has ambient display. (just personal preference) This requires a custom ROM.

---
HARDWARE
---
First you need a capable microSDXC card, I have only tested SanDisk Ultra A1 which are not perfect. SanDisk Extreme 64GB A2 class are probably good but please report performance if you try it. I only recommend this class of cards.
The problem with Sandisk Ultra is that sometimes they stall doing GC and the phone also stalls. This is quite random and will be worse if you use the phone for extended periods without time for background GC to run.
The advantages is they do some kind of wear-levelling and I am yet to see one of these cards die to wear out, despite being used on RPi machines 24/7.

SanDisk Ultra cards (A1 class) and most SanDisk USB drives have issues where they perform great when new but don't do proper garbage collection and will get very slow after a couple of days. So benchmarks look fine but real world it becomes really bad. I had a USB drive that only recovered to 5MB/s writes, that was the baseline, after three or four sequential wipes to most of the drive. These types of cards will also be very slow if you try them as adoptable storage.

Any microSD will work but choose a fast one and please help test different brands.

You also need a PC, preferably with Linux, and a card reader of any kind. This can be done in Windows through TWRP and ADB access but I don't recommend it.

---
BASICS
---
We will format the microSD card with one or two partitions. If you split it, you can do manual backups for the second partition but you can't mount it. Remember that by using /data on the SD card, you cannot use TWRP to backup to it. The modded '/data' partition will mount as a removable SD card in stock TWRP.

Download files:

Process flow:
  1. Install 'adb' and enter TWRP mode to access shell,
  2. Use fdisk to create a DOS partition table
  3. Add a new partition with half or full size, starting at block 32768. Leave 1 or 2GiB space free and don't touch it with data. Some types of cards will be able to use these for better performance.
  4. (OPTIONAL) Create 2nd partition right after the first one.
  5. Change the partition(s) type to 'Linux' and spare space as 'Hidden HPFS/NTFS'.
  6. Format partition(s) as F2FS (can also do ext4 but should be unusable),
  7. After this, we will install arco68's 17.1 ROM and push a new 'fstab.qcom' file that will mount the microSD partiton as '/data' and the phone can use it to install apps and user data.
Encryption has not been tested and is not expected to work.

---
PREPARE microSDXC CARD
---
You should also format the card on a Linux PC if you can, as recovery has outdated f2fs-progs or not at all. The ROM has modules and will boot F2FS when instructed to do so.

Check that /dev/mmcblk1 is your microSD card reader BEFORE PROCEEDING! Otherwise, you may nuke your OS!

Do the procedure as listed before, first thing is to 'p' to check you are on the right microSD drive.
Then create the new DOS table and the partitions. This is for expert users only, at this time I will not post detailed fdisk commands.

The output from 'p' print command looks something like this:

Disk /dev/mmcblk1: 31.00 GiB, xxx bytes, 16252928 sectors
Disk model: Sandisk Ultra
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xZZZYYYXXX

Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 * 32768 62947327 62914560 30G 83 Linux
/dev/mmcblk1p2 62947328 yyyyyyyy xxxxxx 900M 17 Hidden HPFS/NTFS

You have to manually type '62947328' for the start of the hidden partition. This is only required if you had put data on the card, upon which you should TRIM the unused blocks:

blkdiscard -v /dev/mmcblk1p2

If you have a partition to do backups, this moves to p3. Next we format p1 to use as '/data':

mkfs.f2fs -s 2 -z 1 -g android /dev/mmcblk1p1

Now we move the card into the phone.

---
ADB COMMANDS
---
This tutorial assumes you have arco68's LineageOS 17.1 from this ROM already installed.

You need to boot the phone in recovery mode by rebooting with VOLUME UP + HOME pressed, until you see 'recovery booting' on the top of the screen.

Next, mount the /system partition and push the new 'fstab' file from your PC:

adb push fstab.qcom /system/vendor/etc/fstab.qcom

After this is completed wait a few seconds, unmount system and reboot the phone. It should take a while for the first boot but you should see the setup screen and everything should be running.
If it is not booting, go to recovery or remove the microSD card and check if files are being created on the drive. If yes, everything seems ok. S4 Mini has a very long first boot, for some reason.

Enjoy your new S4 Mini storage of 32/64/128 GB!
 
Last edited:

Erickgames_HD

Member
Jan 20, 2020
6
0
I already have LOS 17.1 on my gt-i9192, is there any video tutorial to help out in the SDCARD mod process?
 

tM&M

Member
Feb 6, 2020
30
13
Not really. Are you familiar with Linux and formatting hard drives? If you are, it's mostly install the software and run the commands. You need to know how to find the sdcard device node in /dev (if it's sdX or mmcblk0/1, depending on the PC).

I can help you out or post a preformatted MBR file so you can just write it to the SDCard.
 

ivorget

Member
May 26, 2018
9
4
As my 18.1 phone has eaten it's eMMC, I think I'll do this on my next one. Have you used this with Magisk?
 

tM&M

Member
Feb 6, 2020
30
13
As my 18.1 phone has eaten it's eMMC, I think I'll do this on my next one. Have you used this with Magisk?

I definitely recommend doing this then, as I had my eMMC also down to something like 2MiB/s sequential writes before it died - after a few months - and killed the phone completely.

I have never used Magisk nor really understand it's purpose. What would you want to accomplish?
 

tM&M

Member
Feb 6, 2020
30
13
Yes, it is but you would need to change the above FSTAB file entry for 'mmcblk1p1' from F2FS to:

/dev/block/platform/msm_sdcc.3/mmcblk1p1 /data noatime,nosuid,nodev,auto_da_alloc

I would advise you to not use EXT4 as that is usually more suited to flash with advanced FTL and even TRIM support.
 

ivorget

Member
May 26, 2018
9
4
I definitely recommend doing this then, as I had my eMMC also down to something like 2MiB/s sequential writes before it died - after a few months - and killed the phone completely.

I have never used Magisk nor really understand it's purpose. What would you want to accomplish?
Sorry, just saw this now. Yeah I went and ahead and did on 18.1 and it's working great so thanks for making this guide. I guess it's not really necessary as it hasn't caused you issues but I also fixed the relevant userdata partition line in /vendor/etc/selinux/vendor_file_contexts.

A GPT partition table also works fine now, maybe was just lucky as I saw afterwards that was a recent fix lifted into our kernel. Using gparted and mkfs.f2fs from a recent linux system doesn't seem to have caused any issues either.

I'm using a V10 speed card which I think is about the speed of the original eMMC so should probably be the suggested minimum.

Magisk I use for root, mainly for a Tasker setup to tweak charging to extend battery life. I'll tidy it up enough to share at some stage.
Anyway I took a chance and Magisk does work on this setup too.
 

tM&M

Member
Feb 6, 2020
30
13
Sorry, just saw this now. Yeah I went and ahead and did on 18.1 and it's working great so thanks for making this guide. I guess it's not really necessary as it hasn't caused you issues but I also fixed the relevant userdata partition line in /vendor/etc/selinux/vendor_file_contexts.

A GPT partition table also works fine now, maybe was just lucky as I saw afterwards that was a recent fix lifted into our kernel. Using gparted and mkfs.f2fs from a recent linux system doesn't seem to have caused any issues either.

I'm using a V10 speed card which I think is about the speed of the original eMMC so should probably be the suggested minimum.

Magisk I use for root, mainly for a Tasker setup to tweak charging to extend battery life. I'll tidy it up enough to share at some stage.
Anyway I took a chance and Magisk does work on this setup too.

If you can share the context file that would be great. I was having some issues with contexts but this was not MOD related - happened wit the stock ROM - and had to manually fix contexts on TWRP. So maybe that was the issue.

Do please post what card you are using and if you experience performance degradation after a couple of weeks. SanDisk cards are notorious for only running well the first couple of days as they don't have background GC and maybe are not suited to F2FS/EXT4 at all.
 

ivorget

Member
May 26, 2018
9
4
If you can share the context file that would be great. I was having some issues with contexts but this was not MOD related - happened wit the stock ROM - and had to manually fix contexts on TWRP. So maybe that was the issue.

Do please post what card you are using and if you experience performance degradation after a couple of weeks. SanDisk cards are notorious for only running well the first couple of days as they don't have background GC and maybe are not suited to F2FS/EXT4 at all.
OK I've attached the file - remove the .txt extension. Search for mmcblk1p1 to see the changes - one line referencing mmcblk1p1 commented out and another line where the data partition is changed to that.
(Full disclosure: I'm using partition 4 so I didn't need to comment out the mmcblk1p1 partition line in my setup.)
Reminder that the file is for 18.1 (unless you find that it's the same for 17.1). And to be clear for anyone else reading the full path it goes under is:
/system/vendor/etc/selinux/

My SD card is a Kingston Canvas Select Plus. The package indicates Class 10 U1 so maybe better to say that as the V10 only appears on the card label.

I am a little concerned that the default android 3-day trim seems to be taking longer but I'll keep an eye on it:
$ logcat | grep -E 'trim |Trimmed' 02-04 06:50:34.969 191 9173 D vold : Starting trim of /data 02-04 06:51:09.778 191 9173 I vold : Trimmed 397697024 bytes on /data in 34799ms
 

Attachments

  • vendor_file_contexts.txt
    88 KB · Views: 15
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    ------
    TLDR
    ---
    As most people know, 8GB is not enough for modern smartphones. With this mod, I provide a modified 'fstab' file and instructions on how to expand '/data' to install apps without root and in a universal way. All apps will install as if in internal storage.
    Furthermore, given the old age of these phones, internal eMMC will progressively degrade until the phone dies completely. I have experienced going from 10MB/s writes, to 5, to 2 and then a completely dead phone. This extends the life of eMMC by only writing Android updates to eMMC and will improve responsiveness in phones with very worn eMMC flash.

    This is work in progress (some slowdowns occur depending on the card), but I have been daily driving this mode for two months now. I have made adjustments so that the microSD stalls less than stock 'fstab' and EXT4 filesystem.

    Example of 64GB card, w/ backup partition (p2) created, still 26GiB free for apps:

    IMG_20220630_193309.jpg

    ---

    THIS MAY DELETE YOUR DATA OR SOFT-BRICK YOUR PHONE. Be careful beforehand and backup your data to another microSD card.
    IF YOUR PC HAS eMMC DRIVE, /dev/mmcblk1 MAY BE YOUR OS. Check before doing anything and after each reboot, as sometimes Linux reassigns them on machines with eMMC + card reader.

    ---
    TODO/BUGS
    ---
    - Used space will be messed up if you use more than one partition (can't be mounted as removable storage) but free space will be correct.

    - Sometimes I have experienced reboots, with no data loss that I can find. I don't think it is related to this ROM mod.

    - F2FS is still experimental and has no way to recover from a corrupted drive/card. If something goes wrong, your only option is to dump the files with PhotoRec software and try to recover what you can.
    The data will be there but F2FS can't seem to recover from a damaged superblock.
    I have used on one phone without issues for 3+ years but when there is SB corruption it can't recover.

    - Push this to a 16.0 ROM, which is lighter on the RAM and has ambient display. (just personal preference) This requires a custom ROM.

    ---
    HARDWARE
    ---
    First you need a capable microSDXC card, I have only tested SanDisk Ultra A1 which are not perfect. SanDisk Extreme 64GB A2 class are probably good but please report performance if you try it. I only recommend this class of cards.
    The problem with Sandisk Ultra is that sometimes they stall doing GC and the phone also stalls. This is quite random and will be worse if you use the phone for extended periods without time for background GC to run.
    The advantages is they do some kind of wear-levelling and I am yet to see one of these cards die to wear out, despite being used on RPi machines 24/7.

    SanDisk Ultra cards (A1 class) and most SanDisk USB drives have issues where they perform great when new but don't do proper garbage collection and will get very slow after a couple of days. So benchmarks look fine but real world it becomes really bad. I had a USB drive that only recovered to 5MB/s writes, that was the baseline, after three or four sequential wipes to most of the drive. These types of cards will also be very slow if you try them as adoptable storage.

    Any microSD will work but choose a fast one and please help test different brands.

    You also need a PC, preferably with Linux, and a card reader of any kind. This can be done in Windows through TWRP and ADB access but I don't recommend it.

    ---
    BASICS
    ---
    We will format the microSD card with one or two partitions. If you split it, you can do manual backups for the second partition but you can't mount it. Remember that by using /data on the SD card, you cannot use TWRP to backup to it. The modded '/data' partition will mount as a removable SD card in stock TWRP.

    Download files:

    Process flow:
    1. Install 'adb' and enter TWRP mode to access shell,
    2. Use fdisk to create a DOS partition table
    3. Add a new partition with half or full size, starting at block 32768. Leave 1 or 2GiB space free and don't touch it with data. Some types of cards will be able to use these for better performance.
    4. (OPTIONAL) Create 2nd partition right after the first one.
    5. Change the partition(s) type to 'Linux' and spare space as 'Hidden HPFS/NTFS'.
    6. Format partition(s) as F2FS (can also do ext4 but should be unusable),
    7. After this, we will install arco68's 17.1 ROM and push a new 'fstab.qcom' file that will mount the microSD partiton as '/data' and the phone can use it to install apps and user data.
    Encryption has not been tested and is not expected to work.

    ---
    PREPARE microSDXC CARD
    ---
    You should also format the card on a Linux PC if you can, as recovery has outdated f2fs-progs or not at all. The ROM has modules and will boot F2FS when instructed to do so.

    Check that /dev/mmcblk1 is your microSD card reader BEFORE PROCEEDING! Otherwise, you may nuke your OS!

    Do the procedure as listed before, first thing is to 'p' to check you are on the right microSD drive.
    Then create the new DOS table and the partitions. This is for expert users only, at this time I will not post detailed fdisk commands.

    The output from 'p' print command looks something like this:

    Disk /dev/mmcblk1: 31.00 GiB, xxx bytes, 16252928 sectors
    Disk model: Sandisk Ultra
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xZZZYYYXXX

    Device Boot Start End Sectors Size Id Type
    /dev/mmcblk1p1 * 32768 62947327 62914560 30G 83 Linux
    /dev/mmcblk1p2 62947328 yyyyyyyy xxxxxx 900M 17 Hidden HPFS/NTFS

    You have to manually type '62947328' for the start of the hidden partition. This is only required if you had put data on the card, upon which you should TRIM the unused blocks:

    blkdiscard -v /dev/mmcblk1p2

    If you have a partition to do backups, this moves to p3. Next we format p1 to use as '/data':

    mkfs.f2fs -s 2 -z 1 -g android /dev/mmcblk1p1

    Now we move the card into the phone.

    ---
    ADB COMMANDS
    ---
    This tutorial assumes you have arco68's LineageOS 17.1 from this ROM already installed.

    You need to boot the phone in recovery mode by rebooting with VOLUME UP + HOME pressed, until you see 'recovery booting' on the top of the screen.

    Next, mount the /system partition and push the new 'fstab' file from your PC:

    adb push fstab.qcom /system/vendor/etc/fstab.qcom

    After this is completed wait a few seconds, unmount system and reboot the phone. It should take a while for the first boot but you should see the setup screen and everything should be running.
    If it is not booting, go to recovery or remove the microSD card and check if files are being created on the drive. If yes, everything seems ok. S4 Mini has a very long first boot, for some reason.

    Enjoy your new S4 Mini storage of 32/64/128 GB!