stevenshiau / clonezilla

Clonezilla is a partition or disk clone tool similar to Norton Ghost®. It saves and restores only used blocks in hard drive. Two types of Clonezilla are available, Clonezilla live and Clonezilla SE (Server Edition).
GNU General Public License v2.0
618 stars 95 forks source link

Cloning most of an Ubuntu system disk, except for one data partition #118

Open mslinn opened 1 month ago

mslinn commented 1 month ago

I want to clone a 4 TB Ubuntu system drive, except for one data partition, to a 2 TB drive. The clone should be bootable, so the GPT data, EFI partition and system partition need to function. This does not seem to be possible using the Clonezilla menus, even in expert mode.

The image below shows the partitions on the drive to clone. All partitions should be copied to the new bootable drive, except the last partition (shown as /dev/sdb3, labeled Data):

gojira_gparted

I have no desire to reinvent Clonezilla, or to do any unnecessary programming. The most desirable outcome would be to learn how to use an unmodified Clonezilla to accomplish the task.

Clonezilla has dozens of interesting utilities in clonezilla/sbin/ for managing Linux drives. I have not found any documentation on these utilities.

My detailed notes are online.

stevenshiau commented 1 month ago

That's true. There is no such scenario in Clonezilla. However, it's possible to do that. If you meant "cloning", basically you can create the partition table on the destination disk first. Then use the mode "part_to_local_part" to clone the partition one by one. If you meant "imaging", i.e., restore an image, you can create the partition table on the destination disk first, then use "restoreparts" to restore the destination partitions you want. You might have to deal with swap partition or uEFI BIOS boot entry manually.

Steven

mslinn commented 1 month ago

Steven,

Thanks for letting me know that at least I understand the problem properly.

Yes, I am talking about cloning, not imaging. I have two drives, from two completely different Linux systems that need to be partially cloned: all the contents of the drives need to be cloned, except one partition. The partitions withheld from cloning are not system partitions, they are data partitions. This must be a fairly common scenario, given that I have 2 very different systems that need partial cloning.

Clonezilla is capable of cloning an entire drive, including replicating the partition table verbatim or by modifying the overall space required. It is also capable of replicating the swap partition and uEFI BIOS boot entry. The manual steps you mention (swap and uEFI) are handled by Clonezilla somehow.

I would be happy to write up detailed instructions for how to accomplish partial drive cloning, if you are willing to guide me by answering specific questions. To simplify the problem, I do not intend to support the legacy systems that Clonezilla supports (this means GPT only), and am only interested in Clonezilla Live, so no BitTorrent support, etc.

You have mentioned the steps required at a high level. I have questions about each step:

  1. Replicating most of the partition table - the EFI system partition has flags that must be replicated. Which Clonezilla program(s) in sbin/ perform this function? I would like to look at them to see if it might be feasible for me to modify it/them to support the replication of all but a given data partition. By replication, I mean the creation of identical partitions without file systems.
  2. Replicating the uEFI BIOS boot entry - Which Clonezilla program(s) in sbin/ perform this function? I would like to look at them to see if it might be feasible for me to modify it/them to support this scenario.
  3. File system creation and copying - Although using mkfs and rsync is well understood, again the preference would be to use the existing Clonezilla program(s) in sbin/. Which programs are those?
  4. Swap partition - mkswap is easy to use. Both sbin/ocs-onthefly and scripts/sbin/ocs-functions invoke mkswap. It would be best to use the existing code somehow, unless that is impractical for some reason.
  5. part_to_local_part - The bash script sbin/ocs-onthefly has a function called ask_part_to_local_part. Is this what you were referring to? This bash script is quite large: 1562 lines. I have not studied it. Are there global variables that are set before this function is invoked?

Thank you, Mike