Can cat be used to clone a partition?

6

1

For example, can I do:

cat /dev/sda1 > /dev/sda2

instead of using dd, and if not, why will this not work?

Grezzo

Posted 2013-12-24T11:46:45.443

Reputation: 752

2You should be able to do this using cat, cp, dd and a dozen other tools. dd has the advantage that you can specify a block size which can speed things up. – Hennes – 2013-12-24T12:12:26.607

Answers

10

In principle, you could use either. There are few important differences, but none that apply here.

  • When you use > redirection, the target file is opened, and truncated. Only then it is written to. However this does not apply to block devices — they have a fixed size, so “truncation” doesn't do anything to them.

  • With cat you can not easily tell it to only copy the first n bytes or skip/seek. This is what dd is useful for.

  • cat does not let you specify a block size. This won't matter today when block sizes are masked by the file systems being used, but it used to make a difference where devices would be read from with specific block sizes (tapes).

  • For hard disks, cat may be slightly faster (better even than dd with a well-chosen block size, let alone the default which slows things down).

slhck

Posted 2013-12-24T11:46:45.443

Reputation: 182 472

1That is an excellent post you linked to. – Hennes – 2013-12-24T13:49:42.890