0

I want to know that when we flash specific partition images (say system.img, data.img, cache.img, etc.), then how does the software know where exactly to put those partition bytes? For example, if I flash system.img, which CHS/LBA sector will it consider as beginning of that block? If it is based on the MBR/EBR1 tables, what will happen if I'm flashing the MBR/EBR1 too?

The reason I'm asking is that I want to change the partitioning in EBR1 slightly, so that more space is allocated to /data partition instead of /sdcard. I've got an old but good conditioned MediaTek (MTK-6577) based smart-phone called Karbonn-A30 which is great in build quality and almost every other aspect, but it only has 500MB of Internal Storage (/data partition in Linux lingo) which is not good enough for apps. Presently, the MBR and EBR1 partitions are thus:

$disktype MBR
--- MBR
Regular file, size 512 bytes
DOS/MBR partition map
Partition 1: 2.000 TiB (2199023255040 bytes, 4294967295 sectors from 1024)
  Type 0x05 (Extended)
Partition 2: 10 MiB (10485760 bytes, 20480 sectors from 18432)
  Type 0x83 (Linux)
Partition 3: 10 MiB (10485760 bytes, 20480 sectors from 38912)
  Type 0x83 (Linux)
Partition 4: 650 MiB (681574400 bytes, 1331200 sectors from 113152)
  Type 0x83 (Linux)


$disktype EBR1
--- EBR1
Regular file, size 512 bytes
DOS/MBR partition map
Partition 1: 376 MiB (394264576 bytes, 770048 sectors from 1443328)
  Type 0x83 (Linux)
Partition 2: 1.293 GiB (1388314624 bytes, 2711552 sectors from 2213376)
  Type 0x83 (Linux)
Partition 3: 1.998 TiB (2196501691904 bytes, 4290042367 sectors from 4924928)
  Type 0x83 (Linux)

Why this last partition which corresponds to /sdcard is left so large (1.998 TiB) is beyond my understanding! Since there is a good 2.5GB of space available on my actual /sdcard partition, I was thinking if I can alter the EBS1 and change the LBA addressing so that the third partition starts from 2097152 additional sectors (which comes to 1024MB or 1GB which is good enough for me), will it automatically increase my /data partition by 1GB and decrease the /sdcard by 1GB correspondingly? On XDA and other forums, I've read that people have successfully done this mod and achieved the change in partition sizes, but I first want to understand how it happens.

1 Answer 1

1

Since I have a MTK-6577 based phone and had to delve into repairing a broken partition table recently I thought I'd take a stab at answering this.

I want to know that when we flash specific partition images (say system.img, data.img, cache.img, etc.), then how does the software know where exactly to put those partition bytes?

If you flash to known mount points /system, /data, /cache you not need to know about the underlying structure, simply is there enough space and it's in the correct format (e.g. ext4). The mount points are specified in vold.fstab.

However if you use a low level flashing tool such as SP Flash you will need to also modify the associated scatter file to the new layout of the partitions as it will access the memory addresses for the partitions directly.

An example filesystem mount points for the MT-6577 (copied from /tmp/recovery.log):

CWM-based Recovery v6.0.2.8
recovery filesystem table
=========================
  0 /tmp ramdisk (null) (null) 0
  1 /boot emmc /dev/bootimg (null) 0
  2 /cache ext4 /dev/block/mmcblk0p4 (null) 0
  3 /data ext4 /dev/block/mmcblk0p5 (null) 0
  4 /misc emmc /dev/misc (null) 0
  5 /recovery emmc /dev/recovery (null) 0
  6 /emmc vfat /dev/block/mmcblk0p6 (null) 0
  7 /system ext4 /dev/block/mmcblk0p3 (null) 0
  8 /sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 0
  9 /sd-ext auto /dev/block/mmcblk1p2 (null) 0

Why this last partition which corresponds to /sdcard is left so large (1.998 TiB) is beyond my understanding

This is a result of using GPT vs older MBR partition tables. It is a special extended partition that is the maximum 32-bit address range (2TB). It allows loading the MBR to any device regardless of it's internal memory size. Then you have custom EBR1 (and EBR2) tailored for each model.

I was thinking if I can alter the EBS1 and change the LBA addressing so that the third partition starts from 2097152 additional sectors (which comes to 1024MB or 1GB which is good enough for me), will it automatically increase my /data partition by 1GB and decrease the /sdcard by 1GB correspondingly

I am not entirely sure about the details of that.

Instead I used swapped the partition sizes of /data and /emmc with a EBR1 provided on xda-developers.com. Then in Android use Link2SD app which utilises a 2GB ext4 partition on the external sdcard and move large apps over.

Just thought I'd add that if things go spectacularly wrong, like it did originally for me, you can recover by using backups of the original MBR and ERB1 files for adb shell connecting to your phone in recovery mode.

Restore partition details:

dd if=/tmp/MBR of=/dev/block/mmcblk0
dd if=/tmp/EBR1 of=/dev/block/mmcblk0p1

Oh and to manually create a backup in the first place:

dd if=/dev/block/mmcblk0 of=/tmp/MBR bs=512 count=1
dd if=/dev/block/mmcblk0p1 of=/tmp/ERB1 bs=512 count=1

Mount an external sdcard from CWM and you can copy the file to/from /sdcard.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .