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?
1 Answer
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.
-
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? Commented 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. Commented 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. Commented Mar 14, 2021 at 9:06
dd if=/dev/block/mtdblock2 of=boot.img bs=9.6M count=1
.bs=9.6M
is9.6*1024*1024
bytes.bs=9.6MB
is9.6*1000*1000
bytes. Use whatever applicable to your case.boot.img
format. See official documentation: source.android.com/devices/bootloader/boot-image-header and howmagiskboot
extractsboot.img
: github.com/topjohnwu/Magisk/tree/master/native/jni/magiskboot. It's very device-specific.