I've got a partition P1 (which contains my Linux OS) on a drive A.

I've just gotten a completely new drive B (that is larger than partition P1 AND the entire drive A).

I'd like to copy across the partition from drive A to drive B, and possible resize it later on.

Can this be done with dd? I could easily create a new parition table on drive B, and just cp the files across - but this seems like it might be slightly slower due to the filesystem overhead.

Output of `parted --list`:

It would be the partition 4 that I want to copy to another drive.

Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sdb: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name                  Flags
 1      17.4kB  1049kB  1031kB               BIOS boot partition   bios_grub
 2      1049kB  1074MB  1073MB  fat32        EFI System            boot, esp
 3      1075MB  183GB   181GB   ext4         Linux filesystem
 4      183GB   250GB   67.5GB  ext4         Basic data partition

Please ignore any reference to the boot drive / functionality (which I'll worry about later on) - keeps this question concise.

  • Favour returned! Question upvoted! ;-) – Fabby Nov 21 '18 at 21:45

Yes ,that's what dd is for. Assuming:

  • sxb is the drive to copy from
  • sxc is the drive to copy to
  • sxb4 is the fourth partition on the second drive that you want to copy from
  • sxc1 is the partition you've created to be of equal size to sxb4

do :

    parted /dev/sxc
    GNU Parted 3.2
    Using /dev/sxc
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) mklabel GPT
    Warning: The existing disk label on /dev/sxc will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? Yes
    (parted) mkpart primary 0.0 67.5GB
    (parted) quit

    dd if=/dev/sxb4 of=/dev/sxc1 bs=16M

As that will duplicate the UUID of the partition, in order to change the UUID of the new partition (make sure the partition is not mounted) run the following:

e2fsck -f /dev/sxc1
tune2fs /dev/sxc1 -U random

if sxbis an old drive and you expect it to have read errors, use ddrescue instead.

Note: as dd is known as disk destroyer, and creating a partition table is dangerous, not putting the exact command in the above as some random idiot on the Internet might see this question and copy-paste the codez without understanding what it does...

  • Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition? – Chris Stryczynski Nov 21 '18 at 21:03
  • 1
    Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-) – Fabby Nov 21 '18 at 21:11
  • 1
    Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski – Fabby Nov 21 '18 at 21:41
  • I've just done it! Thanks for pointing me in the right direction though. – Chris Stryczynski Nov 21 '18 at 21:44
  • Just a note that this seems to have duplicated the UUID of the partition - I'm not sure if this is any reason for concern though? – Chris Stryczynski Nov 21 '18 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.