[How to] Determine dd Parameters For All LG G4 Models

Search This thread

dominik-p

Senior Member
Aug 20, 2015
95
56
[How to] determine dd parameters for all LG G4 models

IMPORTANT:
Only for advanced users!
You are an advanced user if you know exactly what you are doing.
You are an advanced user if you know what to do if something went wrong.
You are NOT an advanced user if you know how to do copy+paste.

You can bring your smartphone into a state, so it no longer works.
I am not responsible for anything. The following instructions are only suggestions.



Hello,
everyone knows how to root the LG G4 with the "low effort root" method.
They copied the system partition to an ".img" file, rooted it and copied it back to the "system" partition.
Many users wonder how to get the right parameters for the "dd" commands.
Please read the complete guide and be sure that you understand it until you execute a command!

Information:
Code:
dd if=/inputfile bs=8192 count=12345 of=/outputfile

if = Input File
of = Output File
bs = Blocksize in bytes (default is 512 - to increase copy speed use multiple of 512 e.g. 8192)
count = how many blocks
skip = skip blocks before start reading
seek = skip blocks before start writing

more info: http://man7.org/linux/man-pages/man1/dd.1.html


There are different models of the LG G4 on the market.
We know that the system partition is different depending on the model of the G4.
As an example I will show you how to calculate the parameters for the LG G4 H815 (International Model).

What you need:
Windows with Send_Command.exe

Instructions:
At first we need to know where the "system" partition starts (first sector) and how big it is (partition size).
I used the first method to find these values. But I recommend the second method because it's easier.

First method (difficult method, extracting the GPT and using "gdisk" in linux to read the partition info)

What you need:
Linux with "gdisk" installed

Instructions:
Put your smartphone to "Download Mode" and connect it to the Send_Command.exe command prompt.

We need to copy the partition table to the internal storage.
The partition table of GPT (GUID Partition Table) has a size of 16384 bytes and starts at LBA2.
Each LBA has a size of 512 bytes. Because we start at LBA0 we need to add 1024 bytes.
In summary 16384 + 1024 = 17408 (bytes).

Execute the following command:
Code:
dd if=/dev/block/mmcblk0 bs=1 count=17408 of=/data/media/0/gpt_backup.img

Enter "LEAVE" to restart your phone.

You will find the (very small) file "gpt_backup.img" on your internal storage.
Switch to Linux:
Copy the file to your Linux and open the terminal. Then type this:
Code:
gdisk /yourpath/gpt_backup.img

Some warnings will occur. Ignore them.
You will see:
Code:
Command (? for help):

Enter "p" and hit "enter".
You will get a list of the partitions.
Scroll up a bit and check that you see:
"Logical sector size: 512 bytes"
Scroll down and look for the "system" partition.
You will find a line similar to this:
Code:
47    884736   9363455  4.0GiB   FFFF system
Now you know the number of the "system" partition is "47".

You will see:
Code:
Command (? for help):
Type "i" and hit "enter".
You will be asked the partition number.
Enter it and hit "enter".
You will see something conatining lines similar to this:
Code:
First sector: 884736
Last sector: 9363455
Partition size: 8478720
Partition name: 'system'

We need the values from "First sector" and "Partition size".

Second method (easier method, just using "adb shell" to read the partition info)

What you need:
adb shell
usb debugging enabled

To get the "logical sector size" use:
cat /sys/block/mmcblk0/queue/logical_block_size
It should be 512

To find in any smartphone the offset and the size of /system:

$ adb shell
[email protected]:/ $ ls -la /dev/block/bootdevice/by-name/system
ls -la /dev/block/bootdevice/by-name/system
lrwxrwxrwx root root 2015-01-02 10:50 system -> /dev/block/mmcblk0p47
[email protected]:/ $ cd /sys/block/mmcblk0/mmcblk0p47
cd /sys/block/mmcblk0/mmcblk0p47
[email protected]:/sys/block/mmcblk0/mmcblk0p47 $ cat start
cat start
884736
[email protected]:/sys/block/mmcblk0/mmcblk0p47 $ cat size
cat size
8478720
[email protected]:/sys/block/mmcblk0/mmcblk0p47 $

so:
offset = 512 * 884736 = 452984832
partition size = 512 * 8478720 = 4341104640

Cheers!
So "first sector" is the value from "cat start" (884736).
The "partiton size" is the value from "cat size" (8478720).

Now the mathematics (using the values from above):
Logical sector size = 512 (I never saw something different on LG G4 smartphones)
Assuming bs=8192
skip and seek: "First sector" * "Logical sector size" / bs
884736 * 512 / 8192 = 55296

count: "Partition size" * "Logical sector size" / bs
8478720 * 512 / 8192 = 529920

That was an example for the H815 (International Model).
Use your own values to calulate the "dd" parameters!


Back to Windows:
Put your smartphone to "Download Mode" and connect it to the Send_Command.exe command prompt.
Now you can copy your "system" partition to "system.img" with the following command:
Code:
dd if=/dev/block/mmcblk0 bs=8192 skip=55296 count=529920 of=/data/media/0/system.img
Replace the values with the ones you calculated for your model!

Now you could copy the "system.img" to your Linux and root it or do everything else you want.

Important: Do NOT delete the original "system.img" from your internal storage as long as you are not 100% sure your G4 is stable.
If your modifications don't work, you can copy back the original "system" partition (with "dd").


To copy the modified "system_changed.img" back to the "system" partition use the following command:
Code:
dd if=/data/media/0/system_changed.img bs=8192 seek=55296 count=529920 of=/dev/block/mmcblk0
Replace the values with the ones you calculated for your model!

Important: Be sure to use "skip" when reading and "seek" when writing.
The "dd" command should take about a minute.

Did the instructions help you?
Please give a "Thanks!"
Thank you ;)
 
Last edited:
Hi,

thanks for this great post.
I just have one question. With your formulas and using 8K block size, I get a floating point number as result. So I used a block size of 4K instead, and I get an even number. This seems better to me so I went with it, as I believe smaller block sizes are always ok?

I'm just wondering one thing which seems not right to me. My system partition is reported to be 2.5GB:

Partition number (1-42): 39
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Microsoft basic data)
Partition unique GUID: A8725BAA-9E45-B2F8-8FA3-8C972F60F0CF
First sector: 836608 (at 408.5 MiB)
Last sector: 6074573 (at 2.9 GiB)
Partition size: 5237966 sectors (2.5 GiB)
Attribute flags: 1000000000000000
Partition name: 'system'

So with the formulas:

FACTOR 512 / 4096 = 0.125
skip and seek: "First sector" * "Logical sector size" / bs
836608 *FACTOR = 104576
count: "Partition size" * "Logical sector size" / bs
8478720 * FACTOR = 1059840

If I now run the dd command:
dd if=/dev/block/mmcblk0 bs=4096 skip=104576 count=1059840 of=/storage/external_SD/system.img

I get a file system.img which is 4096 MB. Should it not be 2.5GB as my original system partition?

If I use bs=512 (the default) and type
dd if=/dev/block/mmcblk0 bs=512 skip=836608 count=8478720 of=/storage/external_SD/system.img

I get a system.img of the right size (bit over 2.5GB).
I think the block size to use for "skip" is to be specified with the option ibs=XXX, not bs=XXX which only applies to "count" (according to man dd). I tried the ibs option, but the command then just doesn't work on Send_Command.exe. It doesn't even print an error but simply returns immediately.

Cheers
Jen
 
Last edited:

dominik-p

Senior Member
Aug 20, 2015
95
56
Hi,
which phone do you have?

Your calculation seems wrong. It's ok to use BS with 4k. I could be a bit slower then 8k, but that doesn't matter.
BUT: Look at your "count" value. Your partition size is 5237966. You used 8478720 (the value from my G4(H815EU) example). Thats wrong!!!

How to calculate with 1k and your values:
bs=1024
skip=836608*512/1024=418304
count=5237966*512/1024=2618983
Please check my calulation!!!

It's interesting, that the Send_Command shell has access to your external sd card...

I think the block size to use for "skip" is to be specified with the option ibs=XXX, not bs=XXX which only applies to "count" (according to man dd).
No. "bs" is the right parameter.
If you use "bs" it sets "ibs" and "obs" to the value of "bs".
Just do "dd --help" on a linux system for more details.
 
Last edited:
Hi Dominik,

oh my, how embarrassing ;) I actually did take the wrong value from the example you posted. I used my value (the 5237966) for calculating the parameters with bs=8K, and got a floating value, so tried 4K instead... and the wrong value must have snug in. Oups.

I also get floating value on 4K now that you've pointed my mistake out:
5237966 * 512/4096= 654745.75

If I rounded this up, would this not mean that I copy a tiny bit of the next partition on the image? And if I then use the image to restore, would I not run the risk to damage something in the following partition?

Anyway, it's not a huge drama as I can just use bs=512 and it works.

Yes I have access to the SD card, the image also has copied there successfully. I was also surprised because I read in the forums that it's not possible.
I found it out with the "df" command, as the SD was listed there. I needed to use it because there's no room on my internal storage (it's a ridiculous 8GB on the LG H735) to store the image there.

My system partition is only 2.5GB so I don't think I have to reformat, but you are right it would be better to use ext4.
 

dominik-p

Senior Member
Aug 20, 2015
95
56
Ok ;)
I removed my information about formatting the sd card.
You dont't have to format it. FAT32 is ok.
So you can use your sd card on systems which don't support ext4 too.
 
Last edited:

dominik-p

Senior Member
Aug 20, 2015
95
56
I have the LG G4S (H735). It's unusable without rooting as it only has 8GB internal memory. That's why I'm trying to root it now.
Ok, good luck.
Please open a new thread if you have questions about rooting your phone.
Or is there already one? Maybe these?

http://forum.xda-developers.com/g4/help/rooting-lg-h735-g4-beat-t3192491
http://forum.xda-developers.com/g4/general/lg-g4s-world-root-lg-devices-t3231759/page7
Oh. Just saw that you are already there :)
 
Last edited:
Ok, good luck.
Please open a new thread if you have questions about rooting your phone.
Or is there already one? Maybe these?

http://forum.xda-developers.com/g4/help/rooting-lg-h735-g4-beat-t3192491
http://forum.xda-developers.com/g4/general/lg-g4s-world-root-lg-devices-t3231759/page7
Oh. Just saw that you are already there :)

I just created a new thread too to focus on the particular problem I have:
http://forum.xda-developers.com/g4/general/rooting-lg-g4s-h735-t3243549
 

sparksthedev

Member
Mar 18, 2016
15
16
this guide helped in dumping boot and recovery partitions.

thank you very much sir! i successfully dumped my boot and recovery partition using dd in my mediatek device by following your guide.
 

dominik-p

Senior Member
Aug 20, 2015
95
56
thank you very much sir! i successfully dumped my boot and recovery partition using dd in my mediatek device by following your guide.

Congratulations :)
Did you use the first (more komplex) oder the second method for your device?

I saw that you had problems in this thread:
http://forum.xda-developers.com/showthread.php?p=65907557#post65907557
And you wrote a guide for MTK devices here:
http://forum.xda-developers.com/general/general/guide-dumping-boot-img-recovery-img-t3339530
This doesn't work with the LG G4, but I think it will help many others.
Thank you
 
My sister asked me to root her phone. It seems more complicated than anything I did in the past (HTC Wildfire, Galaxy Core Plus, Xperia M4A).
I tried this tutorial and it kinda worked, but I can't mount image I got, so it's useless (image, not tutorial!).
Phone is LG-H736 (Beat). I got this result in gdisk:
Code:
Partition number (1-42): 39
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Microsoft basic data)
Partition unique GUID: A9520AE6-ABC6-F107-E8FE-B37C4C30CB77
First sector: 836608 (at 408.5 MiB)
Last sector: 6074573 (at 2.9 GiB)
Partition size: 5237966 sectors (2.5 GiB)
Attribute flags: 1000000000000000
Partition name: 'system'
The 8K bs gave me floating point result, so I used 0,5K.
So the dd command were:
Code:
dd if=/dev/block/mmcblk0 bs=512 skip=836608 count=5237966 of=/storage/external_SD/system.img
BTW, I had access to SDCard and I didn't need to open ports...

EDIT: I got the system.img. The problem was I haven't got enough space on SD card.
But now I bricked it...
https://forum.xda-developers.com/g4/help/softbricked-g4-beat-lg-h735-t3959237
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 27
    [How to] determine dd parameters for all LG G4 models

    IMPORTANT:
    Only for advanced users!
    You are an advanced user if you know exactly what you are doing.
    You are an advanced user if you know what to do if something went wrong.
    You are NOT an advanced user if you know how to do copy+paste.

    You can bring your smartphone into a state, so it no longer works.
    I am not responsible for anything. The following instructions are only suggestions.



    Hello,
    everyone knows how to root the LG G4 with the "low effort root" method.
    They copied the system partition to an ".img" file, rooted it and copied it back to the "system" partition.
    Many users wonder how to get the right parameters for the "dd" commands.
    Please read the complete guide and be sure that you understand it until you execute a command!

    Information:
    Code:
    dd if=/inputfile bs=8192 count=12345 of=/outputfile

    if = Input File
    of = Output File
    bs = Blocksize in bytes (default is 512 - to increase copy speed use multiple of 512 e.g. 8192)
    count = how many blocks
    skip = skip blocks before start reading
    seek = skip blocks before start writing

    more info: http://man7.org/linux/man-pages/man1/dd.1.html


    There are different models of the LG G4 on the market.
    We know that the system partition is different depending on the model of the G4.
    As an example I will show you how to calculate the parameters for the LG G4 H815 (International Model).

    What you need:
    Windows with Send_Command.exe

    Instructions:
    At first we need to know where the "system" partition starts (first sector) and how big it is (partition size).
    I used the first method to find these values. But I recommend the second method because it's easier.

    First method (difficult method, extracting the GPT and using "gdisk" in linux to read the partition info)

    What you need:
    Linux with "gdisk" installed

    Instructions:
    Put your smartphone to "Download Mode" and connect it to the Send_Command.exe command prompt.

    We need to copy the partition table to the internal storage.
    The partition table of GPT (GUID Partition Table) has a size of 16384 bytes and starts at LBA2.
    Each LBA has a size of 512 bytes. Because we start at LBA0 we need to add 1024 bytes.
    In summary 16384 + 1024 = 17408 (bytes).

    Execute the following command:
    Code:
    dd if=/dev/block/mmcblk0 bs=1 count=17408 of=/data/media/0/gpt_backup.img

    Enter "LEAVE" to restart your phone.

    You will find the (very small) file "gpt_backup.img" on your internal storage.
    Switch to Linux:
    Copy the file to your Linux and open the terminal. Then type this:
    Code:
    gdisk /yourpath/gpt_backup.img

    Some warnings will occur. Ignore them.
    You will see:
    Code:
    Command (? for help):

    Enter "p" and hit "enter".
    You will get a list of the partitions.
    Scroll up a bit and check that you see:
    "Logical sector size: 512 bytes"
    Scroll down and look for the "system" partition.
    You will find a line similar to this:
    Code:
    47    884736   9363455  4.0GiB   FFFF system
    Now you know the number of the "system" partition is "47".

    You will see:
    Code:
    Command (? for help):
    Type "i" and hit "enter".
    You will be asked the partition number.
    Enter it and hit "enter".
    You will see something conatining lines similar to this:
    Code:
    First sector: 884736
    Last sector: 9363455
    Partition size: 8478720
    Partition name: 'system'

    We need the values from "First sector" and "Partition size".

    Second method (easier method, just using "adb shell" to read the partition info)

    What you need:
    adb shell
    usb debugging enabled

    To get the "logical sector size" use:
    cat /sys/block/mmcblk0/queue/logical_block_size
    It should be 512

    To find in any smartphone the offset and the size of /system:

    $ adb shell
    [email protected]:/ $ ls -la /dev/block/bootdevice/by-name/system
    ls -la /dev/block/bootdevice/by-name/system
    lrwxrwxrwx root root 2015-01-02 10:50 system -> /dev/block/mmcblk0p47
    [email protected]:/ $ cd /sys/block/mmcblk0/mmcblk0p47
    cd /sys/block/mmcblk0/mmcblk0p47
    [email protected]:/sys/block/mmcblk0/mmcblk0p47 $ cat start
    cat start
    884736
    [email protected]:/sys/block/mmcblk0/mmcblk0p47 $ cat size
    cat size
    8478720
    [email protected]:/sys/block/mmcblk0/mmcblk0p47 $

    so:
    offset = 512 * 884736 = 452984832
    partition size = 512 * 8478720 = 4341104640

    Cheers!
    So "first sector" is the value from "cat start" (884736).
    The "partiton size" is the value from "cat size" (8478720).

    Now the mathematics (using the values from above):
    Logical sector size = 512 (I never saw something different on LG G4 smartphones)
    Assuming bs=8192
    skip and seek: "First sector" * "Logical sector size" / bs
    884736 * 512 / 8192 = 55296

    count: "Partition size" * "Logical sector size" / bs
    8478720 * 512 / 8192 = 529920

    That was an example for the H815 (International Model).
    Use your own values to calulate the "dd" parameters!


    Back to Windows:
    Put your smartphone to "Download Mode" and connect it to the Send_Command.exe command prompt.
    Now you can copy your "system" partition to "system.img" with the following command:
    Code:
    dd if=/dev/block/mmcblk0 bs=8192 skip=55296 count=529920 of=/data/media/0/system.img
    Replace the values with the ones you calculated for your model!

    Now you could copy the "system.img" to your Linux and root it or do everything else you want.

    Important: Do NOT delete the original "system.img" from your internal storage as long as you are not 100% sure your G4 is stable.
    If your modifications don't work, you can copy back the original "system" partition (with "dd").


    To copy the modified "system_changed.img" back to the "system" partition use the following command:
    Code:
    dd if=/data/media/0/system_changed.img bs=8192 seek=55296 count=529920 of=/dev/block/mmcblk0
    Replace the values with the ones you calculated for your model!

    Important: Be sure to use "skip" when reading and "seek" when writing.
    The "dd" command should take about a minute.

    Did the instructions help you?
    Please give a "Thanks!"
    Thank you ;)
    2
    thank you very much sir! i successfully dumped my boot and recovery partition using dd in my mediatek device by following your guide.

    Congratulations :)
    Did you use the first (more komplex) oder the second method for your device?

    I saw that you had problems in this thread:
    http://forum.xda-developers.com/showthread.php?p=65907557#post65907557
    And you wrote a guide for MTK devices here:
    http://forum.xda-developers.com/general/general/guide-dumping-boot-img-recovery-img-t3339530
    This doesn't work with the LG G4, but I think it will help many others.
    Thank you