i9100 emulated sdcard, partition resizing and full disk encryption - Galaxy S II General

I recently upgraded a Galaxy S2 to Cyanogenmod 12.1 / android 5.1. I also wanted to use full disk encryption with the device and being able to access the internal memory via MTP instead of having a mass storage device. The removable sd card may be accessed via MTP, too, but will not be encrypted. Updating the recovery images to reflect the changes in the storage configuration (in case this is necessary) is not in scope, either.
Cyanogenmod by default only encrypts the /data partition. Newer models emulate the sdcard storage and save the data to /data/media, so everything gets encrypted. However, being an older phone there is still a separate sdcard-partition on the phone which is physically and directly mounted and which will not be touched by encryption.
In order to achieve the goal of full disk encryption two steps are necessary:
1. Change storage configuration to emulated media
2. Shrink old /sdcard partition and grow /data partition
= Change storage configuration to emulated media =
Emulating the sdcard in /data/media instead of physically mounting it directly requires changes to fstab.hardware (fstab.smdk4210), storage_list.xml and init.hardware.rc (init.smdk4210.rc). These files have to be changed in the Cyanogenmod source code and compiled to a new image. The configuration is based on the "Emulated primary, physical secondary" example given in h t t p s : / / source . android . com / devices / storage / config-example.html (cannot properly post URL due to new user restriction).
Here are the relevant changes in init.hardware.rc (init.smdk4210.rc):
Code:
--- init.smdk4210.rc.bak 2015-11-22 23:01:49.259579157 +0000
+++ init.smdk4210.rc.final 2015-11-30 20:21:37.977943177 +0000
@@ -2,35 +2,47 @@
import init.gps.rc
on init
- export EXTERNAL_STORAGE /storage/sdcard0
+ export EXTERNAL_STORAGE /storage/emulated/legacy
+ export EMULATED_STORAGE_SOURCE /mnt/shell/emulated
+ export EMULATED_STORAGE_TARGET /storage/emulated
export SECONDARY_STORAGE /storage/sdcard1
- mkdir /mnt/media_rw/sdcard0 0700 media_rw media_rw
- mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw
mkdir /mnt/media_rw/usbdisk0 0700 media_rw media_rw
- mkdir /storage/sdcard0 0770 root root
- mkdir /storage/sdcard1 0770 root root
+ mkdir /mnt/shell/emulated 0700 shell shell
+ mkdir /storage/emulated 0555 root root
+ mkdir /mnt/media_rw/sdcard1 0700 media_rw media_rw
+ mkdir /storage/sdcard1 0700 root root
+
mkdir /storage/usbdisk0 0770 root root
+ mkdir /storage/sdcard1 0775 system system
+
mkdir /efs 0771 radio system
mkdir /preload 0771 system system
mkdir /mnt 0775 root system
mkdir /mnt/.lfs 0755 root root
# for backwards compatibility
- symlink /storage/sdcard0 /sdcard
- symlink /storage/sdcard0 /mnt/sdcard
- symlink /storage/sdcard1 /extSdCard
- symlink /storage/sdcard1 /mnt/extSdCard
symlink /storage/usbdisk0 /usbdisk0
symlink /storage/usbdisk0 /mnt/usbdisk0
+ symlink /storage/emulated/legacy /sdcard
+ symlink /storage/emulated/legacy /mnt/sdcard
+ symlink /storage/emulated/legacy /storage/sdcard0
+ symlink /mnt/shell/emulated/0 /storage/emulated/legacy
+ symlink /storage/sdcard1 /ext_card
+ symlink /storage/sdcard1 /mnt/ext_card
+
+
+
# Disable CFQ slice idle delay
write /sys/block/mmcblk0/queue/iosched/slice_idle 0
on fs
mount_all /fstab.smdk4210
+ setprop ro.crypto.fuse_sdcard true
+
swapon_all /fstab.smdk4210
mkdir /efs/bluetooth
@@ -428,11 +440,10 @@
oneshot
keycodes 114 115 116
-service fuse_sdcard0 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard0 /storage/sdcard0
+service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
class late_start
- disabled
-service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
+service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -w 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
class late_start
disabled
Here are the relevant changes in fstab.hardware (fstab.smdk4210):
Code:
--- fstab.smdk4210.bak 2015-11-29 23:52:30.652913883 +0000
+++ fstab.smdk4210.final 2015-11-30 20:20:23.513945994 +0000
@@ -11,8 +11,8 @@
/dev/block/mmcblk0p12 /preload ext4 noatime,nosuid,nodev,journal_async_commit wait
# vold-managed volumes ("block device" is actually a sysfs devpath)
-/devices/platform/dw_mmc/mmc_host/mmc0/mmc0* auto auto defaults wait,voldmanaged=sdcard0:11,nonremovable,noemulatedsd
-/devices/platform/s3c-sdhci.2/mmc_host/mmc1* auto auto defaults wait,voldmanaged=sdcard1:auto,noemulatedsd
+/devices/platform/dw_mmc/mmc_host/mmc0/mmc0* auto auto defaults wait,voldmanaged=sdcard0:11,nonremovable
+/devices/platform/s3c-sdhci.2/mmc_host/mmc1* auto auto defaults wait,voldmanaged=sdcard1:auto
/devices/platform/s3c_otghcd/usb* auto auto defaults voldmanaged=usbdisk0:auto
# recovery
Here are the relevant changes in storage_list.xml:
Code:
--- storage_list.xml.bak2 2015-11-30 21:38:14.565769302 +0000
+++ storage_list.xml.final 2015-11-30 21:43:21.697757684 +0000
@@ -1,16 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<StorageList xmlns:android="h t t p : / / schemas . android . com / apk / res / android "(cannot properly post URL due to new user restriction)>
- <storage android:mountPoint="/storage/sdcard0"
- android:storageDescription="@string/storage_internal"
- android:primary="true"
- android:removable="false"
- android:allowMassStorage="true" />
+ <storage android:storageDescription="@string/storage_internal"
+ android:emulated="true"
+ android:mtpReserve="100" />
<storage android:mountPoint="/storage/sdcard1"
android:storageDescription="@string/storage_sd_card"
- android:primary="false"
android:removable="true"
- android:allowMassStorage="true" />
+ android:maxFileSize="4096" />
<storage android:mountPoint="/storage/usbdisk0"
android:storageDescription="@string/storage_usb"
@@ -18,3 +15,4 @@
android:removable="true" />
</StorageList>
Compile Cyanogenmod and flash your phone. It should boot, but the amount of available storage should be significantly lower as the sdcard is emulated on the /data partition which has not been grown, yet.
= Shrink old /sdcard partition and grow /data partition =
Use PIT Magic to resize the partitions to an appropriate size. For a stock i9100 having 16GB of internal memory my configuration was as follows (according to the backup .pit-file downloaded via heimdall):
Code:
DATAFS:
start: 1,392,640
block count: 4,194,304
end: 5,586,943
UMS:
start: 5,586,944
block count: 24,133,632
end: 29,720,575
Hidden:
start: 29,720,576
block count: 1,048,576
end: 30,769,151
I changed the partition layout to the following sizes:
Code:
DATAFS:
start: 1,392,640
block count: 28,295,167
end: 29,687,807
UMS:
start: 29,687,808
block count: 32,768
end: 29,720,575
Hidden:
start: 29,720,576
block count: 1,048,576
end: 30,769,151
Deleting the UMS or hidden partitions or shrinking the hidden led to Cyanogenmod not booting. Upload the new .pit-file using heimdall and boot the modified Cyanogenmod. Reboot to Cyanogenmod recovery and wipe data. Formatting again using the Cyanogenmod recovery was required as apparently only this recovery honours the "encryptable=footer,length=-16384" option for the /data partition in fstab.hardware which directs the formatting tools to leave 16 kiB of space at the end of the partition for in-place encryption.

Is there a way to achieve emulated SD, without changing source code and recompiling?
Like editing fstab and other config files?
I run CM13 at the moment and would like to achieve full encryption through emulated SD.

I was playing around with the idea that i would resize the sdcard partition to 8mb and resize the /data partition (~14gb), so that applications have a hefty space and i would use the external sdcard (sdcard1) for storing data and media files. Would that be possible to with an emulated sdcard ? I was hoping that with the introduction of Android 6.0 it would allow me to merge (LVM?) the /sdcard0 and /sdcard1 but instead it merges /data and /sdcard1.

fireburner-de said:
Is there a way to achieve emulated SD, without changing source code and recompiling?
Like editing fstab and other config files?
Click to expand...
Click to collapse
I cannot prove that there is no way without having to recompile. However, I couldn't find storage_list.xml in the filesystem on my phone, so I assume that this file is only used during image compilation and therefore it's probably hard/impossible to achieve emulated SD without recompiling.
Maybe this configuration is easier to achieve using Cyanogenmod 13 / Android 6 as the storage_list.xml resource overlay has been removed.

PelzigesOhr, thank you sharing and documenting your experience so well, it has inspired me to try the same on Replicant 4.2 (distro based on CyanogenMod 10).
https:// github . com / GrimKriegor / replicant42-device_samsung_galaxys2-common / commit / 84c5a91a45b059a147921d0ea32367534904b314
However it seems the best way to create a partition table is using PitMagic, which seems to be proprietary software. Would you consider sharing your PIT file please?
Thank you for your time, all of this is greatly appreciated!
EDIT:
If you still have memory of the heimdall parameters used to flash this partition table, please do share as well.
EDIT2:
Managed to create a PIT file similar to yours, thanks for documenting it.
The following thread also includes a patch compatible with Replicant/Android 4.2.
Best of luck!
redmine . replicant . us / boards / 39 / topics / 13707

GrimKriegor said:
Would you consider sharing your PIT file please?
Thank you for your time, all of this is greatly appreciated!
EDIT:
If you still have memory of the heimdall parameters used to flash this partition table, please do share as well.
EDIT2:
Managed to create a PIT file similar to yours, thanks for documenting it.
The following thread also includes a patch compatible with Replicant/Android 4.2.
Click to expand...
Click to collapse
Thanks for the praise, I'm happy that the instructions are of use to someone else. Good to know that you managed everything yourself, I'll answer anyway: This forum doesn't seem to support attachments, so I haven't attached the .pit-file. Feeding the parameters I provided to PIT Magic should yield a good result, though. PIT Magic is indeed a proprietary Windows binary, but it runs fine using wine (at least that's the way I use it).
All the flashing has been done by loading clockworkmodrecovery (
Code:
heimdall flash --KERNEL clockworkmodrecovery.6050.i9100.touch.img
) and afterwards sideloading the compiled ROM.

PelzigesOhr said:
Thanks for the praise, I'm happy that the instructions are of use to someone else. Good to know that you managed everything yourself, I'll answer anyway: This forum doesn't seem to support attachments, so I haven't attached the .pit-file. Feeding the parameters I provided to PIT Magic should yield a good result, though. PIT Magic is indeed a proprietary Windows binary, but it runs fine using wine (at least that's the way I use it).
All the flashing has been done by loading clockworkmodrecovery (
Code:
heimdall flash --KERNEL clockworkmodrecovery.6050.i9100.touch.img
) and afterwards sideloading the compiled ROM.
Click to expand...
Click to collapse
Thanks for the reply sir.
Which partitions did you upload via Heimdall when you flashed the PIT file? I believe repartitioning could delete the contents of important partitions such as BOOT and MODEM, but I am unsure. Do you think maintaining their block boundaries would preserve the data in the respective partitions?

guy i can't mount /storage/sdcard0
i use Cyanogenmod 12.1 android 5.1.1
i need help guy

GrimKriegor said:
Which partitions did you upload via Heimdall when you flashed the PIT file? I believe repartitioning could delete the contents of important partitions such as BOOT and MODEM, but I am unsure. Do you think maintaining their block boundaries would preserve the data in the respective partitions?
Click to expand...
Click to collapse
The exact command I used for repartitioning with Heimdall-1.3.1 was as follows:
Code:
heimdall flash --repartition --pit <filename>
Data should be preserved and if you don't mess with the boundaries of partitions other than DATAFS, UMS and HIDDEN you should be fine. Before repartitioning I backed up all partitions as a precautionary measure, but I didn't have to restore any of them. See also http://forum.xda-developers.com/galaxy-s2/orig-development/guide-enlarge-datafs-partition-rid-t2353551

PelzigesOhr said:
The exact command I used for repartitioning with Heimdall-1.3.1 was as follows:
Code:
heimdall flash --repartition --pit <filename>
Data should be preserved and if you don't mess with the boundaries of partitions other than DATAFS, UMS and HIDDEN you should be fine. Before repartitioning I backed up all partitions as a precautionary measure, but I didn't have to restore any of them. See also http://forum.xda-developers.com/galaxy-s2/orig-development/guide-enlarge-datafs-partition-rid-t2353551
Click to expand...
Click to collapse
Ah! This is excellent, thanks for clarifying this! Just one last question if I may, how did you backup the partitions? Did you use Heimdall to download their contents as image files, did you use DD or maybe even ADB?
Thank you for your time!

GrimKriegor said:
Just one last question if I may, how did you backup the partitions? Did you use Heimdall to download their contents as image files, did you use DD or maybe even ADB?
Click to expand...
Click to collapse
Good guess, I used dd and adb. Get a shell on the phone with adb and dump the partitions to files using dd:
Code:
dd if=/dev/block/mmcblk0pX of=/sdcard/mmcblk0pX.bin bs=512
And then copy the files to your computer using adb pull. You may want to get the mountpoints of the partitions (e.g. using mount) so that you can associate them easily.

Read here for an easy way to switch to emulated storage. Thanks to @Lanchon
https://forum.xda-developers.com/galaxy-s2/orig-development/mod-switch-emulated-to-emulated-t3539651

Related

[HOW-TO] Make Ext4 from Recovery Without Losing FAT32 Data

I've seen a lot of threads detailing how to create an Ext4 partition using Gparted but if you don't want to download the image and would rather do it all on your phone, here's how:
This entire procedure should take less than 5min so you can go back to messing with your phone in other ways.
REQUIRES:
CLOCKWORK MOD RECOVERY
ADB
FINGERS
I am not responsible for any damage done to your phone doing this process. =.=
1. Download the zip file provided.
2. Extract the zip file to the same folder you have ADB in. (You should now have a folder named ext4 in the same folder you have ADB)
3. Reboot the phone into MAGDLR. Then select the option to boot into the recovery.
4. Make sure that /system/ is mounted using the option to mount partition in Clockwork Recovery.
5. Open a command (cmd) prompt and cd into your folder with ADB.
6. Run these commands in the command prompt. (Commands are in BOLD)
adb push ext4 /system/etc/
adb shell
parted /dev/block/mmcblk0
print (make note of the total size of your partition here)
resize 1 0 xxxx (where xxxx is the size you want for your FAT32 partition. It should equal total size of your partition that you gleaned from print minus 1024 for the ext4 partition you're about to set up)
mkpartfs primary ext2 xxxx yyyy (where xxxx is where your previous partition ended and yyyy is the total size of your sdcard)
.... (Let it do its thing. Shouldn't take more than a minute)
print (Make sure that everything is correct: You have a fat32 partition running from 0 to xxxx and an ext2 partition running from xxxx to the total size of your partition)
quit
Now to utilize the two files we previously pushed to /system/etc/
chmod 777 /system/etc/tune2fs
chmod 777 /system/etc/e2fsck
/system/etc/tune2fs -j /dev/block/mmcblk0p2 <- You now have ext3
/system/etc/tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p2 (Note: CAsE SEnSitiVE)
/system/etc/e2fsck -fpDC0 /dev/block/mmcblk0p2 (Note: CAsE SEnSitiVE) <- You now have ext4
7. You can check that it's truly ext4 by:
parted /dev/block/mmcblk0
print (It should now read that you have a FAT32 and an ext4 partition.)
quit
You're all done! Now you have a 1GB ext4 partition for all your data and apps. If you know what you're doing, these same steps can be modified so that you have two ext4 partitions if you'd like. You can also alter the size of your ext4 partition to something smaller if you don't have that many apps to install or have a smaller SDcard (512MB should be sufficient in most cases, 1GB is slightly overkill IMO)
i will try with my HD2. I need more space to install app on sd not on phone. Thanks so much
Hi, I follow your instruction but when I get a "Permision deined" error when I type in the following commond
/system/etc/tune2fs -j /dev/block/mmcblk0p2
Can you please help?
Many many thanks!!
justj said:
Hi, I follow your instruction but when I get a "Permision deined" error when I type in the following commond
/system/etc/tune2fs -j /dev/block/mmcblk0p2
Can you please help?
Many many thanks!!
Click to expand...
Click to collapse
Crap. I forgot a step. You have to type
chmod 777 /system/etc/tune2fs
chmod 777 /system/etc/e2fsck
prior to using those files. That should fix the permission denied error.
I've edited the OP to reflect the changes, thanks for pointing that out.
Thanks man
Thanks Bro I have successfully make ext4 and I am enjoying my new Rom
Using HTC Desire runnymede 5.0
Amazing. I will keep it for future reference, although I partitioned my SD with CWM recovery and Gparted.
What kind of partition is made when using CWM? I made a 1GB partition on my card that way, and it works great. But I've heard good things about having it as ext4. How does this guide reflect the fact that I already have an SD-EXT on my card that's not necessarily ext4?
Thanks!
please help
please help me i cant get it to work... its same with /system mounted and unmounted...not even one 3rd app is working for me on my win 7 64x when i want to create ext4 this is my last hope. card is brand new 8gb ultra speed its working fine so cant be problem there. it seems like chmod 777 will delete that file..
Code:
C:\Users\OgziR\Desktop\adt-bundle-windows-x86_64-20130522\sdk\platform-tools>adb
push ext4 /system/etc/
push: ext4/tune2fs -> /system/etc/tune2fs
push: ext4/e2fsck -> /system/etc/e2fsck
2 files pushed. 0 files skipped.
1573 KB/s (603400 bytes in 0.374s)
C:\Users\OgziR\Desktop\adt-bundle-windows-x86_64-20130522\sdk\platform-tools>adb
shell
~ # /system/etc/tune2fs -j /dev/block/mmcblk0p2
/system/etc/tune2fs -j /dev/block/mmcblk0p2
/sbin/sh: /system/etc/tune2fs: Permission denied
~ # chmod 777 /system/etc/tune2fs
chmod 777 /system/etc/tune2fs
~ # /system/etc/tune2fs -j /dev/block/mmcblk0p2
/system/etc/tune2fs -j /dev/block/mmcblk0p2
/sbin/sh: /system/etc/tune2fs: not found
~ #
Hye... I have 2 question...
My phone is a HTC HD2 running an NexusHD2.ICS.CM9.HWA.V2.3 ROM... The cmd prompt cant seem so fine my device. Do have any advice on this???
Secondly, what do i do with the ext4.zip file??? I mean, do it extract it, or put in same folder with ADB??
Btw, i am Super Noob on this, so i apologize if my question offends anyone... 1000 apologizes...
OK, first of all, do you have adb installed correctly? If cmd prompt can't find your device that is the most likely problem.
As for what to do with ext4.zip, you need to extract it to your adb folder.
Sent from my Vivid 4G using xda app-developers app

[HOWTO] Loop mount

OK, I spent a couple of hours figuring out how loop mounting works. The problem is that the mount command in both toolbox and busybox supports only one loop device. I modified the toolbox version to allow the specification of a new loop device.
Here is how to make a 500mb loop-mounted ext2 system at /mnt/myloop , with the system being stored in /storage/sdcard/myext2system.img
Step 1. Make sure you have root. Download bettermount*.zip to your PC from here. Copy the "bettermount" file from the zip file to /data/local/ (or some other location). One way of doing that is with:
Code:
adb push bettermount /data/local
on the PC. Or you can mount your device to USB, copy bettermount to storage, and then in a root shell copy it to /data/local. Or if you have RW root, you can install bettermount in /bin or some other convenient location.
Start a shell on the device, either via adb or an on-device terminal (not recommended unless you have an external keyboard). Switch to root:
Code:
su
Then make bettermount executable:
Code:
chmod 755 /data/local/bettermount
The following steps assume you're still in your root shell.
Step 2. Create ext2 file system in a file. (Skip this if you already have one.)
Code:
dd if=/dev/zero of=/storage/sdcard/myext2system.img bs=1M count=500
mke2fs /storage/sdcard/myext2system.img
mke2fs will give you a warning that this isn't a block special device, but just press "y" and "enter".
Step 3. Create a loop device node for the ext2 file system. The problem here is that the OS uses loop device nodes for apps moved to external storage and one for the system squashfs, and it only has enough loop device nodes for those purposes--any loop device nodes in /dev/block are already in use. On the assumption that you aren't going to have more than 253 apps moved to storage, we're going to create a loop device node numbered 255. If you like, you can check that there isn't already one with that number with
Code:
ls /dev/block/loop*
So, let's create the loop device node:
Code:
mknod -m640 /dev/block/loop255 b 7 255
Step 4. Create a mount point:
Code:
mkdir /mnt/myloop
Step 5. Mount myext2filesystem.img:
Code:
/data/local/bettermount -t ext2 -orw,exec,noatime,nodiratime,sync,loop=/dev/block/loop255 /storage/sdcard/myext2system.img /mnt/myloop
Enjoy your new file system at /mnt/myloop !
You will have to repeat Steps 3-5 after every boot, or else you can make a script that runs every time you boot. You could simply put the commands for 3-5 into a Script Manager script set to run on boot, or there may be some better, more unixy way (but I haven't had any luck editing startup scripts).
What to do with your shiny new filesystem? Well, you could move not just apps but also their libraries to external storage (you can also do that by remounting your external storage in exec mode).
arpruss said:
OK, I spent a couple of hours figuring out how loop mounting works. The problem is that the mount command in both toolbox and busybox supports only one loop device. I modified the toolbox version to allow the specification of a new loop device.
Here is how to make a 500mb loop-mounted ext2 system at /mnt/myloop , with the system being stored in /storage/sdcard/myext2system.img
Step 1. Make sure you have root. Download bettermount*.zip to your PC from here. Copy the "bettermount" file from the zip file to /data/local/ (or some other location). One way of doing that is with:
Code:
adb push bettermount /data/local
on the PC. Or you can mount your device to USB, copy bettermount to storage, and then in a root shell copy it to /data/local. Or if you have RW root, you can install bettermount in /bin or some other convenient location.
Start a shell on the device, either via adb or an on-device terminal (not recommended unless you have an external keyboard). Switch to root:
Code:
su
Then make bettermount executable:
Code:
chmod 755 /data/local/bettermount
The following steps assume you're still in your root shell.
Step 2. Create ext2 file system in a file. (Skip this if you already have one.)
Code:
dd if=/dev/zero of=/storage/sdcard/myext2system.img bs=1M count=500
mke2fs /storage/sdcard/myext2system.img
mke2fs will give you a warning that this isn't a block special device, but just press "y" and "enter".
Step 3. Create a loop device node for the ext2 file system. The problem here is that the OS uses loop device nodes for apps moved to external storage and one for the system squashfs, and it only has enough loop device nodes for those purposes--any loop device nodes in /dev/block are already in use. On the assumption that you aren't going to have more than 253 apps moved to storage, we're going to create a loop device node numbered 255. If you like, you can check that there isn't already one with that number with
Code:
ls /dev/block/loop*
So, let's create the loop device node:
Code:
mknod -m640 /dev/block/loop255 b 7 255
Step 4. Create a mount point:
Code:
mkdir /mnt/myloop
Step 5. Mount myext2filesystem.img:
Code:
/data/local/bettermount -t ext2 -orw,exec,noatime,nodiratime,sync,loop=/dev/block/loop255 /storage/sdcard/myext2filesystem.img /mnt/myloop
Enjoy your new file system at /mnt/myloop !
You will have to repeat Steps 3-5 after every boot, or else you can make a script that runs every time you boot. You could simply put the commands for 3-5 into a Script Manager script set to run on boot, or there may be some better, more unixy way (but I haven't had any luck editing startup scripts).
What to do with your shiny new filesystem? Well, you could move not just apps but also their libraries to external storage (you can also do that by remounting your external storage in exec mode).
Click to expand...
Click to collapse
Which version of busybox were you testing with? I haven't had a problem with multiple loop devices...
I've been using the stock busybox: 1.7.2.
Do you use -oloop=/dev/block/loopNN to specify the device?
I just tried 1.16.0 from the Titanium Backup website. No luck. I created /dev/block/loop222. Then:
Code:
# /tmp/busybox mount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
mount: can't setup loop device: No such file or directory
# bettermount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
# (works!)
I also tried just plain -oloop, without the =/dev/block/loop222, and it didn't work.
arpruss said:
I've been using the stock busybox: 1.7.2.
Do you use -oloop=/dev/block/loopNN to specify the device?
I just tried 1.16.0 from the Titanium Backup website. No luck. I created /dev/block/loop222. Then:
Code:
# /tmp/busybox mount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
mount: can't setup loop device: No such file or directory
# bettermount -t ext2 -oloop=/dev/block/loop222 /storage/10.img /mnt/myloop
# (works!)
I also tried just plain -oloop, without the =/dev/block/loop222, and it didn't work.
Click to expand...
Click to collapse
I can't remember if mount was symlinked to busybox at the time, but I just used the standard "mount -o loop disk1.img /mnt/disk". I may have even been on a custom kernel and had a crosscompiled mount, so good work, this is probably going to be a common problem for people.
The problem with busybox seems to be that it thinks /dev/block/loop0 is free, but it's not. Doing losetup -f returns /dev/block/loop0.
If you could mount the loopdevice in init.rc this would be the easiest way to expand the 300MB /data problem with archos.
Also it might be the best way in CM7 until its stable for the persistent Data between revisions.
fzelle said:
If you could mount the loopdevice in init.rc this would be the easiest way to expand the 300MB /data problem with archos.
Also it might be the best way in CM7 until its stable for the persistent Data between revisions.
Click to expand...
Click to collapse
I have had no luck adding anything to init.rc with the rw root.
Moreover, /storage and /storage/sdcard get mounted quite late in the boot process--late enough that I think one can't just move the /data directory there. I suppose one might be able to mount them earlier in the process, but I haven't been able to figure out how to run anything in an init script. If anybody knows how to do it, please speak up!
What one could do, however, is mount the loop from an app's on-boot notification, and then symlink individual app files.
It looks like with a better busybox than the one included with the device, one can also use losetup to specify the loop device--see here.
I built a full 1.18.5 version of Busybox, and it does loop mounting just right. You can replace Step 1 of my HOWTO with fetching my modified busybox and putting it in /data/local, from http://code.google.com/p/busybox-for-android/downloads/list
Then step 3 is not needed.
Step 4 should be replaceable with the very simple:
Code:
/data/local/busybox mount -orw,exec,noatime,nodiratime,sync,loop /storage/sdcard/myext2system.img /mnt/myloop
Or if you're pressed for time, and want to use default mount options:
Code:
/data/local/busybox mount -oloop /storage/sdcard/myext2system.img /mnt/myloop
But if you want to implement this is inside an app, depending on your license needs, you may want to use the longer method, since busybox is GPL while bettermount is Apache 2.

[GUIDE] Make sd-ext as data partition (easy way)

You can find some thread for you to move data partition to sd-ext. But there is a easier way to do that: Modify the mount point of sd-ext and data in ramdisk.
The basic step is:
0. Make a nandroid backup
1. Make an ext4 partition on your sdcard (I used gparted in ubuntu, very fast and not lost data)
2. Download your kernel as boot.img
3. Unpack you boot.img (you can find many thread said how to do, and I think the most completly tool you can get from http://forum.xda-developers.com/showthread.php?t=1241005. You can find the example to unpack boot.img, extract ramdisk, repack ramdisk, repack boot.img from the README.txt file of this tool)
4. Extract ramdisk:
Code:
gzip -dc ../unpack/boot.img-ramdisk.gz | cpio -i
If you find ramdisk.cpio file, you need to extract it by
Code:
cpio -i -F ramdisk.cpio
5. Modify the mount point of data and sd-ext
- File fstab:
+ Find the line
Code:
/data yaffs2 userdata
, and change to
Code:
/data ext4 /dev/block/mmcblk0p2
- File init.semc.rc
+ Find the line
Code:
mount yaffs2 [email protected] /data nosuid nodev
and change to
Code:
mount ext4 /dev/block/mmcblk0p2 /data nosuid nodev
- File recovery.fstab:
+ Find the line
Code:
/data yaffs2 userdata
and change to
Code:
/data ext4 /dev/block/mmcblk0p2
6. Repack the ramdisk
If you extracted from ramdisk.cpio file, you need to pack to ramdisk.cpio first
Code:
find . | cpio -o -H newc -O <target path>/ramdisk.cpio
Then repack you ramdisk: At the ramdisk folder:
Code:
mkbootfs <ramdisk folder> | gzip > <target path>/boot.img-ramdisk-new.gz
7. Repack boot.img
Code:
mkbootimg --kernel <path to>/boot.img-zImage --ramdisk <path to>/boot.img-ramdisk-new.gz -o <path to>/boot_new.img --base `cat <path to>/boot.img-base`
8. Flash boot_new.img
9. Enter CWM, wipe phone and restore from your backup
--> Done
Thanks for the info. Or you can go on cmw and create sd-ext from there.
Will it Work with an ext3 partition too?
Gesendet von meinem LT15i
lol
i dont understand at all...
ARip Kenpachi said:
i dont understand at all...
Click to expand...
Click to collapse
It's because the title is wrong.. it's not the "easy way" .. it's a little bit more 'medium - adv user' way..
If it's so hard for you, I think it's better u to search 'script/app' for doing this.
There's a lot available like link2sd, cronmod script, etc
Excellent, it worked on Vengeance Kernel, actually that was the only kernel that I was able to extract the ramdisk.
Lupus kernel has is ramdisk in another format (not gzip), and KTG is in a elf file.
The boot took a little bit longer, but i think is more stable than using init.d scripts.
EDIT: Make the backup from an old CWM (like the one on the recoveryARC.img file), newer versions will check for the correct filesystem, and as we are changing it, It will not work. For restore, use any version of CWM (the one included on Vengeance works great).
Also, if you have an LT15i, backup your /system/vendor folder, otherwise, it will be not longer available (and a lot of apps will crash), I copied it into the data folder and made a symlink into /system/vendor (and as your data folder will be bigger, thats no issue).
I can't manage to do the trick on my Arc S with DoomKernel_v22. When I flash the modified .img the phone doesn't start and i can't go into CWM.
I have two partitions on SD, the second one is the ext4 i want to use.
These are the files extracted from Doomkernel:
fstab:
Code:
/data yaffs2 userdata
/cache yaffs2 cache
init.semc.rc:
Code:
on fs
# mount mtd partitions
# Mount /system rw first to give the filesystem a chance to save a checkpoint
mount yaffs2 [email protected] /system
mount yaffs2 [email protected] /system rw remount
mount yaffs2 [email protected] /data nosuid nodev
mount yaffs2 [email protected] /cache nosuid nodev
recovery.fstab:
Code:
/cache yaffs2 cache
/data yaffs2 userdata
/system yaffs2 system
/sdcard vfat /dev/block/mmcblk0p1
/sd-ext auto /dev/block/mmcblk0p2
Can anyone help me please?

[HACK] Grow your data partition

>>> Please note that Vashiru reworked this guide for reliability and alternate values, so I recommend you check his various posts in this thread starting with this one. <<<
Click to expand...
Click to collapse
THE PROBLEM
As many of us have noticed, it is fairly easy to get an "Out of space" message when installing apps on our phones because, for some weird reason, Oppo decided that the storage part of the device should linger in the dark ages, when /userdata and /sdcard were separate partitions and you only had 2GB of data storage, even if your phone was a 32GB model.
Now, imagine that you are running KitKat and would like to try ART. This may be a bad idea as, if your data partition is more than 30% full, you will find that while converting your apps to this new format, Android will run out of space.
At OppoForums, a few bright people started looking into the issue and, of course, there is a way to improve the situation.
WARNING!
If you follow the steps below correctly, you should not run in any trouble. If you do not, however, you may end up spending much more time fixing your phone.
FIRST, THE THANKS SECTION
Anders tinkered with his device’s partition table until he got to where he had grown the /userdata partition to something useable. Yes, it’s some people’s definition of “play”
Jousa11 is the first person trying to put a guide together explaining the steps to reproduce Anders’ work. WARNING: I did no get to see said guide as Jousa quickly deleted it due to the risks involved. So, take that in account!
Rockman for providing the last resort rescue tools in case you brick your phone
Lucky for providing the WiFi fix
Please let me know if you are not on this list and I forgot to give you credit!
YOU WILL NEED
The hardware:
An Oppo Find5 phone(!)
A computer (Windows/Linux/Mac) with adb installed and working
A USB cable
On your computer:
adb
[Optional] fastboot
On your phone (SDCard):
parted + mke2fs + tune2fs
mmcblk0p21_persist_ext4.img
openrecovery-twrp-2.6.3.0-find5-TP-patch.img
[Optional] gdisk
You will use parted to work on your partition table; mke2fs and tune2fs to create ext4 filesystems on some of these partitions (parted does not know how to create ext4 partitions)
mmcblk0p21_persist_ext4.img is an image that you need to restore your /persist partition and avoid issues such as non-working WiFi.
openrecovery-twrp-2.6.3.0-find5-TP-patch.img is a patched recovery image. I know: you already have a recovery image if you are going through these steps. However, we are going to wipe it so you want to install this guy before rebooting. Note that if you forget, you can always flash it later using fastboot.
On your computer:
adb to access your phone recovery, push files to SDCard, reboot...
[Optional] fastboot. You will only need fastboot if you mess up your recovery partition.
WHAT IF SOMETHING GOES AWFULLY WRONG?
You may “brick” your phone. Apparently it’s near impossible to hard brick your Find5, though. See below.
First, Anders recommends making a backup of your partition table. I didn’t because I felt that if I messed something up, it would be a partitions’ content rather than the partition table but that’s not the wisest approach.
Furthermore, if you are really worried about what stilly error your fat fingers will cause (I know I should be!) you can also backup your partitions.
Backing up your partition table:
On your phone:
Code:
gdisk -b /sdcard/gpt.bin /dev/block/mmcblk0
Backing up a single partition:
On your phone:
Code:
dd if=/dev/block/mmcblk0p<partition id> of=/sdcard/backup-<partition id>.bin
On your computer:
Code:
adb pull /sdcard/gpt.bin
adb pull /sdcard/backup-<partition id>.bin
LAST RESORT
OK. So, you've bricked your phone. Now what?
First, you will need Windows. So if you're on a Mac or Linux and have no access to a Windows machine/VM, er..don't brick your phone.
- Download drivers and tools
- Download and follow the instructions
READY ? LET'S GET STARTED
>>>>>>>>>>>> First, Download The Files <<<<<<<<<<<<
Then...
On your computer:
UPDATE As dixxa pointed out, mke2fs and tune2fs may already be present on your device. It was not the case for me but you should check first; it seems like a good idea to use existing binaries.
Code:
adb reboot recovery
adb push parted /sbin
adb push mke2fs /sbin
adb push tune2fs /sbin
On your phone:
Code:
chmod 755 /sbin/parted /sbin/mke2fs /sbin/tune2fs
umount /cache
umount /sdcard
umount /emmc
umount /data
parted /dev/block/mmcblk0
You are now in the parted shell.
CAREFUL! Do not delete any partition below 20 or you will enter "Big Oops" territory. I recommend typing carefully and, yes, staying away from copy/paste operations that may swallow a character like, say, the '2' in '20'
Note that the size value I am using here is '4GB' for /userdata (rather than 2GB). I guess you could make /userdata bigger than 4GB, in which case you would have to recompute all the offsets in the commands below(!)
Code:
# rm sdcard
rm 29
# 28 thru 23 are reserved
rm 28
rm 27
rm 26
rm 25
# rm recovery
rm 24
# rm misc
rm 23
# rm cache
rm 22
# rm persist
rm 21
# rm data/emmc
rm 20
# now, re-create partitions but data is bigger
mkpart primary 1325 5421
name 20 userdata
mkpart primary 5421 5430
name 21 persist
mkpart primary 5430 5967
name 22 cache
mkpart primary 5967 5968
name 23 misc
mkpart primary 5968 5979
name 24 recovery
mkpart primary 5979 6012
name 25 reserve1
mkpart primary 6012 6019
name 26 reserve2
mkpart primary 6019 6028
name 27 reserve3
mkpart primary 6028 6062
name 28 reserve4
mkpart primary 6062MB 100%
name 29 sdcard
# exit parted shell
q
Let's create a file system on the partitions that require one. Note that I am formatting the SDCard using VFAT as, yes, EXT4 is a better FS, but it is also incompatible with Oppo's ROM and some apps may not require the proper permissions etc.
Code:
# Notes:
# -m 0: no reserved blocks
# -c 0: no max mount count
# -C -1: no mount count
# -i -1: max_int interval between checks
mke2fs -t ext4 -m 0 -L userdata /dev/block/mmcblk0p20
tune2fs -c 0 -i -1 -C -1 /dev/block/mmcblk0p20
mke2fs -t ext4 -m 0 -L persist /dev/block/mmcblk0p21
tune2fs -c 0 -i -1 -C -1 /dev/block/mmcblk0p21
mke2fs -t ext4 -m 0 -L cache /dev/block/mmcblk0p22
tune2fs -c 0 -i -1 -C -1 /dev/block/mmcblk0p22
# Hey look it’s an ext4 SDCard!
mke2fs -t ext4 -m 0 -L sdcard /dev/block/mmcblk0p29
tune2fs -c 0 -i -1 -C -1 /dev/block/mmcblk0p29
# Actually to avoid errors like unable to write to root of sdcard:
mkdosfs -n sdcard -F 32 /dev/block/mmcblk0p29
mount -t vfat /dev/block/mmcblk0p29 /sdcard
At this point, we have clobbered the /persist partition and this could cause issues as mentioned earlier. Let's restore it.
Code:
# Restore /persist partition
mount -t ext4 /dev/block/mmcblk0p29 /sdcard
# On computer
adb push mmcblk0p21_persist_ext4.img /sdcard/
# On phone
dd if=mmcblk0p21_persist_ext4.img of=/dev/block/mmcblk0p21
IMPORTANT! Flash your recovery partition now. If you wait until after rebooting, you will need to use fastboot instead.
Code:
# Recovery partition: on computer
adb push openrecovery-twrp-2.6.3.0-find5-TP-patch.img /sdcard/
# On phone
dd if=openrecovery-twrp-2.6.3.0-find5-TP-patch.img of=/dev/block/mmcblk0p24
Admire your work
Code:
parted /dev/block/mmcblk0 print
Reboot into your new recovery and install your favorite ROM
FAQ
Q: Is this dangerous?
A: Yes. Yes, it is.
Q: Any tip?
A: Yes. Follow these instructions carefully and if something wrong happens, unless you know what you are doing, leave your device alone and come here to ask for help.
Q: Can I hold you responsible for any damage to my phone/etc?
A: As usual, the answer is 'No'
Q: I found an error in your write-up!
A: Please let me know immediately.
-Chris.
You should probably use the latest TWRP 2.6.3.1 found here: http://techerrata.com/file/twrp2/find5/openrecovery-twrp-2.6.3.1-find5.img
Looks good to me. Just be very carefully doing this.
Sent from my Find 5 using xda app-developers app
gdisk -b /sdcard/gpt.bin /dev/block/mmcblk0
those commands need to be typed in recovery even that one ?
Yes although I imagine this particular command should also work when booting system.
Sent from my Find 5 using Tapatalk
This thread is fine the only problem here is with those 2 binaries: mke2fs and tune2fs
You don't need to push them or chmod them since they are already in the recovery
Except that that thread is perfect.
Since we're at toying with partition, can't we merge the partitions in some way ?
Just wondering is there any way to build a script to do this in an automated way thus avoiding user errors and typos?
There is a thread on the oppo forums
http://www.oppoforums.com/threads/guide-resizing-internal-storage-on-find-5-32gb.8361/
Hello everyone,
is the guide for the 32 or 16 gb model?
I have 16 gb Oppo find 5.
Thanks.
PS: what "on your phone" is supposed to mean"?
Click to expand...
Click to collapse
If you don't know what does that mean don't do it you'll screw your phone.
hi
Please would you make something like this for oppo find 7a x9006?
thanks
Anyone willing to recompute all the offsets dor just one 16gb partition?
Scribed henceforth from thy G pad.
Hi all, I am trying to do this mod and I am half way through it with a problem
I am stuck on the new file system, I cannot use mke2fs or tune2fs, i get
Code:
mke2fs: not found
like it doesn't even exist, but it does I can see it. I get the same error for tune2fs. but parted and gdisk work fine.
Yes I did push them and chmod 755 them.. and I have tried running it from the /sbin directory.
Help!
Hello!
I'm getting the same error over and over again creating /dev/block/mmcblk0p21 to /dev/block/mmcblk0p22:
tune2fs -c 0 -i -1 -C -1 /dev/block/mmcblk0p21
"Bad magic number in super-block while trying to open /dev/block/mmcblk0p21"
"Couldn't find valid filesystem superblock"
So i can't create a file system on the created partitions. I have been looking everywhere for an answer. Somebody have an idea?
U should just wait. Andrew dodd found a way to make find7a have unified partition and he claims he can make it work on find5 as well. Let's give him a bit to figure it out tho.
Scribed henceforth from thy G pad.
Gdisk not working...
Ok guys sort of a noob here... Firstly, totally appreciate what you guys are doing here... I wants it bad, thass why i'm here.
So far... I have i have done...
"adb reboot recovery"
"adb push gdisk /sbin"
I figured that's how you are supposed to install it ... hope i'm not wrong, but i guess it pushed through fine
But after rebooting to system in TWRP , i opened terminal emulator and when i use the command
"gdisk -b /sdcard/gpt.bin /dev/block/mmcblk0"
I get ...
"/system/bin/sh: gdisk: not found"
now i'm too scared to proceed without backing up the partition tables... so please help...
edit - FYI , i'm running the last build of Asylum Carbon... should i just go back to latest oopo stable stock rom and then root my device again and then try all this again... would that help... ???
Directly from Andrew Dodds g+ " IT HAS BEGUN.
The first phase of Find 7a/7s LVM testing is here.* See linked post for details.* (Sorry to disappoint, but the first phase is "make sure we don't break existing configurations")
Once this phase is complete, the remaining list is:
Fix up the remaining TWRP issues (make RECOVERY_SDCARD_ON_DATA runtime instead of compile-time)
Make user-friendly conversion processes
Once things are solid on Find 7, I'll work on Find 5 and N1."
Stay thirsty my friends. Good things ahead
Sent from my A0001 using Tapatalk
Does this work for the 16gb model?
Can someone help please?
I'm trying to do this, but after enter in parted [parted /dev/block/mmcblk0] when i try to do "rm 29", i get "can't remove 29: no such file or directory
I'm doing the "on your phone" commands in TWRP command line., is that correct?
I'm running stable colorOS 1.0.9i
Finally I finish the process.
My notes:
Goal:
Keep my current system intact (stable colorOS 1.0.9i , because i have no patience to format, install a new ROM and reinstall/recofigure everything
So I backup everything on phone with TWRP and I push sdcard content (wich include the system backup i made) with ADB
1 - If I push mke2fs and tune2fs IT WILL NOT WORK. I flash the last find 5 recovery (openrecovery-twrp-2.8.1.0-find5.img) and I dont push or chmod anyting, parted, mke2fs, tune2fs are all already in the recover and that's the only way I could run mke2fs and tune2fs
edit: 1.5 - The phone commands had to be enter via ADB shell. In TWRP command line, after you enter in parted it will not accept commands.
2 - To "rm 29", i had to "umount /dev/block/mmcblk0", otherwise "rm 29" fail due to partition in use
3 - after this instruction:
mount -t vfat /dev/block/mmcblk0p29 /sdcard
(the last one on the 4 block of code)
We have this:
# Restore /persist partition
mount -t ext4 /dev/block/mmcblk0p29 /sdcard
This instruction was the only one that give me a error, so I move to the next ones.
The error was that the partition was busy, what makes senses because in the last instruction we mount the same partition on the same folder but with different file system!!??
So I move to the next instruction. I have no idea if it's a instructions mistake but it looks like, because it says "# Restore /persist partition" but the command has nothing to do with /persist
4 - FINISH
5 - Reboot in recovery. Push sdcard backup to /sdcard. restore system backup with TWRP restore
Voila, my phone exactly as before but with 3,76GB for APPS. Finally!!! The "running out of space" message on a flagship quad-core 2GB RAM phone!!!!!!?????? Was driving me CRAZYYYYY
Thanks Fickx for the up to date information, I just did my re-partition successfully, here's what I did:
- Use Rashr update the recovery to twrp-2.8.1.0
- reboot into recovery
- connect to PC (Make sure adb works, "adb devices")
- on PC:
> adb shell
> umount /cache
> umount /sdcard
> umount /emmc
> umount /data
> umount /dev/block/mmcblk0p29
> parted /dev/block/mmcblk0
> rm 29
>...
> rm 20
> mkpart primary 1325 5421
> name 20 userdata
> ...
> name 29 sdcard
> q
> mke2fs ...
> ...
> mount -t -vfat /dev/block/mmcblk0p29 /sdcard
Open another PC command terminal
> adb push mmcblk0p21_persist_ext4.img /sdcard/
> adb push openrecovery-twrp-2.8.1.0-find5.img /sdcard/
Back to original terminal in "adb shell".
> dd if=/sdcard/mmcblk0p21_persist_ext4.img of=/dev/block/mmcblk0p21
> dd if=/sdcard/openrecovery-twrp-2.8.1.0-find5.img of=/dev/block/mmcblk0p24
> exit
> adb reboot recovery
Flash the rom.

Help Needed Modifying System Image

Hello XDA, I was attempting to do some experimentation with what I could do on the device via modifying init.rc files and the like. Rather than building and flashing a custom ROM for each run which is time consuming I thought I could just mess with the existing system images.
What I was hoping would work:
1. Download the October 007 (patch) stock binaries from Google
2. Extract the flame_xxxxx.zip image file
3. Convert the sparse system image file to a raw image file
- $ simg2img system.img system.raw
4. Mount the ext2 filesystem to a loopback device
- $ mount -o loop -t ext2 system.raw temp_dir
5. Edit the init file (e.g. init.rc) and save it
6. Unmount the ext2 filesystem
7. Create sparse system image
- Still don't quite know how to do this
8. Flash the sparse image from fastboot
- $ fastboot flash system system.img
So my question to the community at large is, is this track of work even logically correct. If so, how does one do it?
I have been trying to run these steps against image-flame-qd1a.190821.007.zip
My machine is running Ubuntu 19.10
For example Step 4 (mounting the ext2 system is failing for me)
Code:
$ losetup --list
....
/dev/loop8 0 0 1 1 /path/system.raw 0 512
....
$ sudo mount /dev/loop8 sys_mount
mount: /pathsys_mount: wrong fs type, bad option, bad superblock on /dev/loop8, missing codepage or helper program, or other error.
Also not working for Step 4
Code:
$ file system.raw
system.raw: Linux rev 1.0 ext2 filesystem data, UUID=4729639d-b5f2-5cc1-a120-9ac5f788683c (extents) (large files) (huge files)
$ sudo mount -o loop -t ext2 system.raw sys_mount
mount: /pathsys_mount: wrong fs type, bad option, bad superblock on /dev/loop8, missing codepage or helper program, or other error.
Thanks for the help.
I have since built my own AOSP build and have the same issue in that I can't mount the resulting system.img file from the AOSP build either.
Not sure if that matters or not, but I found it odd.

Categories

Resources