[Guide]Resizing Partitions on Android (Redmi device) - Xiaomi Redmi 3s Guides, News, & Discussion

4 this kind of guys x)
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Code:
Warning:
Your device will never boot :D
Does this enough?
Ok jk but consider its possible
So don't blame me,
not responsible for anything
Trick:
Read 2nd Post First
(if u think necessary)(i would)
Why ?? :
Cuz u want to increase/decrease size on internal storage/internal sd card/nand/emmc.
So u can save Avengers 1080p in dual audio
I.e. default internal storage will increase from 24.x GB to 26.x GB
Sounds cool ?
Go ahead
Tools required:
0. Nandorid Backup ,
back up everything every way you can/know
1. Rooted Phone
2. Custom Recovery with ADB Sideload
3. Minimal ADB and Fastboot Tools(for Computer)
4 parted utilities.zip (download from below)
5. Computer should recognise device for that install necessary drive
6. brain, commen sense, patients,calm etc.
---> PROCEDURE/STEPS
(will add screen shot, Rewrite again )
1.
Extract 'parted' from zip copy to "/system/bin"
(if can't Open Es File explorer app>find & tape Root explorer option>mount r/w option> mount system to r/w (read/write allow)
2.
Put phone in TWRP Recovery
3.
Connect to computer
On command line interface
(Windows>Run>CMD>enter)
#commands:
adb shell
su
parted /dev/block/mmcblk0
you will see the following screen
4.
Now to see the partitions and their partition numer use the following command
print
It will output a screen like follows
From the list above we can see partition number, the start position, the end position and the type of partition
Now from the List we need to figure out what partitions we need to remove and remake, and since we are majorly concerned about the Userdata and system partition, we will be playing around with those partitions only. But from the screenshot above you can see that Between the system and the userdata partition there is the cache partition.
To avoid any problems further. i would suggest you take a screenshot of this list .
5
Now Enlisting the partitions that we would have to remove inorder to resize them, they are:-
partition no. 27 i.e. system
partition no. 28 i.e cache
partition no. 29 i.e. userdata
In case you are using a device that has 2 system partitions (For eg. MI3) and you wanna reduce system2 and increase system1 you will need to delete only those 2 partitions
So now going further we will now remove the partitions using the following commands
rm 27
The above command will remove the partition no. 27 i.e the system partition
rm 28
This will remove the partition no. 28 i.e cache
rm 29
This will remove the partition no. 29 i.e. userdata
At this point of time you have lost all the data on your internal storage, system and cache partition. that means your device wont boot anymore except in recovery (which we are already in )
6.
Now that we have removed the partitions, we have raw space with us, which we would allocate to the three partitions that we removed, as per our choice.
To do that, we use the following commands
mkpartfs primary ext2 336 1250
mkpartfs primary ext2 1250 1653
mkpartfs primary ext2 1653 7818
336 is the start position of the partition and 1250 is the end position of the paritition.
since the partitions we removed started at 336 and ended at 7818, for my device, we would be able to play around only between these two numbers. i.e 336 and 7818
The first parition we made here is numbered 27 by default and will be of the size (1250-336 = 914) MBs
The second partition we made is numbered 28 and will be of the size 403 MB. (This is the cache partition and since I did not want to change the size i kept it the same)
The third partition we made is numbered 29 and will be of the size (7818-1653 = 6165) MB
The Important thing we need to note here is that the partition Number should not change as this could cause problems later on. i.e., considering my case the system parition should be 27, cache should be 28 and userdata should be 29.
7.
Now we will name these partitions using the following commands
name 27 system
name 28 cache
name 29 userdata
8.
Now punch the following command
quit
This will make you come out of parted utility. so that we can perform the next set of commands
Now we need to convert the partitions from ext2 to ext4 using the following commands
**// For System Partition //**
tune2fs -j /dev/block/mmcblk0p27
e2fsck -fDp /dev/block/mmcblk0p27
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p27
e2fsck -fDp /dev/block/mmcblk0p27
**// **
**// For cache Partition //**
tune2fs -j /dev/block/mmcblk0p28
e2fsck -fDp /dev/block/mmcblk0p28
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p28
e2fsck -fDp /dev/block/mmcblk0p28
**// **
**// For userdata Partition //**
tune2fs -j /dev/block/mmcblk0p29
e2fsck -fDp /dev/block/mmcblk0p29
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p29
e2fsck -fDp /dev/block/mmcblk0p29
**// **
9.
Now we have changed the type of the 3 partitions that we created from ext2 to ext4 and we are ready to go
Now we will enter the parted utility again and check to see if the partitions are made properly or not.
parted /dev/block/mmcblk0
print
As we can see in the screenshot. The system partition is now 914 MB and the userdata partition is no 6165 MB
Now punch the command
quit
exit
exit
Yes you need to exit two times.. first to come out of super user and second to come out of ADB shell
10.
Now Once the repartitioning is done
you need to flash your ROM
(MIUI /Lineage/RR/Viper/Mokee etc)
Now exit sideload in the TWRP and goto Install and select the Rom package and flash it.
Reboot and you should be done!
CREDITS, Thanks :
https://iwf1.com/how-to-re-partition-your-android-tablet-or-smartphone-all-options-included-change-size-fs-type-etc
https://forum.xda-developers.com/crossdevice-dev/android-one-general/guide-repartition-internal-storage-to-t3292159
http://en.miui.com/thread-183258-1-1.html

Reserved
sry for being so direct
here explanation for things that might didn't understood
->
Note: as much as I’d like to, I do not currently possess the resources to grant readers technical support. The guide itself, in the vast majority of cases should be sufficient help. For any individual issue please refer to online forums which are meant for that purpose.
Why Re-Partition?
If you’re here out of curiosity or any other reason than necessity, you may wonder: “why would anyone want to repartition a smartphone / tablet?”.
To answer, each person probably has their own reason, a couple of such I can think of are:
In the case of an upgrade, when there’s not enough space on one partition but others has aplenty.
When you don’t have enough space to install more apps – since your data partition is full – so you want to resize that partition.
Of course, some cases can be resolved via a more simple solution, however, if you want to deal with the problem directly and not just bypassing it – repartition is perhaps the best way to go.
In order to re-partition your device, basically, these are the steps you’ll need to make:
1. Connect your device to your PC.
2. Open up a command shell, on Windows you’d probably use CMD / PowerShell, on Mac / Linux – Terminal.
2-a. Reboot into recovery mode. (Optional, depends on the partition you plan to modify)
3. Use ADB to connect to your device.
4. Launch a partitioning software.
5. Start partitioning.
6. Reinstall any required system file in case you’ve deleted those and afterwards you may exit the shell and reboot your device.
Explaining The Steps
1. We use another machine, in this case our PC, in order to re-partition Android, because we want to have access to our Android system just in case something goes wrong during the partitioning, and also, since Android system cannot be run and resized at the same time.
2. This step is rather self explanatory. We must use a flexible tool that will assist us re-partitioning.
2-a. If you wish to modify any partition other than the recovery partition, I recommend booting into recovery mode in order to do so.
Being inside recovery mode wouldn’t interfere with the process as you may delete the system partition and its files. Furthermore, it might become handy in case you’ll need to reinstall Android system.
3. ADB is an official Android developers tool and it also happens to be the most suitable tool for the job at the moment.
5.
Since this step depends on what you’re actually intending to do with your device – it doesn’t say much, it is an open step, open for your decisions that is.
By typing the help command of your partitioning tool you’ll get a list of the options available to you. For example, these are a few of the options you’ll see in parted:
rm NUMBER – will delete a partition
mkpart – will create a partition
unit UNIT – will set unit type, for example “unit b” will set parted to use bytes, “unit gb” for Giga bytes, etc… (Tip: use bytes for maximum accuracy).
name NUMBER NAME – lets you name the partition (upon making any changes, don’t forget to name the partitions properly).
q – quit parted.
Important Things To Note:
fdisk executes your commands only when changes are saved whereas Parted executes them instantly.
fdisk may not fully support GPT partition table, thus in case yours is GPT, it’s recommended to use Parted instead.
6.
* Tip: If you’re unsure about your device partition names, you can use a command that shows them: cat /proc/partitions.
As you can see, there’s mmcblk0 – which is the main block where all the partitions are stored.
And there are 12 partitions in total which uses the name format “mmcblk0” plus “p” and a number that represent them, such as: mmcblk0p1, mmcblk0p2, etc…
Blocks lie inside /dev directory in Linux (yes, Android is a variation of Linux). We will use the block we’ve found in order to re-partition the device.
A short explanation regarding the relevant partitions:
Partition number 9 labeled FACTORYFS – is the “system” partition where all the operating system files are stored in.
Number 10 – DATAFS – is the “data” partition where all applications usually save their data.
Number 11 – UMS (USB Mass Storage) – is the internal storage partition where all the stuff such as: pictures, videos, etc, are stored in.
To resize those, you’ll have to delete them all and then assign different sizes – this is where a backup might become handy (I recommend copying all the files to your computer prior to erasing any partition).
After erasing and re-partitioning the available space, you should re-label the partitions with the same names (for compatibility sake) and create file systems (I prefer using ext4, however, if your device came with other specific file systems, it might be a good idea to stick to those).
So, how do we do it?
Here’s the sequence of commands with a following explanation:
(parted) rm 9
(parted) rm 10
(parted) rm 11
Will delete FACTORYFS, DATAFS and UMS respectively.
************
From another thread different info
By default, Parted uses MB as the storage unit. To prevent possible unused space after repartitioning, we’ll use sectors as a unit instead.
Type
unit s
This’ll change to sectors.
Type
print
It’ll give a warning, just type
i
Then:
print free
At the top, you’ll see that the sector size is written. Write this number down somewhere. For my Android One 4GB, the sector size is 512 bytes.
Now, you need to understand what the list means. Each horizontal row shows the details of a partition.
The 1st column shows the partition number.
The 2nd column shows the start offset of that partition. That means that the partition starts at the location mentioned.
The 3rd column shows where the partition ends. Notice that each partition starts exactly 1 sector after the previous one ends.
The 4th column is obviously the size of the partition.
The 5th column is the file system used by the partition. If nothing is written in this column, that means that it’s a binary partition.
The 6th column is the partition name.
You’ll see that the sizes in that list are weird. They’re not in any standard unit you might know. That’s because we used sectors instead of megabytes. The ‘s’ after each number indicates that it’s in sectors. (You can use the default MB unit (1MB=1000 KB. 1KB=1000bytes), or the MiB unit (1MiB=1024 KiB), but that just might leave 1 or 2 MB of space unused. So, I’m using sectors).
Remember that 1 sector = 512 bytes for my phone.
There’s some free space at the top and bottom of the list. Leave that free space there. Do not make partitions using those.
To convert sectors to MiB or KiB:
1s = 512bytes (Use the sector size you wrote down previously for this step, it might not be 512 bytes for you)
1024 bytes = 1 KiB
1024 KiB = 1 MiB
1024 MiB = 1GiB
So, 4833280s = (4833280 x 512) B = 2474639360 B
= (2474639360 / 1024) KiB = 2416640 KiB
= (2416640 /1024) MiB = 2360 MiB
= (2360 / 1024) GiB = 2.30 GiB
We’ll use another terminal window with sizes in MiB now. So open another Parted prompt in a new terminal / command prompt window, but instead of
unit s,
this time, write
unit MiB
Type “print”, “i”, and “print free” again
Look at my 11th partition. Its size is 8MiB. I know that this logo partition doesn’t need more than 2 MiB. So, I’ll make it smaller.
When you make partitions smaller, all the data inside will be lost. So, we need to back up the partitions first.
Open a 3rd terminal window. Type
adb shell dd if=/dev/block/mmcblk0p11 of=/microSD/p11
The “dd” command copies bytes from the “if=” location, to the “of=” location. The internal storage is /dev/block/mmcblk0. The “p11” after that refers to the partition we are backing up. Notice that in the Parted list, “logo” has a partition number of “11”. So the general command to back up partitions is
adb shell dd if=/dev/block/mmcblk0p<partition_number> of=/microSD/p<partition_number>
From recovery, unmount all partitions except microSD and oem. Then back up partitions 11, and 13 from PC. We will copy the files from OEM instead of using dd. So type
adb shell mkdir /microSD/oem
adb shell cp –a /oem/ /microSD/oem
Go to /microSD/oem/oem/app with TWRP’s file manager, and delete everything there.
Open the 1st terminal with sizes in sectors.
Type
rm 11
This will delete the oem partition. Type
print free
.

Abhijeet Rajgor said:
sry for being so direct
here explanation for things that might didn't understood
->
Note: as much as I’d like to, I do not currently possess the resources to grant readers technical support. The guide itself, in the vast majority of cases should be sufficient help. For any individual issue please refer to online forums which are meant for that purpose.
Why Re-Partition?
If you’re here out of curiosity or any other reason than necessity, you may wonder: “why would anyone want to repartition a smartphone / tablet?”.
To answer, each person probably has their own reason, a couple of such I can think of are:
In the case of an upgrade, when there’s not enough space on one partition but others has aplenty.
When you don’t have enough space to install more apps – since your data partition is full – so you want to resize that partition.
Of course, some cases can be resolved via a more simple solution, however, if you want to deal with the problem directly and not just bypassing it – repartition is perhaps the best way to go.
Click to expand...
Click to collapse
Hey, Can you tell me the partition sizes for different partitions i.e. system, data, cache.... for the attached zip file.

incomplete guide
Bro go to link in the post guide is yet incomplete , I'll rewrite again with more specific n Direct to point
Thanks

Abhijeet Rajgor said:
Bro go to link in the post guide is yet incomplete , I'll rewrite again with more specific n Direct to point
Thanks
Click to expand...
Click to collapse
Do you know how we can delete the /cust partition and include it into the system?

I don't know
bekcicandrej said:
Do you know how we can delete the /cust partition and include it into the system?
Click to expand...
Click to collapse
Am yet working on my device itself yet didn't tried on Redmi 3s,

Cwm recovery for my Alcatel

Related

[DEV] "Root easily your Gen8 device" (developers only thread!)

This thread is for discussing features and improvements of this rooting method
For questions and problems read the [HOWTO] thread
Project site online: archos-gen8-sde-rooting
wdl1908 said:
chulri what about creating a 1Gb file on the /mnt/storage and formatting that as ext3 copying all the original /data to it and then mounting that with a loop interface on /data.
Click to expand...
Click to collapse
That's what I tried previously (before the /data thing), but I had no luck and it's a big issue because android tries to unmount /mnt/storage when you connect your archos device to the computer but that's not possible because the lock of the mounted rw-file makes umounting of /mnt/storage impossible and I have to mount the rw-file before /mnt/storage gets mounted, that's another issue which must be resolved.
chulri said:
That's what I tried previously (before the /data thing), but I had no luck and it's a big issue because android tries to unmount /mnt/storage when you connect your archos device to the computer but that's not possible because the lock of the mounted rw-file makes umounting of /mnt/storage impossible and I have to mount the rw-file before /mnt/storage gets mounted, that's another issue which must be resolved.
Click to expand...
Click to collapse
Yeah I came to the same conclusion as you, that what I suggested would bork the usb mount option to the PC.
Another thing I realized is that the official firmware upgrades could probably update files on the data partition. So moving the whole partition is not an option as that would break the upgrade process.
I've been looking at splitting the storage partition in several parts with parted I found an arm binary at http://plugapps.com/arm/ maybe these can be included in the initramfs.
I've also been analyzing my data partition
Code:
# du -s /data/*
112003 app
70503 dalvik-cache
40084 data
4622 test
The test directory is the place where the google market is installed via arctools or gappsinstaller.
So if it's possible to split the storage partition in several part we could move these dirs to it's own partition. This would not be optimal a good solution would be to move the complete data partition over but this needs a bit of thinking how to handle upgrades.
wdl1908 said:
So if it's possible to split the storage partition in several part we could move these dirs to it's own partition. This would not be optimal a good solution would be to move the complete data partition over but this needs a bit of thinking how to handle upgrades.
Click to expand...
Click to collapse
We could shrink the internal storage and append partition(s) after it. I'll give it a try, as long as my usb port is broken I have more time to focus on this here
chulri said:
We could shrink the internal storage and append partition(s) after it. I'll give it a try, as long as my usb port is broken I have more time to focus on this here
Click to expand...
Click to collapse
I've been trying to cross compile e2fsprogs and parted but I can't seem to get it.
Code:
e2fsprogs-1.41.14$ cross ./configure --host=arm-linux-uclibcgnueabi --build=i686-linux
Completes without errors but the make does not complete.
Code:
gen_uuid.c:(.text+0x418): undefined reference to `__aeabi_read_tp'
../../lib/libuuid.a(gen_uuid.o):gen_uuid.c:(.text+0x788): more undefined references to `__aeabi_read_tp' follow
I've tried to use the pre-compiled packages but it seems they don't work or i'm missing something.
fdisk is already included in initramfs thus no need for a parted binary.
edit: but to minimize data loss we need a resize2fs binary to resize the fat/ext3 partition
mkfs.ext3 (for the rw partition) and fsck are included too in the initramfs by archos
chulri said:
fdisk is already included in initramfs thus no need for a parted binary.
edit: but to minimize data loss we need a resize2fs binary to resize the fat/ext3 partition
mkfs.ext3 (for the rw partition) and fsck are included too in the initramfs by archos
Click to expand...
Click to collapse
Yep resize2fs is part of e2fsprogs. I've been working on the packages in the buildroot there seems to be a lot of errors but I finally succeeded in building the e2fsprogs package. but riseze2fs is not included. I need to check the config for that package maybe there is an option missing.
To get the buildroot working properly you need to copy the file
Code:
cp local/g8_arm/g8_arm.config .config
remove the line
Code:
package/apdf/Config.in
from .config.cmd
remove the line
Code:
depends on BR2_EXT_UCLIBC_VERSION_0_9_30_1
from toolchain/uClibc/Config.in
then in the buildroot directory execute
Code:
make menuconfig
enable the e2fsprogs in Package selection -> Harware handling
also you have to remove the --disable-resizer from the e2fsprogs.mk file else the resizer is not build.
I can't believe this build package from archos is very up-to-date it seems very strange that all these bugs are in there how where they ever building a good firmware.
but that builds dynamic linked binaries, doesn't it? but we need a static build, don't we?
chulri said:
but that builds dynamic linked binaries, doesn't it? but we need a static build, don't we?
Click to expand...
Click to collapse
Yeah stupid me it needs to run in the initramfs and that does not contain any libraries. Let me check to see if it's possible to link it statically.
and because it has to be statically linked, maybe we better just take the newest e2fsprogs (btw.: does this support FAT resizing?!) and compile it without that buildroot stuff (except for the toolchain of course, we need that to crosscompile)
chulri said:
and because it has to be statically linked, maybe we better just take the newest e2fsprogs (btw.: does this support FAT resizing?!) and compile it without that buildroot stuff (except for the toolchain of course, we need that to crosscompile)
Click to expand...
Click to collapse
Well I tried that and failed. That's why I wanted to do it in the buildroot. I'll try again later need to create a clean environment and do some diffs after I fixed all the stuff that's wrong.
wdl1908 said:
Well I tried that and failed. That's why I wanted to do it in the buildroot. I'll try again later need to create a clean environment and do some diffs after I fixed all the stuff that's wrong.
Click to expand...
Click to collapse
I think I got it.
Add
Code:
export BOARD=g8_arm
To your .bashrc then in the buildroot directory do a make it will take a while as it needs to build everything. This is just a precaution as i think the statically linked resize2fs needs some linking with uclib libraries.
After that is finished do a
Code:
make e2fsprogs LDFLAGS=-static
in the buildroot directory. You should find the resize2fs binary in the directory buildroot/project_build_arm/uclibc/root/sbin
Code:
$ file resize2fs
resize2fs: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
resize2fs does not resize vfat so we probably need parted and some extra utils
How to compile parted with buildroot.
I found the attached files on some forum
e3fsprogs.mk is a replacement for the existing file.
Config.in parted.mk and parted-001-ui.cast.patch need to be placed in the directory buildroot/package/parted
then execute the following commands
Code:
make e2fsprogs LDFLAGS=-static
make e2fsprogs-libs
make parted LDFLAGS=-static
you can find the statically linked parted in buildroot/build_arm/parted-2.3/parted
and this is what i tried.
Code:
# [B]parted /dev/block/mmcblk1[/B]
GNU Parted 2.3
Using /dev/block/mmcblk1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) [B]print[/B]
print
Model: MMC MMC08G (sd/mmc)
Disk /dev/block/mmcblk1: 7466MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 8192B 7466MB 7466MB primary fat32 lba
(parted) [B]resize[/B]
resize
WARNING: you are attempting to use ./parted to operate on (resize) a file system.
./parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use ./parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition number? [B]1[/B]
1
Start? [8192B]?
End? [7466MB]? [B]6466MB[/B]
6466MB
(parted) [B]check[/B]
check
WARNING: you are attempting to use ./parted to operate on (check) a file system.
./parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use ./parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition number? [B]1[/B]
1
(parted) [B]quit[/B]
quit
Information: You may need to update /etc/fstab.
#[B]fdisk /dev/block/mmcblk1[/B]
The number of cylinders for this disk is set to 227840.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): [B]p[/B]
Disk /dev/block/mmcblk1: 7465 MB, 7465861120 bytes
4 heads, 16 sectors/track, 227840 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/block/mmcblk1p1 1 197327 6314445+ c Win95 FAT32 (LBA)
Command (m for help): [B]n[/B]
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): [B]2[/B]
First cylinder (197327-227840, default 197327): Using default value 197327
Last cylinder or +size or +sizeM or +sizeK (197327-227840, default 227840): Using default value 227840
Command (m for help): [B]p[/B]
Disk /dev/block/mmcblk1: 7465 MB, 7465861120 bytes
4 heads, 16 sectors/track, 227840 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/block/mmcblk1p1 1 197327 6314445+ c Win95 FAT32 (LBA)
/dev/block/mmcblk1p2 197327 227840 976426+ 83 Linux
Command (m for help): [B]w[/B]
The partition table has been altered!
Calling ioctl() to re-read partition table
# [B]mkfs.ext3 -v -I 128 /dev/block/mmcblk1p2[/B]
mke2fs 1.40.9 (27-Apr-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
61184 inodes, 244106 blocks
12205 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=251658240
8 block groups
32768 blocks per group, 32768 fragments per group
7648 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# [B]tune2fs.static -c -1 -i 0 -m 1 /dev/block/mmcblk1p2[/B]
tune2fs 1.40.9 (27-Apr-2008)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
Setting reserved blocks percentage to 1% (2441 blocks)
I leave the scripting to you but with these utils it should work perfectly to resize the partition and create the second partition.
I copied the mkfs.ext3, fdisk and tune2fs.static from the recovery initramfs
I started hacking around and I came to the conclusion that it would be better to change the initramfs to mount /data from mmcblk1p2 if that partition exists and not if it's not existing and move the whole partition resizing, partition creating, partition deleting (if you wan't to revert without dataloss) and again resizing into an app. so the user has more control over what he's doing and see's if something is failing and not just get's a bootloop or some fancy log file.
edit: /data is mounted by /init.rc script, all of the above can be done by an app, incl. modifying /init.rc script. no need for any special initramfs, yay!
everybody who has +rw rooting installed will be able to use that app. I'm starting development...
edit2: project page online: http://code.google.com/p/archos-gen8-sde-rooting/
stay tuned
First test app: http://code.google.com/p/archos-gen8-sde-rooting/downloads/detail?name=AppDataResizer_v0.1.apk
Release notes:
initial test version v0.1:
- parted binary added
- test button lists partitions of mmcblk1 device
Click to expand...
Click to collapse
note: 250 GB version of the A70 is currently not supported.
chulri said:
First test app: http://code.google.com/p/archos-gen8-sde-rooting/downloads/detail?name=AppDataResizer_v0.1.apk
Release notes:
note: 250 GB version of the A70 is currently not supported.
Click to expand...
Click to collapse
Nice. Yep I was thinking about the transition from standard to custom and also came to the conclusion it had to be done outside the boot process scripts.
Edit: Should this app be installable via the usual way or should it be a system app? (Copied to /system/app)
What I was thinking was split the process in 3 steps.
Step1: Resize storage partition, Add new-data partition and format.
Step2: Copy existing /data to /new-data
Step3: Enable/Disable new-data
Maybe a step2a: To run after upgrade of firmware to check things that have changed.
The step1 requires a reboot as the partitioning should be done in the initramfs if you do that when apps are running you're going to have a hell of a time getting the storage partition unmounted (I know I had the problem when testing the parted binary)
Step2 can be done without any problem when storage is mounted and Step3 requires a reboot after the init.rc is changed.
wdl1908 said:
Nice. Yep I was thinking about the transition from standard to custom and also came to the conclusion it had to be done outside the boot process scripts.
Edit: Should this app be installable via the usual way or should it be a system app? (Copied to /system/app)
Click to expand...
Click to collapse
usual way (download and install) (or maybe I include it in the initramfs (like the Superuser.apk) and copy it to /system/app, but I don't like modifying initramfs any further, no need for 100 different versions )
wdl1908 said:
What I was thinking was split the process in 3 steps.
Step1: Resize storage partition, Add new-data partition and format.
Step2: Copy existing /data to /new-data
Step3: Enable/Disable new-data
Maybe a step2a: To run after upgrade of firmware to check things that have changed.
Click to expand...
Click to collapse
great, that were my plans too.
wdl1908 said:
The step1 requires a reboot as the partitioning should be done in the initramfs if you do that when apps are running you're going to have a hell of a time getting the storage partition unmounted (I know I had the problem when testing the parted binary)
Click to expand...
Click to collapse
No API to unmount /sdcard/? I think I got one: IMountService it's not a public API but android.os.FileUtils isn't public either and it's working great. I think IMountService is the API that the popup, which pops up when you connect your android device to the computer, uses. I think, no need to worry because android handles everything pretty well when you connect your device to the computer, isn't it?
wdl1908 said:
Step2 can be done without any problem when storage is mounted and Step3 requires a reboot after the init.rc is changed.
Click to expand...
Click to collapse
agreed
chulri said:
usual way (download and install) (or maybe I include it in the initramfs (like the Superuser.apk) and copy it to /system/app, but I don't like modifying initramfs any further, no need for 100 different versions )
Click to expand...
Click to collapse
I tried to install it but it won't install. logcat gives something like
Pckage chrulri.gen8.AppDataResizer has no certificated at entry res/layout/main.xml
Yep I agree no need for different versions of the initramfs
chulri said:
No API to unmount /sdcard/?
Click to expand...
Click to collapse
The problem is not only the mount of /mnt/storage if the user has used move2sd there are a lot of other mounts present that also uses that partition.
maybe the API will do. Needs to be tested.
One other remark. Let the AppDataResizer check for the unionfs directory so that you can be sure you'r running on the correct initramfs.

[Guide] Resizing LG G2 partition size

Resizing LG G2 partition size​Must have: Latest TWRP Recovery, ADB experience and gdisk for arm in attached zip.
Clean /system partition (unused apps, bloatware, garbage and so on...)
Backup everything important from /sdcard.
Reboot to TWRP and connect ADB (if "ADB devices" fails, check windows "Device Management" and install "Android Sooner Single ADB Interface" for your unrecognized phone).
In TWRP backup /system and /data and download /sdcard/TWRP folder via MTP to your PC.
Now it's ADB time:
Code:
[B]# check /system used space (in Mb) and remember it, as we should cut no more than "Available" space:[/B]
adb shell "mount /system"
adb shell "df -m /system"
[B]# un-mount partitions:[/B]
adb shell "umount /system"
adb shell "umount /data"
adb shell "umount /sdcard"
adb shell "umount /cache"
[B]# unzip gdisk in your ADB folder and install it:[/B]
adb push gdisk /sbin
adb shell "chmod 0755 /sbin/gdisk"
[B]# check partitions info:[/B]
adb shell "/sbin/gdisk -l /dev/block/mmcblk0" >gpt.txt
[B]# open new gpt.txt file in your ADB folder
# now you should recalculate your new partitions (30-36) size and position (in sectors)
# partition start-sector should be even, end-sector should be odd
# to make it simplier, use formula: (new size in MB) * 2048 + 1 = (new size in sectors)[/B]
Check my examples:
Code:
default (4.4.2 firmware):
30 819200 6488063 2.7 GiB 0700 system
31 6488064 7733247 608.0 MiB 0700 cache
32 7733248 7897087 80.0 MiB 0700 tombstones
33 7897088 7929855 16.0 MiB 0700 spare
34 7929856 8028159 48.0 MiB 0700 cust
35 8028160 60948479 25.2 GiB 0700 userdata
36 60948480 61071326 60.0 MiB 0700 grow
my mod v1:
(30) 800000 3526297 1.3 GiB system
(31) 3526298 3853977 160 MiB cache
(32) 3853978 3858073 2 MiB tombstones
(33) 3858074 3862169 2 MiB spare
(34) 3862170 3866265 2 MiB cust
(35) 3866266 61067229 27.2 GiB userdata
(36) 61067230 61071326 2 MiB grow
my_mod_v2:
(30) 800000 2897153 1 GiB system
(31) 2897154 3122433 110 MiB cache
(32) --- --- deleted tombstones
(33) --- --- deleted spare
(34) 3122434 3126531 2 MiB cust
(35) 3126532 61071326 27.6 GiB userdata
(36) --- --- deleted grow
Important! It's only mine D802 4.4.2 example. You should calculate your own values, because of your /system used size, /cust size for unlock, etc.
/spare and /grow partitions unused on our phones. /tombstones is obesolete since it mounts from /data, anyway.
After all checks and calculations, let's do the magic:
Code:
[B]# run gdisk:[/B]
adb shell
cd /sbin
gdisk /dev/block/mmcblk0
[B]# no real changes applied to the phone, before "w" command.
# if you did something wrong, exit by "q" command
# you can check youreself with "p" command (partition list with virtual changes you made).
# OK, let's delete our old partitons and create them anew:[/B]
"d" command > enter partition number (for all 30-36 partitons).
"n" command > enter partition number > start > end > code (start & end = new values in sectors, code = 0700)
"c" command > enter partition number > name (system, cache, etc.)
[B]# if all seems fine, and you're pretty sure of youreself:[/B]
"w" command > "Y" answer
[B]# there is no FS on new partitions, so format them:[/B]
mke2fs -t ext4 /dev/block/mmcblk0p30
mke2fs -t ext4 /dev/block/mmcblk0p31
mke2fs -t ext4 /dev/block/mmcblk0p34
mke2fs -t ext4 /dev/block/mmcblk0p35
[B]# there is no point to format others, because they have no fs by default.
# if using kernel with F2FS support (like Dorimanx), you can format some of them as F2FS:[/B]
mkfs.f2fs /dev/block/mmcblk0p35
[B]# to make TWRP realise, horrors we just did - reboot it:[/B]
reboot recovery
[B]# after reboot, we can optimize /userdata a bit (ext4 only), with this:[/B]
adb shell "tune2fs -m 0 /dev/block/platform/msm_sdcc.1/by-name/userdata"
[B]# bring backups from PC to /sdcard via MTP and restore them, as usual
# now you can reboot to your system with custom-sized partitions!
# P.S. If you notice your /sdcard permissions glith a bit after all this - flash "sdcard Fix Permissions script" from [URL="http://forum.xda-developers.com/showthread.php?t=2239421"]this[/URL] thread.[/B]
Good luck.
Awesome :good: this guide will help 16GB user like me to increase data/sdcard partition
Too bad I don't have pc to play around with....
so, stock, user-usable fresh after format on KK4.4 we have 24GB on the /sdcard part. Would we want to use this to go smaller? Would there be a benefit to that? Or would I want to use it to go larger, shrinking my /sdcard
I know it can go both ways, but which are people more interested in here?
rancur3p1c said:
I know it can go both ways, but which are people more interested in here?
Click to expand...
Click to collapse
Who knows? It's not that hard, it takes 5 minutes, it gets you + 1-3 Gib on the phone (without SD-Card support), and it's safe - coz we don't touch bootloader or recovery partitions... It's worth it.
THIS is just pure awesome
I've followed the guide and successfully added almost 2gb to userdata on my 16gb d802
This is my gpt for now
30 791568 4158721 1.6 GiB 0700 system
31 4158722 4306179 72.0 MiB 0700 cache
34 4306180 4310277 2.0 MiB 0700 cust
35 4310278 30777310 12.6 GiB 0700 userdata
And this is my aim, if i have time to do it again
30 791568 3937297 1.5 GiB 0700 system
31 3937298 3961875 12.0 MiB 0700 cache
34 3961876 3965973 2.0 MiB 0700 cust
35 3965974 30777310 12.7 GiB 0700 userdata
Also, i've notice this in the gpt.txt file
Total free space is 230360 sectors (112.5 MiB)
So can we get even more from our phone?
Hello everybody
first of all I ll thank you for your guide Resizing LG G2 partition size.
But no I have problems with installing a new rom. Everytime I enter twrp I get the message "Can't mount /system". So its impossible for me to install a new rom.
All partitions seems to be fine. gdisk works perfect without any errors.
My partition table looks like:
Code:
30 819200 3686401 1.4 GiB 0700 system
31 3686402 4014083 160.0 MiB 0700 cache
34 4014084 4034565 10.0 MiB 0700 cust
35 4034566 30777310 12.8 GiB 0700 userdata
If someone have any idea how I can solve this problem?
Thanks
Chris
I am thinking to try this tool, but I would like to know if flashing kdz will work in case I screw things up, or am I risking to permanently brick the phone?
Okay, going back to stock partitions will fix my problem and my system partition is again 2.7 GB
With the customised partitions i was unable to install neither Resurrection Remix Rom nor Google Edition 1.5. Both return an error in twrp.
Backfisch said:
Everytime I enter twrp I get the message "Can't mount /system". So its impossible for me to install a new rom.
All partitions seems to be fine. gdisk works perfect without any errors.
Click to expand...
Click to collapse
I have the same problem. Did you fix it by any chance?
Yes, going back to the stock values of the partition using the gdisk again.
Its also import to make sure the partition format works correct. Better format twice....
Backfisch said:
But no I have problems with installing a new rom. Everytime I enter twrp I get the message "Can't mount /system". So its impossible for me to install a new rom.
Click to expand...
Click to collapse
Okay, the fix is that you have to restore TWRP backup, in my case CM13 booted all good. But now I have a different problem, the MTP connection is really unstable, disconnects and reconnects for no reason. Same problem using twrp mtp or cm mtp. Tried two different cables, two different pc, and resized the partitions twice using different values. Still no luck. Anyone had any similar experience?
EDIT: Seems my charging port is failing. Many cables have hard time being stable, but some of them work better.
Backfisch said:
Yes, going back to the stock values of the partition using the gdisk again.
Its also import to make sure the partition format works correct. Better format twice....
Click to expand...
Click to collapse
Back when I tried to resize the /system partition, all non-lg rom doesnt install because of that error, and they are the ones that has the most potential of freeing some space
you can only get some space from /cache and other partitions without getting errors
I have gained 2 Gb extra space on the internal memory, and it works great so far. The only problem is that flashing roms from twrp returns the error /system can not be mounted, and you have to install the rom by restoring twrp backups.
Am I right in thinking that you cant install an rom update with modified partitions by flashing it in twrp?
If restoring my backup is the only way to install my rom, I will delete some music and pictures on the userdata partition...
You can install roms with "system" folder and files in it, on modified partitions (if you have enough space in /system, of course).
But you won't be able to install CyanogenMod-based roms with partition image in them (system.img, system.bin, etc.)
I played with this a bit and something went wrong Now i can't flash any os neither TOT or KDZ. I dismantled my phone to enter 9006 mode and recover it from there. But with no success :c What should i do now? I have my stock values of 30f saved, but after flashing kdz and tot i have stock recovery. It doesn't have adb suppor so i can't start gdisk operation. And i can't push any rom or recovery by sideload. When recovery starts I have list of errors. It can't mount system, data etc. I think I bricked it quite well xd
SantoSubito said:
I played with this a bit and something went wrong Now i can't flash any os neither TOT or KDZ. I dismantled my phone to enter 9006 mode and recover it from there. But with no success :c What should i do now? I have my stock values of 30f saved, but after flashing kdz and tot i have stock recovery. It doesn't have adb suppor so i can't start gdisk operation. And i can't push any rom or recovery by sideload. When recovery starts I have list of errors. It can't mount system, data etc. I think I bricked it quite well xd
Click to expand...
Click to collapse
Did you fix it yet? Does download mode work? Why didn't work flashing kdz in the first place?
Yes it does. After flashing kdz phone enters recovery and I have list of errors. And when i tried to flash tot i have error something with laf partition and gpt. Yesterday i tried to recover it from 9008 but I'm also getting error :c
SantoSubito said:
And when i tried to flash tot i have error something with laf partition and gpt.
Click to expand...
Click to collapse
Try to flash TOT-firmware with modded dll (bypass gpt-error). One of this should do the trick.
Yeah it worked. But not in 100%. When its 94% my phone reboots and LG Tool shows:
...
CACHE
CACHE
CUST
Wiating for the device 120s
then device reboots and get bootloop
BoardDiag have this wierd dload error and also i cant do nothing with this tool

filesystem mounting / repartitioning on live android system

Hy!
I have a mi2s and this phone is come to separated partitions in its internal drive. It has separated data and sdcard partition. My sdcard partition not mounted for some reason.
I want to keep this partition system, I just want to either mount the sdcard partition, or resize them without loseing data. (I can delete the sdcard partition but I want the data partition untouched, I had a long fight till this rom started to work with google play store, and I dont really want to remach it after all my apps are installed... Fun thing that after the first boot both partitions were mounted, after my first reboot only the data.)
I tried:
adb mount - adb sees it Android not sees it
write it to the fstab.qalcom - its on the / if I reboot the phone its loaded from somewhere again (I know its a ramdisk), my modifications are not permanent on there
I have basic linux knowlage and I started to dig into it, but I cant google out a general solution.
My questions:
How can I mount a fs like the usb otg from adb/android shell?
Can I edit the fstab file in its permanent store on an installed rooted device? And if I can where?
If I place new lines to the fstab on rootfs how can I tell the system to "reload" it?
Can I extend an ext4 partition from adb without loseing its data? *
* I have the required tools like parted from xiaomi forum, I cant post the link but you can google it with "Mi2S extending size of storage partition stillka".
Any help appreciated, and sorry for my english I'm not native.
So the basics:
If you can mount it from adb its a half win!
Try search the correct block partition and mount it with -t, add the correct file system and don't try auto it.
After you can mount it, you need to start an sdcard process its in /system/bin/sdcard. I had to see the custom rom implementation for that, in cm u need to param it "sdcard from to 1023 1023", but in samsung devices the to is hardcoded, and you nedd to do some sed magic.
After that your android programs will see it as a valid sdcard partition.
The harder way:
Wrap it to a startup script.
Add this script somewhere to run at bootup.
I'm still working on it, but I'm closer and closer. After I have the final solution I will write here once more.
I get so much help from there:
http://forum.xda-developers.com/showthread.php?t=2467048
If somebody want to do this:
After few hours of trying to mount the filessystem in boottime (in CM 12.1 its a hard work), i gave up, and went to a repartitioning way.
BE CAREFUL YOU CAN BRICK YOUR DEVICE IF YOU HAVE NO IDEA WHAT IM TALKING ABOUT!
I merged 2 tutorials:
reboot phone into CWM, connect phone to PC
connect to phone over adb and check if you are root
mount system
umount cache
umount data
copy content of partition_tools.zip into /system/bin and add executable attributes if necessary
Run parted on your device: parted /dev/sdX
Change display unit to sectors: unit s
Print current partition table and note the start sector for your partition: p
Delete your partition (won't delete the data or filesystem): rm <number>
Delete your partition (the second one we will delete data from there): rm <number>
Recreate the partition with the starting sector from above: mkpart primary <start> <end>
Recreate partition 27 (the last) mkpartfs primary ext2 3070 15758
name 26 userdata #we have to set back partition labels
name 27 storage
Exit parted: quit
Check the filesystem of 26: sudo e2fsck -f /dev/sdXX
Resize filesystem 26: sudo resize2fs /dev/sdXX
restore partition 27 with:
tune2fs -j /dev/block/mmcblk0p27
e2fsck -fDp /dev/block/mmcblk0p27
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p27
e2fsck -fDp /dev/block/mmcblk0p27
Of course in parted print you can see your original partition layout and this case it is possible that you have other partition numbers (my 26 partition is labeld by userdata and 27 with storage, and I gave more space to userdata from storage without loseing any data from userdata).
You can download the partition_tools.zip from the original miui forum, try to search to mi2s extending size of storage partition. (yes it will work with other devices too)

Expanding adoptable storage (bigger sdcard) or replacing sdcard without losing data

Ok so this took me a long time to figure out, and I didn't find this exact procedure anywhere so I thought to post it here for safekeeping. May it be useful to others. Say thanks if you think so.
The problem: You use adoptable storage in MM or up, but
you're running out of space, OR
you don't trust your sdcard anymore and would like to replace it
But, you have tons of apps and data on there, and want to keep it exactly as it was. You have already figured out that Android offers no tools to migrate adoptable storage to a new card, and actually makes it quite hard to do so. It is possible, albeit involved. But first...
Disclaimer: This is decidedly a 'pro' tutorial. If you've not used adb and Linux shell or don't know what root access is, this is not for you. Making mistakes following this, or even following this without fully understanding what you're doing may cause you to lose all your precious data, destroy your sdcards, lose your nerves and all hopes for mankind. I am not responsible for any damages to your hardware or social life. Don't blame me. You've been warned.
Read on? Good. Hold on to your hats and bear with me. This is what you'll need:
A new sdcard to replace the old one, of equal or bigger size (duh)
Root access to your Android device, adb shell
Two USB sdcard readers
A Linux board or PC (Linux live distro is fine) with at least two USB slots and root shell access. The Linux kernel version must be recent in order to have latest f2fs file system support and tools. I have used the latest Xubuntu ISO (live distro, booted from USB) for this.
With all of the above readily in place, these are the steps:
First, on your Android device, go to Settings - Storage, open the sdcard that is your adoptable storage, open the context menu and choose "eject". This may at a different spot in your device or Android version, look around until you find it.
Physically remove the card
Make sure that USB debugging is enabled and working on your Android and open an adb shell on your PC. Enter 'su' to become root and confirm on the Android device is SuperSU or similar asks for it.
In adb shell, enter the following 'ls' command and observe the output, e.g.:
Code:
[email protected]:/ # cd /data/misc/vold
[email protected]:/ # ls -al
total 32
drwx------ 3 root root 4096 2018-10-10 16:55 .
drwxrwx--t 26 system misc 4096 1970-01-01 15:24 ..
drwx------ 2 root root 4096 2018-10-10 15:42 bench
-rw------- 1 root root 16 2018-07-04 21:29 expand_961cbadcafe15c25ac1234294afdfa0c.key
[email protected]:/ #
There may be more than one "expand.... .key" file in there. If you're not sure which one is the one for your card, you'll have to try all of them to figure it out. Sorry, don't know of a better way, if anybody does, leave it in the comments. Now let's look at the binary key in that file and output it in hex:
Code:
[email protected]:/ # xxd -g 1 expand_961cbadcafe15c25ac1234294afdfa0c.key
00000000: 1a 74 4d 9f 4e ce e4 64 bb d4 5a 5e 6c 15 35 b0 .tM.N..d..[^l.5.
Make note of the key as we'll need it later - in this example, it is
1a744d9f4ecee464bbd45a5e6c1535b0
While you're here, if you have multiple key files, do the above for all of them and write down all possible keys.
You may close adb.
Now, put your old sdcard and the new sdcard in USB readers and plug the readers into the Linux PC's or board's USB ports. Open up a root shell and enter 'fdisk -l'. The card with the adoptable storage should be easy to spot as it will have two partitions where the first one will be a small 16M one, like this example from a 16GB card:
Code:
Disk /dev/sdb: 14.9 GiB, 15962472448 bytes, 31176704 sectors
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: gpt
Disk identifier: C7C77E9E-3C20-409C-CE45-5E6E60B8717C
Device Start End Sectors Size Type
/dev/sdb1 2048 34815 32768 16M unknown
/dev/sdb2 34816 31176670 31141855 14.9G unknown
For the remainder of this tutorial, we will assume that the source card with the adoptable storage is '/dev/sdb' and the target, new card is '/dev/sdc'. If your devices look differently, please replace these accordingly.
Now we clone the source card with the following command (THIS WILL OVERWRITE EVERYTHING IN THE 'of=...' DEVICE!):
Code:
dd if=/dev/sdb of=/dev/sdc bs=64k status=progress
Now test the encryption key with the source card:
Code:
dmsetup create crypt1 --table "0 `blockdev --getsize /dev/sdb2` crypt aes-cbc-essiv:sha256 1a744d9f4ecee464bbd45a5e6c1535b0 0 /dev/sdb2 0"
mkdir /mnt/as_src
mount -t f2fs /dev/mapper/crypt1 /mnt/as_src
ls /mnt/as_src
If you get errors, the key is wrong and you should do 'umount /mnt/as_src', then 'dmsetup remove crypt1', then repeat the above with the next key (not the 'mkdir' of course) until you succeed.
This only if the new card is bigger: We expand the second partition on the target card (here: /dev/sdc) using parted:
Code:
# parted /dev/sdc
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
Enter "print" to list the partitions - they should look the same as in the fdisk -l command above for the source card. After all, this is a clone. But the card size should be bigger. Now enter
Code:
resizepart 2 100%
quit
Now we have made the second partition bigger, but the encrypted file system still doesn't know about it. We now have to create the encrypted device and expand the file system (needs the package f2fs-tools):
Code:
dmsetup create crypt2 --table "0 `blockdev --getsize /dev/sdc2` crypt aes-cbc-essiv:sha256 1a744d9f4ecee464bbd45a5e6c1535b0 0 /dev/sdc2 0"
resize.f2fs /dev/mapper/crypt2
This should run through ok but will take a while. Go grab a coffee. After it has finished, verify that the encrypted storage is available by mounting it:
Code:
mkdir /mnt/as_dst
mount -t f2fs /dev/mapper/crypt2 /mnt/as_dst
ls /mnt/as_dst
No errors but you see the list of files and directories? Congrats - you are almost there! Now let's get outta here:
Code:
umount /mnt/as_src
umount /mnt/as_dst
dmsetup remove_all
eject /dev/sdc
eject /dev/sdb
Remove the card readers and insert the new card in your Android device. It should detect it as the original, do "checking" for a while and then see it normally, just with more space in case you migrated to a bigger card.
You did it! :good:
Can you tell if this method still works on newer Android versions (in my case, Pie)? In particular, are the keys still stored under /data/misc/vold? I've read that newer versions use safer methods to store keys, like hardware protected keys.
Just looked in my tablet which also runs Android Pi with adoptable storage and the key is there at the expected location. Haven't tried the method lately, but it's easy to test - just do the steps 1-5 and 7, skipping step 6. You don't need a second card and nothing will be written to your primary card so it's safe.
hello_world.c said:
Haven't tried the method lately, but it's easy to test.
Click to expand...
Click to collapse
Thanks for the response! I'd love to try, but the tablet that I'd need it for isn't rooted, and I can't root it without destroying the current encryption key. I was mostly asking out of curiosity, and for better understanding.
Hi, tx for the info going to try this when my new SD card arrives.
To find the right key file, at least on the lineage os 18.1/Android 11 installation, find the relevant "android_expand" partition of the sdcard block device, and run blkid on it.
The PARTUUID will match with the key file name.
Code:
# cd /data/misc/vold
# ls
expand_cddaaf99fe994c1185a1d8d637e855b5.key
# blkid | grep expand
dev/block/mmcblk1p2: PARTLABEL="android_expand" PARTUUID="cddaaf99-fe99-4c11-85a1-d8d637e855b5"
Thank you so much, just successfully upgraded my 8GB card to 128GB without losing any data!
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}

? How to recover deleted files on rooted Android without USB Debug & PC connection?

? How to recover deleted files on rooted Android without USB Debug & PC connection?
Hello.
I have removed some important files in my DCIM folder on internal memory of my Android device. The USB socket of the phone is broken so I couldn't use any recovery software that using USB debug mode but I have Team Win I want to use the terminal of Team Win to make an image and copy it to SD Card of my Android device. I know that there is a command dd but how to use it in a proper way to make a full image of the partition including also free space.
Thank you very much in advance!
Yes, dd command could be used simmilar to this:
open terminal, cd to external SD folder
dd if=/dev/block/block/bootdevice/by-name/userdata of=data.img
or if you know number of partition
dd if=/dev/block/mmcblk0p18 of=data.img (p18 is on Huawei LDN, image size is that same as partition size 16GB/32GB/64GB..etc, so for bigger then 32GB need to use NTFS sdcard or exFAT sdcard and TWRP also has to support NTFS or exFAT).
Or edit etc/*.fstab and repack twrp. You can back up files from /data for now (as ext4 or f2fs). Just add line to back up full image of /data (as emmc).
If /data has ext4 filesystem it can easilly mount/unpack/scan/rip image. But if /data has f2fs ... got not cure.
Example:
/data f2fs /dev/block/bootdevice/by-name/userdata flags=length=-16384;backup=1;settingsstorage;encryptable=footer;
/data_image emmc /dev/block/mmcblk0p55 flags=display="Data Image";backup=1;flashimg;
adeii said:
Yes, dd command could be used simmilar to this:
open terminal, cd to external SD folder
dd if=/dev/block/block/bootdevice/by-name/userdata of=data.img
or if you know number of partition
dd if=/dev/block/mmcblk0p18 of=data.img (p18 is on Huawei LDN, image size is that same as partition size 16GB/32GB/64GB..etc, so for bigger then 32GB need to use NTFS sdcard or exFAT sdcard and TWRP also has to support NTFS or exFAT).
Or edit etc/*.fstab and repack twrp. You can back up files from /data for now (as ext4 or f2fs). Just add line to back up full image of /data (as emmc).
If /data has ext4 filesystem it can easilly mount/unpack/scan/rip image. But if /data has f2fs ... got not cure.
Example:
/data f2fs /dev/block/bootdevice/by-name/userdata flags=length=-16384;backup=1;settingsstorage;encryptable=footer;
/data_image emmc /dev/block/mmcblk0p55 flags=display="Data Image";backup=1;flashimg;
Click to expand...
Click to collapse
Thank you very much for you point to point reply!
Finally, I choose to use that option with some modifications because vfat doesn't support files larger than 4GB.
Code:
dd if=/dev/block/bootdevice/by-name/userdata conv=noerror,sync bs=100M | gzip -c | split -b1000000000 - mybackup.img.gz
I have mounted this *.img partition using OSFMount for Windows. But after the scanning process (I was using R-Studio that supports ext4 file system I found my deleted files in the tree structure /media/0/DCIM/Camera but all of the deleted files has 0 bytes size and have 2 flags: deleted, wiped.
I couldn't understand how that happened. I mean I didn't use my phone after deleting files at all. I also mounted this *.img as raw disk in Active Undelete but the result is actually the same all of the deleted files have 0 bytes file size.
Is that a bug of the program? Or I have made an image using wrong command? Or Android 9 actually wiping files after deletion?
The files have been accidentally deleted by AirDroid-web app but I don't think so that this app is wiping deleted files it doesn't make sense...
RaTr said:
Thank you very much for you point to point reply!
Click to expand...
Click to collapse
You are welcome. Thank you are for note about 4GB file size limit on vfat/fat32, will save us from a lot of headache.
---------- Post added at 10:03 AM ---------- Previous post was at 09:49 AM ----------
RaTr said:
actually the same all of the deleted files have 0 bytes file size.
Click to expand...
Click to collapse
Maybe to try DiskDigger on phone if it is rooted to scan internal sd?
PhotoRec for Windows/Linux: https://www.cgsecurity.org/wiki/PhotoRec_Step_By_Step
There are few programs to try on your image on GNU/Linux like extundelete, ext4magic, AnalyzeEXT, ext3grep ...
Source: https://askubuntu.com/questions/217606/undelete-files-on-ext4
I am trying to use ext4magic to recover deleted files. But I need a copy of the journal when I am trying to use command
Code:
debugfs -R "dump <8> /var/tmp/home.journal" /dev/mapper/home
I see that Team win terminal do not have this command how to add it or how to make a copy of the journal of my ext4 partition where I am trying to recover my files.
adeii said:
Maybe to try DiskDigger on phone if it is rooted to scan internal sd?
Click to expand...
Click to collapse
I have tried to use DiskDigger. When I am putting a filter to show only deleted files it doesn't show anything. Which is pretty strange.
adeii said:
There are few programs to try on your image on GNU/Linux like extundelete, ext4magic, AnalyzeEXT, ext3grep ...
Source: https://askubuntu.com/questions/217606/undelete-files-on-ext4
Click to expand...
Click to collapse
Next program that I have tried was TestDisk but looks like it doesn´t support ext4 file system.
Thank you for the advice about PhotoRec. It has support of ext4 system. But it won't help. So, there are still some options. I will try to use extundelete as the next one.
If you have an image of EXT4, then you can use 7-Zip Archiver to read all the files inside it.
jwoegerbauer said:
If you have an image of EXT4, then you can use 7-Zip Archiver to read all the files inside it.
Click to expand...
Click to collapse
7-Zip will show deleted files also?..
I have tried 2 more utilities:
1. ext4magic without external journal file. It has done the job but I couldn't find any files that I need.
2. extundelete that program restored less files and also no files that I want to recover.
One more strange thing:
I have installed R-Studio and opened my image there. I fount full list of my deleted files, but all of the records of my deleted files have 2 flags: deleted, wiped and it shows me that the size of that specific files is 0 bytes.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I have checked other files from different dates, they can be recovered, there is no flag wiped and also I can see the size, in some of them there is a flag cross-link, but I think it is normal, that means part of that file is already overwritten by another one.
RaTr said:
I have tried 2 more utilities:
1. ext4magic without external journal file. It has done the job but I couldn't find any files that I need.
2. extundelete that program restored less files and also no files that I want to recover.
One more strange thing:
I have installed R-Studio and opened my image there. I fount full list of my deleted files, but all of the records of my deleted files have 2 flags: deleted, wiped and it shows me that the size of that specific files is 0 bytes.
I have checked other files from different dates, they can be recovered, there is no flag wiped and also I can see the size, in some of them there is a flag cross-link, but I think it is normal, that means part of that file is already overwritten by another one.
Click to expand...
Click to collapse
I am stuck in the same situation bro
See it here I described the issue very similar to yours. Any luck in trying to recover that `ext4` data
RaTr said:
I found my deleted files in the tree structure /media/0/DCIM/Camera but all of the deleted files has 0 bytes size and have 2 flags: deleted, wiped.
Click to expand...
Click to collapse
expected.
emmc/ufs flash storage is handled different from hard disk drive. there is FTL controller with own firmware that is wear-leveling whole storage all the time. not to mention files are fragmented.
file system sends TRIM on each deletion of file. note the discard mount flag for userdata partition.
Android 4.3 Update Brings TRIM to All Nexus Devices
www.anandtech.com
Hi, I tried dd command, and it returned
Code:
dd: data.img: Read-only file system
But ./adb pull /dev/block/mmcblk0p57 57.img worked, and created a NDIF image.
Why dd did not work?
And which format of image would dd create?
Thanks.
you're trying to write into phones / rootdir. you cannot dump partition into phone itself. external MicroSD card or OTG pendrive is required. but you could redirect to stdout into remote file (note the quotes make the difference where > redirection is executed)
Code:
adb root
adb shell 'dd if=/dev/block/mmcblk0p57 bs=1m status=none' > data.img
open data.img file with HxD editor and have a look into first bytes. search for magic 53 ef at offset 0x438 to confirm it's ext4 image.
dd is useful in case no usb connection available (topic of thread). the result is same as adb pull. you can increase speed with block size (bs= default 512 bytes) up to 1 MB.
Note: on FDE encrypted phone one can't pull userdata directly. instead pull whatever is mounted /data (like /dev/block/dm-0)
aIecxs said:
you're trying to write into phones / rootdir. you cannot dump partition into phone itself. external MicroSD card or OTG pendrive is required. but you could redirect to stdout into remote file (note the quotes make the difference where > redirection is executed)
Code:
adb root
adb shell 'dd if=/dev/block/mmcblk0p57 bs=1m status=none' > data.img
open data.img file with HxD editor and have a look into first bytes. search for magic 53 ef at offset 0x438 to confirm it's ext4 image.
dd is useful in case no usb connection available (topic of thread). the result is same as adb pull. you can increase speed with block size (bs= default 512 bytes) up to 1 MB.
Note: on FDE encrypted phone one can't pull userdata directly. instead pull whatever is mounted /data (like /dev/block/dm-0)
Click to expand...
Click to collapse
Thanks for your reply.
What would be the differences between
adb shell 'dd if=/dev/block/mmcblk0p57 bs=1m status=none' > data.img
and
the method described in this message: https://stackoverflow.com/a/41214172 ?
Thanks.
streaming over netcat avoids unwanted characters using stty raw. on macOS probably result is no difference (after unpacking gzip).
you don't need this as you wrote adb pull worked (which is the easiest method)
aIecxs said:
streaming over netcat avoids unwanted characters using stty raw. on macOS probably result is no difference (after unpacking gzip).
you don't need this as you wrote adb pull worked (which is the easiest method)
Click to expand...
Click to collapse
Thanks.
I searched Hex in 57dd.img created by adb shell 'dd if=/dev/block/mmcblk0p57 bs=1m status=none' > 57dd.img.
It showed
Is the 53EF on line 1080 in the image above is the one you mentioned "at offset 0x438"?
right, that is ext4 magic at offset/byte hex (0x438)16 = (1080)10 dec
I have a slightly different but related question /problem. My apologies if this is not the right place to post.
On my Samsung A10e, TWRP (and other recoveries) gives me a tarfork 255 error when trying to backup userdata. Normally this should be 32GB in size from Samsung specs.
I have used two alternatives :
* adb pull /dev/block/by-name/userdata data.img which creates a 26G file on my linux PC, that I can mount and inspect. When I run filesystem check it throws out errors, probably due to some of the data being encrypted - I am running AOSP Android 11 gsi. Perhaps the same errors that prevents TWRP from working ?
* alternatively I have put in a clean 32GB SD card, then via adb shell run dd if=/dev/block/by-name/userdata of=/dev/block/mmcblk1p1 to copy the full userdata partition over to the SD card. Once removed from the phone and put in a card reader, again this can be inspected on my linux PC, and gives the same filesystem check errors. I also ran dd if=/dev/external_sd of=data2.img on my linux PC to create a similar image file as adb pull but it is now the full 32GB that I would have intially expected.
So why the size difference between adb pull and dd ?? Does adb pull actually get everything - in other words if I try and restore with adb push will the phone recover to previous state and boot ?
I was hoping to then reduce the size of my data copy to 16GB since on my phone I am only using 12GB of the 32GB, but file errors are preventing me at the moment.
I was thinking about wiping data and then with arm32 parted and adb shell creating a 16GB userdata partition and an additional 16GB user shadow partition - the latter only to be used locally via dd to do backup and restore and avoid TWRP errors.
that is very lightly due to encryption issues....esp Magisk is known to break encryption.
if you can decrypt at TWRP level and then proceed to backup user data via ADB shell to memory card that is your best bed and then wipe the partition and then restore your app data individually for apps that you need e.g. contacts db for contact an SMS. I strongly doubt if you will be able to restore that entire partition and boot to that original partition successfully.... it may have become what what we can call "encryption tainted"
excuse my typos

Categories

Resources