Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active February 15, 2021 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/493818b007403e3f2ae0dbd1cfb5e689 to your computer and use it in GitHub Desktop.
Save WillSams/493818b007403e3f2ae0dbd1cfb5e689 to your computer and use it in GitHub Desktop.
Cloning large hard drives
  1. Use built in gnome-disks app to create the partition image.
  2. Note the size of actual contents. I.e., for the 500GB partition you just cloned, the actual contents might have been only 20 GB. We'll use this number to make sense of the 'truncate' command in step 3.
  3. Force partition size of actual contents:
sudo modprobe loop
sudo losetup -f  # use the loop device returned.  For this example, we'll use /dev/loop1
sudo losetup /dev/loop1 my-mintbox.img
sudo partprobe /dev/loop1  
sudo gparted /dev/loop1    # while in gparted, unmount /dev/loop1 and re-size by moving slider all the way to size of actual contents.  Apply!
sudo losetup -d /dev/loop1
truncate --size=25000000000 myimage.img  # just truncate to actual contents (in bytes) with some space.  We'll re-size again, just make it bigger than actual.
  1. Using any tool you choose, create the partitions on the target hard drive. For example, create extended partion with swap space and primary with your contents w/ bootale flag).
  2. Using gnome-disks again, restore the image to the primary, bootable partition.
  3. Now, you'll have the restore but the partiition will actually still have some unallocated space. To fix,run cfdisk and delete the partition. No worries, the data will still be there.
  4. Using gparted Create a new partition from the unallocated space; if free-space preceeding 1Mib, that should be correct. I know this sounds scary but you your original data is still there, no worries).
  5. If you need bootable flag to a partion, add/re-add it.
  6. Install Grub. For example:
sudo grub-install /dev/sdb
sudo update-grub /dev/sdb

This entire process should take no longer than a couple of hour's time if you are working with SSD drives. A little longer with older hard disks, but not too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment