2

I have two devices & mdash; the first one has 20 partitions and the second has one big partition. I would like to clone specific partition (content + data) from device one to device two.
How can I do this? How can I create in the second device the same partition with same features as the source partition?
For example, I want to duplicate the partition type, filesystem type, flags, ... etc of the original partition.

  • 1
    Since the second device currently has one big partition, how do you plan to make room for the data that you want to copy? Do you want to shrink the existing partition? What does it currently contain? – Gilles 'SO- stop being evil' Mar 15 '15 at 22:00

2 Answers2

0

dd is your friend.

Example syntax:

dd if=/dev/sda1 of=/dev/sdb1 bs=1M

Alternatively you can dd the partition to a file and the dd the file to your target disk at a different offset.

For more information, type man dd in a console to find out the various uses and options.

Edit, modified example to show how to copy a partition.

captcha
  • 1,010
  • That would copy the content of the whole disk (overwriting what is already there), not a specific partition. In addition, dd is very much not your friend: what you wrote is a complex, error-prone, potentially slower way of writing cat /dev/sda >/dev/sdb. – Gilles 'SO- stop being evil' Mar 15 '15 at 22:00
  • Thanks for the minus one. If you had read the man page it will tell you that you can also use dd to copy a partition. – captcha Mar 15 '15 at 22:02
  • You can, in the same way you can swim across a crocodile-infested swamp. That doesn't mean that the crocodiles are your friends. – Gilles 'SO- stop being evil' Mar 15 '15 at 22:18
  • I'll take personal responsibility if dd chews out a piece of your leg.. :) – captcha Mar 15 '15 at 22:36
  • @Gilles can you expand on why dd is dangerous and cat is good for copying drives (or drive partitions)? (I use dd to make copies of my system partition.) – gogoud Mar 16 '15 at 06:31
  • @gogoud dd is dangerous because it doesn't always copy what you tell it to. It's ok in scenarios like this one where the input and output are both block devices or regular files and you don't pass a block count. But if you pass a block count, or if one of the ends is a pipe, data is likely to be silently dropped. dd has its uses but they're uncommon. dd is often not faster than cat or cp. – Gilles 'SO- stop being evil' Mar 16 '15 at 13:14
  • @gogoud cat just copies its input to its output (except on antique implementations that fail on null bytes, but if your system is *BSD or Linux or made in the 21st century that shouldn't be an issue). You don't need to worry about whether it's going to do what you wanted or whether you've passed appropriate parameters for decent performance. Despite what some uninformed tutorials say, the magic is in /dev/…, not in dd. – Gilles 'SO- stop being evil' Mar 16 '15 at 13:15
0

the partiton types are set using fdisk or equivalent, I don't know of an automated way to copy them. so you will have to set the type when you create the partition. or update the type manually after the creation.

Jasen
  • 3,761