Duplicate a slice (and data) on the same disk

Hi all,

FreeBSD 8.2. Needing to duplicate a non-FreeBSD slice on the same drive. Backups do not work! It must be raw sector copied. Typically I would use two disks and dd it, something like dd if=/dev/ad4 of=/dev/ad6 bs=1m. However this time I would like to do it on the same drive. (tired of wasting drives and doing the complete drive).

#gpart show /dev/ad6
Code:
=>       63  976773105  ad6  MBR  (466G)
         63  409593177    1  ntfs  [active]  (195G)
  409593240  567179928       - free -  (270G)

Question 1:
Needing confirmation of where it all starts and stops.
Code:
    Read Starts  at 63        and ends at 409593240
    Write starts at 409593241 and ends at 819186418
Correct?

Question 2:
How to tell dd to start writing at the end of the first slice and continue from there?

Tried using OSEEK on the output and made a mess of things. So before I try again I plead for assistance.

At some point in time I'll need to go the other way as well. Slice 2 (the copy) will need to be copied back to slice 1. (restored)

Thanks,

-Enjoy
fh : )_~
 
Just to make sure it's clear, dd(1) is a terrible tool for copying filesystems. But since you insist...

First, make a backup. Seriously.

Second, use gpart(8) to create the new partition. This must be done, or the copied data will not be accessible. See gpart(8) about the add option, using -t ntfs and -s to limit size of the new partition. Because you are copying with dd(1), any extra space in the target partition will be wasted, so it might as well be exactly the same size as the original, 409593177 blocks.

Once that's all completed, copy the first partition to the second: dd if=/dev/ad6s1 of=/dev/ad6s2 bs=64k.
 
How can I tell dd() to:
copy block 63 to 409593241
copy block 64 to 409593242
And so on, Stopping after reading block 409593240 and writing it to block 819186418

-Enjoy
fh : )_~
 
Please quit thinking on such a high level ... Obviously I need to work at a lower level, not by file system!

My mistake was showing the partition I did for an example (and my test partition)... That is NOT the actual partition, the actual partition is proprietary.

I've done this before, unfortunately I do not remember the exact command, it was something like dd if=/dev/ad6 of=/dev/ad6 bs=512 skip=63 count=409593177 seek=409593241.

If I understand things right, the above command reads 409593177 blocks of 512k skipping the first 63, seeking to block 409593241 and writing them. I question the skip=63, wouldn't that be skip=62, thus to start reading at 63?

Is my math correct, numbers correct for the above NTFS example without stomping on each other?

EDIT:
I already know they are not!

-Enjoy
fh : )_~
 
FestusHagen said:
Please quit thinking on such a high level ... Obviously I need to work at a lower level, not by file system!

Filesystems are not involved here, just partitions. Done as you requested in the original question.

My mistake was showing the partition I did for an example (and my test partition)... That is NOT the actual partition, the actual partition is proprietary.

It does not matter. The slices FreeBSD uses correspond to MBR partitions.

I've done this before, unfortunately I do not remember the exact command, it was something like dd if=/dev/ad6 of=/dev/ad6 bs=512 skip=63 count=409593177 seek=409593241.

If I understand things right, the above command reads 409593177 blocks of 512k skipping the first 63, seeking to block 409593241 and writing them. I question the skip=63, wouldn't that be skip=62, thus to start reading at 63?

Is my math correct, numbers correct for the above NTFS example without stomping on each other?

Using dd(1) like that gives a very good chance of overwriting the wrong part of the original or the copy. Using actual slices (MBR partitions) make this easier and less error-prone. The contents of the partition do not matter.

There are several problems with using dd(1) like you show. To do what you want probably requires using oseek. Using a larger buffer size will greatly increase copy speed but may require adjustment of the other numbers. It is easier, safer, and more compatible to use gpart(8) once to create another slice.
 
Absolute perfection ...

After playing and testing on a XP loaded drive I did it on the POS system, Worked flawless.

I successfully duplicated the POS secure volume, destroyed the original, then restored it. All with dd(). The POS reports no volume issues!

Yup, takes a long long time 512 bytes at a time on a 200 GB volume. About 32 hours each way! All without creating any partitions/slices or whatever, Could it be seen with common disk tools (gpart, fdisk), NO! Can't see the original either!

No this does not violate copyrights, it still must be used on the same system! I just don't like paying their prices for pre-loaded drives of software that I already own and paid HUGE BUX for!

-Enjoy
fh : )_~
 
Back
Top