Quote:
Originally Posted by spiri13
So I want to skip 47906301 bytes.
|
Not quite: You want to skip 47906301
blocks, not bytes.
Since the output from the
filefrag command tells you that one block is 4096 bytes (and you set obs=1), you will have to seek to a position of:
Code:
seek=$(( 47906301 * 4096 ))
(BTW, your
dd command has a seek position of 41978746, instead of 47906301. Probably just a typo?)
Quote:
Briefly: I want to get the physical location of a file and overwrite its content directly writing to /dev/sda.
|
No, you should definitely
not write to
/dev/sda (i.e., the whole disk), but to the
partition instead (e.g.,
/dev/sda1, or
/dev/sda2, or whatever).
If you
really do want to write to the proper location on the whole disk, then you will have to add in the starting position of the partition—which you can find using the
fdisk command:
The
"Units:" line in the output will tell you that the command will count
sectors of 1 * 512 = 512 bytes. So, for instance, if your file is on the
/dev/sda6 partition, and
fdisk tells you that that partition begins at sector 302252032, then the correct position (relative to the whole disk) will become:
Code:
seek=$(( 302252032 * 512 + 47906301 * 4096 ))
By the way, overwriting some arbitrary position on your disk is pretty risky business, so you may want to double-check that you really are addressing the correct location by
reading it first, e.g.:
Code:
sudo dd if=/dev/sda ibs=1 skip=$(( 302252032 * 512 + 47906301 * 4096 )) count=4 | hexdump -C
The output should look like the following:
Code:
4+0 records in
0+1 records out
4 bytes copied, 0.3293 s, 0.0 kB/s
00000000 61 62 63 0a |abc.|
00000004