读取指定扇区的文件

在Linux系统中通过dd命令可以直接读取和写入指定扇区的文件

读指定物理扇区:

dd  if=<源设备>  of=<输出设备或文件>   skip=<指定扇区值>  bs=512 count=1

写指定物理扇区:

dd   if=<输入设备或文件>   of=<输出设备>   seek=<指定扇区值>  bs=512 count=1

举个例子,我创建一个文件

# cat test.txt 
[Some of this is taken from Frohwalt Egerer’s original linux-kernel FAQ]

What follows is a suggested procedure for reporting Linux bugs. You
aren’t obliged to use the bug reporting format, it is provided as a guide
to the kind of information that can be useful to developers – no more.

If the failure includes an “OOPS:” type message in your log or on
screen please read “Documentation/oops-tracing.txt” before posting your
bug report. This explains what you should do with the “Oops” information
to make it useful to the recipient.

Send the output to the maintainer of the kernel area that seems to
be involved with the problem, and cc the relevant mailing list. Don’t
worry too much about getting the wrong person. If you are unsure send it
to the person responsible for the code relevant to what you were doing.
If it occurs repeatably try and describe how to recreate it. That is
worth even more than the oops itself.  The list of maintainers and
mailing lists is in the MAINTAINERS file in this directory.  If you
know the file name that causes the problem you can use the following
command in this directory to find some of the maintainers of that file:
perl scripts/get_maintainer.pl -f <filename>

然后读取这个扇区的文件,那么这个扇区在哪里呢?

# debugfs /dev/vda1
debugfs:  bmap test.txt 0
3795452

然后就可以计算出扇区:2048+8*3795452=30365664

# dd if=/dev/vda of=test.dump skip=30365664 bs=512 count=1

然后查看这个文件

# cat test.dump 
[Some of this is taken from Frohwalt Egerer’s original linux-kernel FAQ]

What follows is a suggested procedure for reporting Linux bugs. You
aren’t obliged to use the bug reporting format, it is provided as a guide
to the kind of information that can be useful to developers – no more.

If the failure includes an “OOPS:” type message in your log or on
screen please read “Documentation/oops-tracing.txt” before posting your
bug report. This explains what you should do with the “Oops” informa

猜你喜欢

转载自blog.csdn.net/u010278923/article/details/79901556
今日推荐