0

I have 9.6mb file that after doing dd if=/dev/zero of=/dev/block/mtdblock2 I write to mtdblock2. Before writing I have done a sha1sum on the file. I can use applypatch -c to check both size and sha but if I do a sha on the blockdevice it is of course different because of the space left on the device. If I copy the device I will get a 16mb image including that free space. Every where I read the suggestions are to use fdisk to get a count and then use the count option in dd. However, this does not work because the block and partition is the boot partition. How can I copy the original file, same size and sha, back off of the block device?

4
  • Not clear what you are asking. If you already know the size (9.6mb; is it 9.6MB or 9.6MiB?) just do dd if=/dev/block/mtdblock2 of=boot.img bs=9.6M count=1. bs=9.6M is 9.6*1024*1024 bytes. bs=9.6MB is 9.6*1000*1000 bytes. Use whatever applicable to your case. Mar 10, 2021 at 2:31
  • you know what /dev/zero is? you destroyed boot already, no way to get back
    – alecxs
    Mar 10, 2021 at 7:06
  • @Irfan Latif - The file I have is 9.6mb but the file I'm trying to extract maybe and probably is a different size. It's proprietary and signed. I need the image file itself to get the sha1sum so that I can use applypatch on it.
    – stoneAge
    Mar 16, 2021 at 11:55
  • So you are looking for boot.img format. See official documentation: source.android.com/devices/bootloader/boot-image-header and how magiskboot extracts boot.img: github.com/topjohnwu/Magisk/tree/master/native/jni/magiskboot. It's very device-specific. Mar 16, 2021 at 13:20

1 Answer 1

1

I would indeed use dd, with one or more of the several options available to specify the length (amount) of data to copy; otherwise, as you have noticed, dd will read the entire contents of the device, which is not what you want.

Re the apparent problem of the block device being the boot partition, the usual solution is to boot from some other medium (perhaps a LiveCD) so that the device you want to read is not the boot device/partition and can be read without difficulty. Before that, though, try sudo dd ... and see if running as root solves the problem without requiring more drastic measures.

3
  • 1) Boot partition is read-only. It's loaded in memory only once by the bootloader. After that it's no more in use. And even if it is, reading a raw block device is always possible. 2) How would you boot an Android device from LiveCD or any other medium? Mar 10, 2021 at 2:54
  • Taken literally, (1) is a little different than I'm used to on platforms I know better than Android, but still means OP should have no problem. Since he says he does*, I hypothesized that "maybe Android is different." Too, Android runs on so many different devices that maybe OP's device can boot from CD --or maybe a thumbdrive if you prefer. I've never seen anybody run a command-line shell, or dd, on Android before ; so, if he can do that, I can't assume anything is impossible. Bottom line, I think my basic points still hold, as far as they go. Mar 14, 2021 at 8:41
  • Just if you are interested to know in detail what I meant: android.stackexchange.com/a/220678/218526. Concepts of booloaders, boot partition and booting are entirely different on Android devices as compared to normal Linuxes or other OSes. Mar 14, 2021 at 9:06

You must log in to answer this question.

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