How do I use dd to clone an external USB drive installation to a local hard disk?

62,199

Using dd to clone an Ubuntu installation

Yes, you can use dd to clone an installation, but it's not the fastest/easiest way to do it. It's better to do it via backup/restore with a live-tool such as Clonezilla.

  • If you wish to use dd, note that the target disk must be the same size or larger than the source.

  • Also, to make it bootable, you must copy from device-to-device (e.g. /dev/sdX), NOT from partition to partition (/media/...)

  • Use sudo fdisk -l or gparted to find out which block devices your target internal hard disk (usually /dev/sda) and external USB hard disk (usually /dev/sdb) are.

  • Then use dd with exactly the following syntax, where x is the letter for the USB drive and y the letter for the internal drive which you have determined in the previous step:

      sudo dd if=/dev/sdx of=/dev/sdy bs=8M && sync
    

    and wait for it to complete.

  • To answer your other question, no, simply dd'ing to an ISO (or CD or DVD, etc.) will NOT work; it will be unbootable. For that, you need to use a tool such as remastersys. See this question for more information:

    How do I convert my Ubuntu installation into a Live-USB or Live-CD?

Share:
62,199

Related videos on Youtube

Rayson Jimenez
Author by

Rayson Jimenez

Updated on September 18, 2022

Comments

  • Rayson Jimenez
    Rayson Jimenez over 1 year

    can I use the dd command to clone my ubuntu installation from my external disk to my local hard drive. will it even boot? I think I can, but not sure. do I need to make the output partition on my local disk the exact size as the input partition on the usb? I'm thinking install and boot off a liveusb on a different small flash drive and run something like sudo dd if=/media/usbexternaldisk of=/media/localdisk would that work as is?

    also if I make an iso image of my external ubuntu installation using dd, can I burn it onto disk or unto another hard drive and have that boot up?

  • Jordon Bedwell
    Jordon Bedwell over 11 years
    dd is the fastest, it's low-level. Your second point is incorrect. You can copy from partition to partition via /dev/sd[X][N]... /media/... is not a partition, it's a mount pointing to a partition AKA /dev/sd[X][N] or for some people who work with virtual machines just /dev/sd[X].
  • ish
    ish over 11 years
    @JordonBedwell: Can you copy from partition to partition? Yes. Will that result in a bootable clone? No.
  • ish
    ish over 11 years
    @JordonBedwell: Also, dd is not the fastest because it's low-level. It will copy every single bit, including free space, which smarter tools won't.
  • Jordon Bedwell
    Jordon Bedwell over 11 years
    Nobody implied it would create a "bootable clone" so you are making a moot point, my goal was to help you better your answer by correcting the things that were wrong. Though if you you want to get technical... you neglect to mention that if he does your exact command from an internal disk to usb hd that it will make a bootable copy since it will copy the mbr too since you didn't add a count and you start from the beginning.
  • ish
    ish over 11 years
    With all due respect, your nit-picking is off-topic since the question clearly involves making a bootable clone, and that is the goal my answer aims to achieve. We are not discussing the general usage or merits of dd when copying arbitrary data.
  • Jordon Bedwell
    Jordon Bedwell over 11 years
    Why would you even compare dd to an incremental/diff backup tool and then claim it's slower... If that is what you mean... if any other tool /exactly like dd/ is faster then dd when it comes to complete 1:1 copies, you are doing it wrong.
  • Jordon Bedwell
    Jordon Bedwell over 11 years
    Seriously? You're going to claim I am nit-picking when you are giving the user false information? Targeted or not? DD can copy partitions, that is point blank true, you claim it can't, you are wrong, in any context. You claim that DD won't make a bootable copy, it can and you neglect to mention that it depends on the type of copy he is doing, yes for an ISO you are right, but he also briefly mentioned a liveUSB which /he can create/ with DD and no other tool.
  • ish
    ish over 11 years
    Please add your own answer (or feel free edit mine). This discussion is unproductive.
  • RobotHumans
    RobotHumans over 11 years
    He never claimed it wouldn't directly copy partitions. a)it will copy partitions with /dev/sdXY format, b)it will NOT copy the boot sector when using that format(/dev/sdX would), c)it will, in all probability, NOT be boot-able (disk UUIDs would be different for one thing, there are more), d)dd is NOT faster than higher level tools unless the disk is mostly full, e)dd will hang if it fails to read due to a failing disk, f)I don't think you're helping anyone better understand anything.