Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
2  
Try asking on superuser.stackexchange.com or serverfault.stackexchange.com –  Joe Apr 29 '13 at 14:49
    
Can you reword your question, please. –  jofel Apr 29 '13 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. –  Ottavio Campana Apr 29 '13 at 14:54
    
Have a look at this question. –  Benny Hill Apr 29 '13 at 14:58
add comment

migrated from stackoverflow.com Apr 29 '13 at 16:42

This question came from our site for professional and enthusiast programmers.

3 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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))

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.