2

I have 2 SSD's. My system (Ubuntu 12.04) is installed on one and I want to clone it to another. The problem is that the system is currently on a 128GB drive and the new one is only 120GB. Is it possible to create an image using dd ​​to a drive of smaller capacity?

4
  • 2
    Try asking on superuser.stackexchange.com or serverfault.stackexchange.com
    – Joe
    Apr 29, 2013 at 14:49
  • Can you reword your question, please.
    – jofel
    Apr 29, 2013 at 14:50
  • this is not a programing question. By the way, boot with a live system, mount both disks and make a cp -a to copy to a smaller disk. Apr 29, 2013 at 14:54
  • Have a look at this question.
    – Benny Hill
    Apr 29, 2013 at 14:58

4 Answers 4

5

How to do what you asked to do:

  1. use gparted to resize your system partition smaller than 120GB... preferably, if possible, considerably smaller than 120GB, to make sure you really do have it below the total size of the target drive.

  2. dd if=/dev/sda bs=8M of=/dev/sdb, assuming your source and target drives are sda and sdb, respectively. do this from safe mode or from a live boot environment, NOT from your source OS running with a normal multiuser login.

    OR, if you have network access in your live boot environment, and universe in your sources: apt-get install pv ; pv < /dev/sda > /dev/sdb. The difference between this command and the dd command, for your purposes here, is that this one gives you a P-R-O-G-R-E-S-S B-A-R... :)

However, a probably better way to do what you really WANT to do:

  1. do a bare install of Ubuntu on the target drive. (there are more efficient ways to get a boot sector on a new drive, but I'm going for "noob-friendly" here.)

  2. mount both drives from a live boot environment, and rsync -harv --progress /path/to/source/ /path/to/target/. Note that you REALLY want to be in a live boot environment here, not in a running system, otherwise you'll have to deal with stuff like devfs, procfs, and so forth - not to mention files potentially altering/disappearing while you rsync.

2

STEPS

  1. If at all possible, make a backup of the source drive (128 Gb).

  2. Use Gparted USB to boot, then use it to shrink your partition of source drive (128 Gb) to less than the target drive size (120 Gb).  If you have a full drive, let's say 128 Gb with no space at all, then you may need to compress (zip) some of the data files, or copy to another temporary USB to achieve less than 120 Gb (size of target drive). Otherwise you can't fit the source contents into the target drive. It simply won't fit.

    Leave some extra free space just in case (1 Gb maybe, for geometry translations or whatever. My drive is one size, but dd and Gparted displayed a different size, slightly different).

  3. Once the partition of the source drive has been shrunk to less than the size of target drive, then you can perform the dd. Make sure you are copying source to target, otherwise you will end up very unhappy. (If the source is /dev/sda make sure is the 128 Gb drive now with partition less than 120 Gb... Your target is /dev/sdb new 120 Gb drive.)

    dd if=/dev/sda of=/dev/sdb bs=4096 conv=notrunc,noerror

  4. Now, if you want, you can go back to Gparted and on the source drive, extend the full size of the partition to max allowed.

Gparted makes a great job shrinking partitions and shows you space used, so you can shrink to whatever size above the used space. I have tried to copy and paste partitions using Gparted but did NOT work for me. Only use Gparted to shrinking partitions, then use dd to do the copying.

Once it finishes, it may tell you that you ran out of space. It's normal; you are copying onto a smaller disk. But since you are copying a smaller partition, then all data gets copied. dd tries to copy all the 128 Gb onto the 120 Gb and throws an error. Don't worry; no damage to drives. Now remove the Gparted USB, remove the source drive and boot to the new 120 Gb disk, check for contents, and if you have any space left, you may unzip those previously zipped files.

2
  • This is very similar to Jim Salter's answer, with only slightly more detail. Dec 4, 2018 at 2:09
  • Indeed, try to comment on that post, but Im new, the system does not allowed me. I did exactly that procedure yesterday, backing up my server. So the procedure is the correct. Regards. Dec 4, 2018 at 5:45
1

The only viable option that I could think of is if you resized the ext4 partition so that you have 119gb of data and 9 gb of free space trailing at the end. Then you could use the DD with the bs= and count= commands to copy 120 gb of data to the drive. (You will have 1 gb leftover of free space which you can then resize again (I only did that to be safe))

0

I'm assuming each drive has/will have only one partition.

dd cannot be used the way you want to because it will copy each block of data that is physically on one drive to the other, including data defining the partition and filesystem as using 128GB. And any blocks of data stored at the end of the first drive will be lost.

One simple solution, alluded to by Ottavio Campana in the comments:

  1. Boot the system using a LiveCD
  2. Create the filesystem on the new drive
  3. Mount both drives and copy the old to the new using cp -a

You will then have to install a bootloader (e.g. GRUB) on the new drive if it will be your main drive.

Benny Hill's comment provides a link to a similar question with answers offering other solutions.

You must log in to answer this question.