Cloning multiple partitions in Ubuntu

9,130

Solution 1

I was able to clone to a smaller drive by the following steps:

Before doing this I prepared the destination disk by creating a replica of the source partition table on the destination disk as described by Malte Skoruppa here. (essentially you make the same size partitions on the destination drive before cloning). I used Gparted for this.

The method of cloning was to plug in an external drive that had working clone of my original install and copy that using:

sudo -s dd if=/dev/sda1 of=/dev/sdb1 & pid=$! while kill -USR1 $pid; do sleep 1; done

dd if=/dev/sda2 of=/dev/sdb2 & pid=$! while kill -USR1 $pid; do sleep 1; done

(this will give you the output as the data is copied)

Next was to reinstall GRUB which would also need to be configured, so I booted up in BOOT-Repair LIVE to fix GRUB. I selected ADVANCED mode to reinstall GRUB and purge the old one.

See also my thread HERE So with the help of many wise Ubuntu gurus I was able to acomplish cloning onto a smaller drive. Thank you to all who contributed.

Solution 2

Just dd the section of the disk that goes from the start of the disk to the end of the last partition.

In your case the last partition is /dev/sdb3, so:

  1. Find /dev/sdb3's end using sudo fdisk -l /dev/sdb (End column);
  2. dd the section of the drive that goes from the start of the disk to the end of /dev/sdb3 (let's assume that the end of /dev/sdb3 is on byte 50000000000 and that the target drive is /dev/sdc for the sake of the example): sudo dd if=/dev/sdb | head -c 50000000000 | sudo tee /dev/sdc
Share:
9,130

Related videos on Youtube

Kalamalka Kid
Author by

Kalamalka Kid

One day at a time.

Updated on September 18, 2022

Comments

  • Kalamalka Kid
    Kalamalka Kid over 1 year

    I am attempting to clone multiple partitions with either Clonezilla or dd without cloning the whole drive which consists of:

    1. A boot partition
    2. A home partition

    Seen below is the original installation on a 128GB SSD, which I successfully cloned to a larger 250GB. This as a backup that I would later try to resize and shrink down.

    ORIGINAL INSTALLATION

    Below is a photo of a working clone of the operating system, which is now about 41 gigs in size total after being resized with Gparted.

    /dev/sdb2 circled

    I have tried to clone these partitions to my 64GB USB disk as a working portable backup, but have ran into some issues.

    I have tried using:

    sudo -s
    dd if=/dev/sdb of=/dev/sdc & pid=$!
    while kill -USR1 $pid; do sleep 1; done
    

    This bit for bit cloning method tried to copy the unallocated space on the input drive, which obviously won't work because the output disk is much smaller. In a second attempt I was able create a partition table on the destination disk that matched the source's sizes. I then tried to use boot repair and got this output

    Moving onto to Clonezilla options; normally a disk to disk would be my choice, but since the destination drive is smaller than the source, Clonezilla will not allow this.

    I do see an option to copy ONE partition at a time using the disk to disk option, but do not see how I might clone all three at once. I know there is an option to do this with saving as image but I want the USB to be bootable.

    One way I can think of making this work would be to make an image of the partitions I want to clone using disk to image, then restoring the image to the 64GB USB disk later, but after trying this I ran into more errors.

    After making an image of /dev/sdb/ I attempted to restore the file but got this error about /dev/sdb2/ missing:

    Unable to find target partion sdb2

    (/dev/sdb is the target for this session)

    So perhaps my image was OK, but it didn't properly read /dev/sdb2/ so I checked it with Gparted again and saw this following here:

    Warning! Unable to read the contents of this file system. The cause might be a missing software package. The following list of software packages is required for ext4 file system support: e2fsprogsv 1.41+.

    I checked with Synaptic Package Manager to see, and I already have e2fsprogs v1.42.9-3 installed. So I did some reading and tried the following solutions that have worked for other people:

    sudo fsck.ext4 -f /dev/sda6
    sudo touch /forcefsck
    Sudo reboot
    

    this seemed to work temporarily, as after another reboot or two, the problem still persists. I am assuming now that during the device to image process in Clonezilla that my /dev/sd2/ was not read properly, as I can not even access this partition in Nautilus or Gparted. I am thinking that is may have been caused by the re-sizing of the drive, but can not be sure, as it will still allow me to boot to this installation.

    I think I can actually clone these two partitions to image, and then restore them but I need to address this problem of:

    The following list of software packages is required for ext4 file system support: e2fsprogs v1.41+.

    Could this have come from re-sizing the partition? If so, how come I am able to boot to this installation if it can't be read?

  • Melebius
    Melebius over 4 years
    You could use the bs and count options of dd to avoid head (and tee), see superuser.com/a/1343575/84807 for details.