The impression of the capability of writing a single byte to a disk comes from Linux. Linux'the hardware is not even capable of writing a single byte, only a block at a time
dd
will perfectly do that if bs=1
is set. dd
I can easily update 2 bytes on the disk (EMMC) to change the partition number in the kernel's command line.Since you can only write one or more disk blocks (block size can be 512 or 4K etc.), if you want to *overwrite* a byte, what you have to do is read a block from the disk, then overwrite the byte you want, then write it out. But keep in mind what ralphbsz said re footshooting!How do I copy a single character to a device?
This doesn't work:-
echo -n '\x22' | dd of=/dev/da0
Is this doable?
Even more off-topic: When you do this in Linux to a disk (and your EMMC is a disk in the sense of using a block protocol), do you know whether it will perform a read-modify-write cycle? Or will it pad the partial block with zeroes?The impression of the capability of writing a single byte to a disk comes from Linux. Linux'dd
will perfectly do that ifbs=1
is set.
Two things. First, a common complaint about your posts: You need to give more details, and a justification. Why do you want to copy a single character to a device? What are you really trying to accomplish? If we know what your goal is, we can often suggest a solution. And: you simply write "it doesn't work". What does it actually do? Do you get an error message?
echo -n '\x23' | dd of=/dev/da0
dd: /dev/da0: Invalid argument
if [ -n "$VTGPT" ]; then
echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
else if [ -n "$VTGPT" ]; then
echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
else
xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
fi
Makes sense. You can only write one block at a time.Code:echo -n '\x23' | dd of=/dev/da0 dd: /dev/da0: Invalid argument
Do you know what that code is trying to do? What is the goal here? I could try to decode it myself and make educated guesses, but it's easier if you tell me what you want to accomplish.I'm trying to make some Linux code on FreeBSD.
That changes the meaning of the dd statement. Except that if dd gets only a single byte on its input, even with bs=1B it will still write a short block, containing only one byte.Strangely I noticed that on FreeBSD bs=1 does not work. I needed to use bs=1B.
Makes sense. You can only write one block at a time.
Do you know what that code is trying to do? What is the goal here? I could try to decode it myself and make educated guesses, but it's easier if you tell me what you want to accomplish.
Code:echo -n '\x23' | dd of=/dev/da0 dd: /dev/da0: Invalid argument
$ echo -e "\0043\c" | hd
Strangely I noticed that on FreeBSD bs=1 does not work. I needed to use bs=1B.
I'm a bit late to this thread and only want to comment on the use of "echo".How do I copy a single character to a device?
This doesn't work:-
echo -n '\x22' | dd of=/dev/da0
Is this doable?
printf '\x22\xAA\035%-10s!' "foo"
for all your output needs and never look back.