tags:

views:

62

answers:

3

Is there a script i can use to copy some particular sectors of my Harddisk?

I actually have two partitions say A and B, on my Harddisk. Both are of same sizes. What i want is to run a program which starts copying data from the starting sector of A to the starting sector of B until the end sector of A is copied to the end sector of B.

Looking for possible solutions...

Thanks a lot

A: 

I am not sure if what you are looking for is a partion copier. If that is what you mean try clonezilla.
(it will show you what exact statement it uses so can be used to find out how to do that in a script afterwards)

Hennie
Nah. I actually need to copy some particular sectors. That "Partition" was just an example. I need something that copies specified sectors.
baltusaj
+4  A: 

How about using dd? Following copies 1024 blocks (of 512 bytes size, which is usually a sector size) with 4096 block offset from sda to sdb partition:

dd if=/dev/sda1 of=/dev/sdb1 bs=512 count=1024 skip=4096

PS. I also suppose it should be SuperUser or rather ServerFault question.

Daniel Bauke
Thats very close but I don't have partition information. It's something like some data is hidden in unallocated region of Harddisk and I want to copy some sectors from that unallocated region to some other place in the same unallocated region. Which to me is only possible if i copy by specifying sectors. Any thoughts on this?
baltusaj
A disk is also a block device, so you may use it as an argument for `if=` and `of=` as well, e.g. `if=/dev/sda of=/tmp/any_file`
Daniel Bauke
If you operate on the disk itself (eg `/dev/sda`), and use `bs=512`, then the `count` and `skip` will be effectively addressed as LBAs.
caf
Thanks guys. That helped.
baltusaj
+2  A: 

If you want to access the hard drive directly, not via partitions, then, well, just do that. Something like

dd if=/dev/sda of=/dev/sda bs=512 count=1024 skip=XX seek=YY

should copy 1024 sectors starting at sector XX to sectors YY->YY+1024. Of course, if the sector ranges overlap, results are probably not going to be pretty.

(Personally, I wouldn't attempt this without first taking a backup of the disk, but YMMV)

janneb