Fast Disk Cloning [closed]
Asked Answered
L

7

7

Is there a way to have Linux read ahead when cloning a disk? I use the program named "dd" to clone disks. The last time I did this it seemed as though the OS was reading then writing but never at the same time. Ideally, the destination disk would be constantly writing without waiting that's of course if the source disk can keep up.

UPDATE: I normally choose a large block size when cloning (ex. 16M or 32MB).

Lori answered 10/9, 2008 at 16:39 Comment(0)
N
10

Commodore Jaeger is right about:

dd if=/dev/sda of=/dev/sdb bs=1M

Also, adjusting "readahead" on the drives usually improves performance. The default may be something like 256, and optimal 1024. Each setup is different, so you would have to run benchmarks to find the best value.

# blockdev --getra /dev/sda
256
# blockdev --setra 1024 /dev/sda
# blockdev --getra /dev/sda
1024
# blockdev --help
Usage:
  blockdev -V
  blockdev --report [devices]
  blockdev [-v|-q] commands devices
Available commands:
    --getsz (get size in 512-byte sectors)
    --setro (set read-only)
    --setrw (set read-write)
    --getro (get read-only)
    --getss (get sectorsize)
    --getbsz    (get blocksize)
    --setbsz BLOCKSIZE  (set blocksize)
    --getsize   (get 32-bit sector count)
    --getsize64 (get size in bytes)
    --setra READAHEAD   (set readahead)
    --getra (get readahead)
    --flushbufs (flush buffers)
    --rereadpt  (reread partition table)
    --rmpart PARTNO (disable partition)
    --rmparts   (disable all partitions)
#
Ninetieth answered 11/9, 2008 at 4:14 Comment(0)
B
7

You might try increasing the block size using the bs argument; by default, I believe dd uses a block size equal to the disk's preferred block size, which will mean many more reads and writes to copy an entire disk. Linux's dd supports human-readable suffixes:

dd if=/dev/sda of=/dev/sdb bs=1M
Berrie answered 10/9, 2008 at 16:46 Comment(0)
H
6

The fastest for me:

dd if=/dev/sda bs=1M iflag=direct | dd of=/dev/sdb bs=1M oflag=direct

reaches ~100MiB/s, whereas other options (single process, no direct, default 512b block size, ...) don't even reach 30MiB/s...

To watch the progress, run in another console:

watch -n 60 killall -USR1 dd
Hereabout answered 6/11, 2012 at 11:7 Comment(1)
Actually dd if=/dev/sda of=/dev/sdb bs=1M is fasted for me.Dorothadorothea
L
2

if the two disks use different channel (e.g., SATA) you can use high performance tool like fastDD. The authors claim:

"In this work, we reviewed the problem of reliably and efficiently copying data, recalling all the hardware and software mechanisms which intervene and interfer in the copying process. Our consideration have been coded in fastdd, a C++ program able to copy data very efficiently, as we show in our test."

Moreover the tool keeps a syntax very similar to the old dd.

http://www.dei.unipd.it/~zagonico/fastdd/

https://github.com/zagonico86/fastdd

Layby answered 15/7, 2014 at 13:5 Comment(0)
W
1

Maybe you can use two processes

dd if=indevfile | dd of=outdevfile

I'll assume you can set the other dd options as it suits you. This has some overhead but should allow asynchrony between reading one disk and writing the other.

Wismar answered 10/9, 2008 at 16:43 Comment(0)
M
0

Are you sure it isn't doing that at the same time? I would expect the disk caches to make sure it that happens. If not, non-blocking or even asynchronous reads/writes may help,

Mythological answered 10/9, 2008 at 16:45 Comment(1)
I believe the read/write swap was occurring because of the sounds the disks were making.Lori
M
0

About your update: How big are the caches of your HDs? (specially the writing one). It may be that that is too much and you may need to reduce it to prevent unnecessary blocking.

Mythological answered 10/9, 2008 at 16:56 Comment(1)
I cannot remember the cache size of either disk.Lori

© 2022 - 2024 — McMap. All rights reserved.