Basic question about flashing nandroid backups
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.