Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,771,756 Members 41,139 Now Online
XDA Developers Android and Mobile Development Forum

[HOWTO] Combined emulated storage for the Nexus S (LVM) [WIP]

Tip us?
 
KreAch3R
Old
(Last edited by KreAch3R; 15th August 2014 at 06:43 PM.)
#1  
Senior Member - OP
Thanks Meter 58
Posts: 297
Join Date: Nov 2010
Location: Thessaloniki

 
DONATE TO ME
Default [HOWTO] Combined emulated storage for the Nexus S (LVM) [WIP]

Combined emulated storage for the Nexus S (LVM) [WIP]

This is a guide to make your Nexus S use an internal emulated SDcard, and mount it using MTP (just like the Nexus 4 and newer smartphones)!
In order to do that, we have to enable the Logical volume partitioning (LVM) on our rom and recovery, using this great guide. Kudos to @steven676 because without him, this wouldn't be possible.

The end result is this:



in a Nexus S running CM11 M9 with the latest Guru kernel (any rom+kernel combination should work).

It’s going to be a long run, so take your time. This is a summary of what we are going to do:

Summary:
  1. TAKE A FULL BACKUP OF EVERYTHING, INCLUDING SDCARD! EVERYTHING WILL BE ERASED! WE ABSOLUTELY NEED A TWRP BACKUP!
  2. Create a modified recovery, which will recognize the logical volumes
  3. Create the specified logical volumes
  4. Reboot into the recovery, and restore the twrp backup
  5. Modify the updater-script of the ROM you want to use and change the partition directories
  6. Create a modified boot image. I used the Guru kernel, which comes as a full boot.img, and incorporated the changes there.
  7. Archive the modified boot image inside the rom .zip
  8. Create a modified framework-res.apk
  9. Archive the modified framework-res.apk inside the ROM .zip
  10. Copy the now-ready ROM .zip inside the mounted storage, and install it
  11. Boot into CM11 with ~13GB data+sdcard combined storage!

Requirements:
  1. My git repository: https://github.com/KreAch3R/crespo-lvm-emulated-storage
  2. LVM repository: https://github.com/steven676/android-lvm-mod
  3. A ROM .zip (CM11-M9)
  4. A kernel boot.img (Guru kernel)
  5. A custom recovery (TWRP 2.7.1.0)
  6. Android SDK tools configured on your PC (ADB running etc)
  7. Android Image Kitchen
  8. Apktool 2 (setup and ready, using this guide and this file (renamed to apktool.jar).
  9. Basic linux, terminal, adb knowledge

This is my first guide, so any help is appreciated! I have used these steps and they worked for me, but YMMV. I will try to help you as much as I can, but you should be aware that using this guide may brick your phone. Please, be patient, read the guide carefully, take any precautions you want, and of course, I cannot be held responsible for whatever happens to your device. You are following this guide with your own risk (DISCLAIMER). Also, please excuse my wrong terminology, if there is any, and correct any mistakes.

So, if you are ready, let's start!

Mahdi ROM | Android 4.4. Kitkat
Many thanks and gratitude to this awesome community.
The Following 2 Users Say Thank You to KreAch3R For This Useful Post: [ Click to Expand ]
 
KreAch3R
Old
(Last edited by KreAch3R; 20th August 2014 at 12:36 PM.)
#2  
Senior Member - OP
Thanks Meter 58
Posts: 297
Join Date: Nov 2010
Location: Thessaloniki

 
DONATE TO ME
  1. BACKUP, BACKUP, BACKUP!

    Backup everything you can, we need a nandroid backup, sdcard backup, etc. Try to imagine you have lost your phone, and backup what you would have missed!


  2. MODIFY (TWRP) RECOVERY

    1. Unpack the recovery image you want using the Android Image Kitchen
    2. Copy the contents of lvm-bin/ in the lvm repository to lvm/ in the ramdisk folder
    3. Copy devices/crespo/lvm.conf to lvm/etc/lvm.conf in the ramdisk folder
    4. Intergrate the changes from my git files
      (NOTE: I think fstab.herring and recovery.fstab should be identical to fstab.herring from boot.img, and twrp.fstab should be the only different, - but it is just a theory, not tested)
    5. Repack
    6. Flash using fastboot


  3. CREATE SPECIFIED LOGICAL VOLUMES

    I created 3 (in the future, they should be 2) logical partitions on the device, on top of the mmcblk0p1, mmcblk0p2, mmcblk0p3 partitions.

    LVs:
    1. /dev/lvpool/system 550M
    2. /dev/lvpool/userdata 13G
    3. /dev/lvpool/media 1G (for recovery use only)

    Android OS is supposed to only recognize and mount the first two, (/system and /userdata). SDcard is created and symlinked in the /data/media folder, as per official Google examples.
    TWRP Recovery, on the other hand, can mount all three of them, and uses the "media" partition as sdcard storage. I had to hack it like that for now, because I could not build the twrp recovery from source, using the correct make-configs (32bit system only here!), and the current crespo recovery can't recognize the emulated storage correctly, at least as far as I could try.

    NOTE #2:
    The plan is to build a correctly modified twrp for this crespo configuration when I get to my main PC and ditch the /lvpool/media partition. At this point I should mention that /media/ for a recovery-only partition is a terrible name, but I was following the lvm guide to the point, and I didn’t have time to re-do it just for a name change. If you want to change it, also change it in every .fstab file / mount point you find it.

    Steps:
    1. Boot into the recovery you just created (hope it boots)
    2. Use the LVM guide and give the necessary lvm commands to create the logical volumes (ATTENTION! THIS WILL ERASE EVERYTHING!)
    3. Reboot
    4. Mount the USB Storage and format it like a normal USB Stick (FAT32, VFAT). I used the “Disks” program in Lubuntu.
    5. Copy the TWRP backup to USB Storage
      (in my case, it was too big, so I erased the data folder; This all should be pointless I think, if we can use the make_ext4fs command on its own. If I din't restore the backup, the partitions weren't recognized by the twrp recovery. So I'm thinking that it has something to do with them being unformatted - I haven't tried it yet)
    6. Restore it
      (you should see that the recovery is formatting the /system and /data using make_ext4fs, that’s why I think we could skip the restoring)
    7. Full Wipe-factory reset
    8. Now our phone is ready to take our modified rom.zip, once we build it!



  4. ROM UPDATER-SCRIPT
    1. Open the ROM .zip and navigate to the updater-script. Replace the block partitions with the logical ones (I didn’t mess with ‘EMMC’ tag at all). Example, from this:
      Code:
      mount("ext4", "EMMC", "/dev/block/platform/s3c-sdhci.0/by-name/userdata ", "/data")
      To this:
      Code:
      mount("ext4", "EMMC", "/dev/lvpool/userdata", "/data")
    2. Save the file.



  5. MODIFY BOOT.IMG

    1. Unpack boot.img
    2. Copy the contents of lvm-bin/ in the git repository to lvm/ in the ramdisk folder.
    3. 2)Copy devices/crespo/lvm.conf to lvm/etc/lvm.conf in the ramdisk folder.
    4. Intergrate the changes for the following files: fstab.herring, init.herring.rc, init.herring.usb.rc, default.prop
    5. Repack


  6. UPDATE ROM .ZIP W/ NEW BOOT.IMG

    Open the ROM .zip again and drag ‘n’ drop the kernel boot.img inside. It should replace the other one.


  7. MODIFY FRAMEWORK-RES.APK

    1. Extract the .apk from the ROM .zip
    2. Install the framework to apktool [apktool if ...]
    3. Decode the framework-res.apk [apktool d ...]
    4. Intergrate the changes
    5. Build the .apk [apktool b ...]
    6. Open simultaneously the created apk and the unmodified one. Drag ‘n’ drop the changed file from the created one to the unmodified. Save the unmodified file. Be careful to use the now-modified-previously-unmodified .apk from now on.

    TIP: DO NOT use spaces in the apktool directories. Keep it simple to avoid errors.


  8. UPDATE ROM .ZIP W/ NEW FRAMEWORK-RES.APK

    Open the ROM .zip again, drag ‘n’ drop the new framework-res.apk inside /system/framework, and save the file.


  9. INSTALLATION

    Copy the modified ROM .zip inside the mounted USB storage. Install it using the recovery.


  10. BOOT

    Let’s hope that everything went as planned and now you are rocking a Nexus S with a ~13GB combined internal storage! MTP should work, too.

Mahdi ROM | Android 4.4. Kitkat
Many thanks and gratitude to this awesome community.
The Following 2 Users Say Thank You to KreAch3R For This Useful Post: [ Click to Expand ]
 
KreAch3R
Old
(Last edited by KreAch3R; 16th August 2014 at 12:47 PM.)
#3  
Senior Member - OP
Thanks Meter 58
Posts: 297
Join Date: Nov 2010
Location: Thessaloniki

 
DONATE TO ME
My TWRP, BOOT, ROM files, if you want to use them:

Mediafire links:
TWRP Recovery
BOOT img
CM11-M9 ROM

TWRP and BOOT.img are also attached.
Attached Files
File Type: img twrp-lvm-extraSD-patched.img - [Click for QR Code] (5.85 MB, 4 views)
File Type: img guru10-lvm-emulated.img - [Click for QR Code] (3.91 MB, 1 views)

Mahdi ROM | Android 4.4. Kitkat
Many thanks and gratitude to this awesome community.
 
KreAch3R
Old
(Last edited by KreAch3R; 15th August 2014 at 05:14 PM.)
#4  
Senior Member - OP
Thanks Meter 58
Posts: 297
Join Date: Nov 2010
Location: Thessaloniki

 
DONATE TO ME
So, this is it. I hope I covered all edges, and did not make any mistakes (it is a big guide). Please let me know if something is wrong, or you have any suggestions or advice.

Mahdi ROM | Android 4.4. Kitkat
Many thanks and gratitude to this awesome community.
 
cshnz
Old
#5  
Junior Member
Thanks Meter 2
Posts: 7
Join Date: Nov 2013
did the partition is compatible with art?can i install much app in art mode?
 
Zeratul91
Old
#6  
Member
Thanks Meter 19
Posts: 47
Join Date: Jan 2012
Hi!
I'm trying to follow your guide but i'm struck with the twrp recovery, i can boot in the twrp but the recovery doesn't mount any partition and i can't lunch the lvm commands from the other thread (i got "permission denied"). So i made successfully to the lvm partitions with the modded clockwork recovery, format the usb storage, copy the twrp backup and the reflash the modded twrp but even after that the twrp recovery won't mount anything and won't find the backup.
I'll attach my twrp img, can you post yours or help me someway?
Attached Files
File Type: img openrecovery-twrp-2.7.1.0-crespo.img - [Click for QR Code] (5.84 MB, 1 views)
 
KreAch3R
Old
(Last edited by KreAch3R; 16th August 2014 at 01:20 PM.)
#7  
Senior Member - OP
Thanks Meter 58
Posts: 297
Join Date: Nov 2010
Location: Thessaloniki

 
DONATE TO ME
Quote:
Originally Posted by cshnz View Post
did the partition is compatible with art?can i install much app in art mode?
I have not tried ART at all, sorry. You can install many apps using the Dalvik runtime, though, just like any other phone.

Quote:
Originally Posted by Zeratul91 View Post
Hi!
I'm trying to follow your guide but i'm struck with the twrp recovery, i can boot in the twrp but the recovery doesn't mount any partition and i can't lunch the lvm commands from the other thread (i got "permission denied"). So i made successfully to the lvm partitions with the modded clockwork recovery, format the usb storage, copy the twrp backup and the reflash the modded twrp but even after that the twrp recovery won't mount anything and won't find the backup.
I'll attach my twrp img, can you post yours or help me someway?
Hello!

Your twrp.img looks fine! I couldn't understand if you managed to actually create the lvm partitions though. Did you get past this "permission denied" error?
If you are using Linux, try:
Code:
adb kill-server
sudo adb start-server
In Windows try to launch it using administrator privileges

Also, after "adb shell" you can try to "su".
Code:
adb shell
su
If you think you managed to create the lvs successfully, use this command:
Code:
#/lvm/sbin/lvm lvs
to actually see what you have created.

Did you use the same partitions names as the guide? If you changed something, you also change it in all the fstabs, too.

I flashed your recovery, and you are right, no partition is mounted. Re-flashed back to mine and everything works. I can't find any difference though! I will keep searching. For now wait 5 mins for the upload.

I have started uploading my twrp.img, my boot.img and my ROM .zip, to help you test things, I didn't think of that earlier. I will post the links ASAP.

Mahdi ROM | Android 4.4. Kitkat
Many thanks and gratitude to this awesome community.
 
Zeratul91
Old
#8  
Member
Thanks Meter 19
Posts: 47
Join Date: Jan 2012
Quote:
Hello!

Your twrp.img looks fine! I couldn't understand if you managed to actually create the lvm partitions though. Did you get past this "permission denied" error?
If you are using Linux, try:
Code:
adb kill-server
sudo adb start-server
In Windows try to launch it using administrator privileges

Also, after "adb shell" you can try to "su".
Code:
adb shell
su
If you think you managed to create the lvs successfully, use this command:
Code:
#/lvm/sbin/lvm lvs
to actually see what you have created.

Did you use the same partitions names as the guide? If you changed something, you also change it in all the fstabs, too.

I flashed your recovery, and you are right, no partition is mounted. Re-flashed back to mine though and everything works. I can't find any difference though! I will keep searching. For now wait 5 mins for the upload.

I have started uploading my twrp.img, my boot.img and my ROM .zip, to help you test things, I didn't think of that earlier. I will post the links ASAP.
I created the partitions with the names and sizes you said using the modded clockwork from the steven676's guide, I lunched #/lvm/sbin/lvm lvs under clockwork and everything was right and i formatted the 1gb media partition as FAT. TWRP wouldn't anything, not even mount the usb storage, and the adb shell would give me "~ # ←[6n" and permission denied with every command
 
KreAch3R
Old
(Last edited by KreAch3R; 16th August 2014 at 01:14 PM.)
#9  
Senior Member - OP
Thanks Meter 58
Posts: 297
Join Date: Nov 2010
Location: Thessaloniki

 
DONATE TO ME
Quote:
Originally Posted by Zeratul91 View Post
I created the partitions with the names and sizes you said using the modded clockwork from the steven676's guide, I lunched #/lvm/sbin/lvm lvs under clockwork and everything was right and i formatted the 1gb media partition as FAT. TWRP wouldn't anything, not even mount the usb storage, and the adb shell would give me "~ # ←[6n" and permission denied with every command
Let's take this one step at a time. Grab the twrp image from the third post and test it. I can't understand what I forgot to include to the instructions. Testing now.

UPDATE: I think I found the culprit. Are you using Linux or Windows? your "lvm/sbin'lvm" file didn't have executing permissions.
Code:
cd /ramdisk/lvm/sbin
chmod +x lvm
Once I changed that, the twrp recovery worked. I don't know why yours was different from mine, I didn't have to change that.

Mahdi ROM | Android 4.4. Kitkat
Many thanks and gratitude to this awesome community.
 
Zeratul91
Old
(Last edited by Zeratul91; 16th August 2014 at 01:40 PM.)
#10  
Member
Thanks Meter 19
Posts: 47
Join Date: Jan 2012
Quote:
Originally Posted by KreAch3R View Post
Let's take this one step at a time. Grab the twrp image from the third post and test it. I can't understand what I forgot to include to the instructions. Testing now.

UPDATE: I think I found the culprit. Are you using Linux or Windows? your "lvm/sbin'lvm" file didn't have executing permissions.
Code:
cd /ramdisk/lvm/sbin
chmod +x lvm
Once I changed that, the twrp recovery worked. I don't know why yours was different from mine, I didn't have to change that.
Unfortunately I'm on windows :S
BRB I'm going to try with your files

EDIT

I flashed your twrp, now i can use lvm commands and i created successfully the partitions:

Code:
C:\android-sdk-windows\platform-tools>adb shell
~ # ←[6n/lvm/sbin/lvm lvs
/lvm/sbin/lvm lvs
File descriptor 8 (/dev/__properties__) leaked on lvm invocation. Parent PID 120
: /sbin/sh
File descriptor 9 (socket:[1993]) leaked on lvm invocation. Parent PID 120: /sbi
n/sh
  LV       VG     Attr      LSize   Pool Origin Data%  Move Log Copy%  Convert
  media    lvpool -wi-ao---   1.00g
  system   lvpool -wi-a---- 552.00m
  userdata lvpool -wi-a----  13.00g
Now i should format the 1gb media to fat, but usb storage mount does nothing and i still get "unable to mount" error in the twrp log

Tags
emulated, internal, lvm, nexus s, storage
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes