r/linuxquestions • • 20d ago

Support Is cloning a linux drive (including OS, specifically fedora) safe? in the instance of transferring the contents to a different drive.

I am buying a new laptop and I need to transfer the contents of the old one, when I moved away from windows I had to copy manually anything I wanted saved, but I was hoping this is not the case with linux, is it? Or are there more efficient ways?
EDIT: Thank you all immensly for the help! I appreciate it a lot!

5 Upvotes

33 comments sorted by

8

u/DroiidBro 20d ago

Cloning a storage drive to other it's normally safe, but be aware that the second drive preferably must be the same storage size that your primary or bigger. Mostly to prevent any issues with the partitions. (You can also try to shrink your original partitions first so that way you could clone it to a smaller drive or reduce the time of cloning specifying the max size the tool must clone)

1

u/iu1j4 20d ago

I would not recomend shrinking if you have no backup. First rule if you would like to be safe - dont touch / modify original drive before you dont have another copy of it. Rule number two: dont keep your backup in the same computer when you operate on new drive - keep it outside the pc. If you can not take off tour drive - make spare copy to usb drive and then keep it in safe place. Do not experiment when you have no spare copy safe.

1

u/Particular-Poem-7085 20d ago

this can be taken further, don't keep the copy in the same building.

13

u/Grand-Satisfaction55 20d ago

I prefer to do a fresh install. Keeps my system clean rather than having those apps that I installed and never used again from taking up space.

But Clonezilla will do what you are asking about. It doesn't destroy the data from the original drive so there's no harm.

4

u/ungabunga-engineer 20d ago

generally yes. boot into a live usb, use the lsblk and dd commands to clone one drive to another

3

u/ipsirc 20d ago

s/dd/rsync/

1

u/hexdump74 20d ago

No, you'll loose the partitions table, uuid, etc...

2

u/ipsirc 20d ago

If you can't create partitions on your own, you shouldn't start cloning a system.

2

u/hexdump74 20d ago

Why create manually the partititions when you can simply dd the whole disk ?

2

u/ipsirc 20d ago edited 20d ago
  1. I assume your drive isn't full, so it's useless to copy zeroes. (it can be much faster)
  2. If the new device is not similar in 1:1 C/H/S, then the partition alignment can easily cause performance degradement + if you have to resize partition+filesystem after dd, then rather you can start creating new partitions+fs with the same effort.
  3. Copying the files is equivalent to a defragmentation process, so you'll gain a performance boost as well on new filesystem.

edit:

4. It's unsafe, if you're using btrfs, because you can easily stuck in a duplicated UUID collision which can result in various exotic effects aftermath. ( https://marc.info/?l=linux-btrfs&m=139881549909546&w=2 , https://lkml.iu.edu/hypermail/linux/kernel/2601.1/12546.html )

5. You can run rsync on an online running system, even copy the rootfs (/); you don't have to boot from usb and dd-ing the umounted filesystem. (less time, more convenient)

6. If any errors occur during the copying process (crash, power outage, etc...), rsync can easily resume the process, while you have to restart from beginning if you used dd (and you'll loose time again.).

1

u/fllthdcrb Gentoo 20d ago

If the new device is not similar in 1:1 C/H/S, then the partition alignment can easily cause performance degradement

This implies that filesystem drivers are somehow aware of drive geometry and allocate accordingly. Isn't this information hidden by LBA?

while you have to restart from beginning if you used dd

TBF, it is possible to resume when using dd, if you used status=progress to begin with. It's just a more manual thing, and obviously, easier to screw up.

1

u/ipsirc 20d ago

This implies that filesystem drivers are somehow aware of drive geometry and allocate accordingly. Isn't this information hidden by LBA?

The sector size may not hidden. However, it is still worth recalculating the start and end points of the partitions.

https://pieterbakker.com/optimal-disk-alignment-with-parted/

https://en.wikipedia.org/wiki/Partition_alignment

TBF, it is possible to resume when using dd, if you used status=progress to begin with. It's just a more manual thing, and obviously, easier to screw up.

You do realize, though, that this is highly theoretical, right? I can’t imagine anyone sitting there glued to a progress bar for hours, only to be able to say—from memory, in the event of a sudden power outage—exactly where they should resume from. Rsync handles it fully automatically.

1

u/fllthdcrb Gentoo 20d ago

The sector size may not hidden. However, it is still worth recalculating the start and end points of the partitions.

https://pieterbakker.com/optimal-disk-alignment-with-parted/

https://en.wikipedia.org/wiki/Partition_alignment

Of course, partitions should be aligned on 1 MiB boundaries. But you brought up CHS. I'm just wondering why a device with a different CHS geometry would be a real problem, if a filesystem driver can't allocate according to it and therefore would be just as likely to misalign the data in the first place as a copy would be to misalign it.

(This is not to argue for using dd, BTW. I generally agree with what you were saying. It's just this one point that doesn't make sense to me.)

1

u/ipsirc 20d ago edited 20d ago

Ok, Now I'm sure it's an outdated practice nowadays, but back then you have to align the partitions to cylinders.

"By the mid-1990s, hard drive interfaces replaced the CHS scheme with logical block addressing (LBA), but many tools for manipulating the master boot record (MBR) partition table still aligned partitions to cylinder boundaries; thus, artifacts of CHS addressing were still seen in partitioning software by the late 2000s." - https://en.wikipedia.org/wiki/Cylinder-head-sector

In my defence, I was already using rsync back then for cloning systems. I apologize for being a boomer.

3

u/Wally-Gator-1 20d ago

Is it safe: yes. Is it doable: yes. Should you do it: no, because the hardware and the drives identifiers will be different. Do a fresh install and move a backup of /etc (configs), /home directory and any directory with user content.

2

u/Klutzy_Cat1374 20d ago

A clean install and copying of the data over to the new drive will fix any broken things. Just don't use Windows to clone a Linux drive because it will 100% not work (easily). Clonezilla has always worked well for me. Keep your old laptop for a while in case Nvidia drivers break the new system.

2

u/No_Base4946 20d ago

It's probably easier just to do a clean install and copy any data over. It won't take long, assuming you've got both disks in the same machine. Just remove the "old" disk while you're installing in case of accidents.

Copying stuff across on the face of it makes sense but then you either have to resize the partition which is a pain to do or live with wasting a chunk of disk space, and you'll still need to play about installing a new bootloader. It's just neater doing a clean install from scratch.

1

u/absnotkinkyreggae 20d ago

i think it will work.

you need to fix the bootloader at the UEFI firmware. search that and i think you will be good to go.

Some settings might need to be adapted if your network devices change names, etc.

1

u/xXEMO_POTATOXx 20d ago

Yes it's safe I have done it several times I distro hop alot to find my perfect setup I have several 250gb sata m.2 drives but only like 2 nvme m.2 drives so I test what I want on the sata m.2 and when I find a good setup I might copy it over to the nvme m.2 using DD yes I copy my active drive to my nvme but has never caused an issue for me just let the copy finish before you do anything.

1

u/Just_Badger_4299 20d ago

Is Clonezilla (on a live USB) still a thing?

Otherwise, 'dd' is your friend. 😉 

1

u/Confident_Dragon 20d ago

I've just copied the drive using dd and checksummed everything, or just moved the drive. It was some time ago and it was Mint, but I don't see why things should be different. Maybe you'll need to fix bootloader or install drivers for GPU if you are migrating between Nvidia and AMD.

1

u/nhermosilla14 20d ago

Clonezilla works great for this, but this kind of instance is usually a good chance to do some cleanup starting fresh. If you must clone the entire thing, though, either Clonezilla or Rescuezilla, both work just fine.

1

u/erroneousbosh 20d ago

It's considerably simpler just to do a fresh install and copy what you want over. You probably want a lot less of your old crap than you think.

I know because I have a moving crate of old hard disks going back 20 years.

1

u/dronostyka 20d ago

No, it can explode both computers half way

1

u/chuggerguy Linux Mint 22.3 Zena | MATÉ 20d ago

I've used different methods. When I had Windows I would occasionally image my Linux device with Macrium Reflect. I no longer have Windows but I still have the rescue ISO it allowed me to make. I haven't used it for a long time but it worked just as well imaging Linux as Windows and the image could be restored to another device, either larger or smaller I believe.

A lot of drive manufacturers provide free migration tools. (making the transfer smooth increases the chance you'll buy from them again?)

I've never used Timeshift to migrate to a different device but it sound like it should work. Just create a snapshot on a second device (USB perhaps) and restore it to the new device. I haven't personally tested that but... maybe.

(image also shows my old Macrium Reflect rescue ISO which is about 600MB)

What I do now (using a script) goes something like this:

  1. Create the same partitions on the new device. (proportionate to the source partitions so as to use all space.
  2. Format each target partition to match the source partitions.
  3. rsync files from each source partition to their respective target partition.
  4. chroot into the target and make it bootable.

Others have mentioned clonezilla, dd, etc. Those are all good options, I'm just mentioning a couple more. I use Mint though; although I suspect they would be just as viable in Fedora, I can't say for sure.

Good luck.

1

u/oshunluvr 20d ago

Yes, I've done this very often in a production environment.

1

u/corpse86 20d ago

Just take a look at Rescuezilla.

1

u/lnxguy 20d ago

Use Clonezilla. Super easy.

1

u/3string 20d ago

I've cloned boot drives before, or yanked a boot drive from one machine and thrown it in another. Linux mint doesn't seem to care lol

1

u/skyfishgoo 19d ago

did you consider just moving the physical drive from one machine to the other?

but if use foxclone or rescuzilla to clone the drive (assuming the new one is the same size or larger), then it should boot from the new drive as if nothing changed.

1

u/iHarryPotter178 20d ago

Just reinstall the os and copy your personal data over. Cleaner.. 

2

u/ipsirc 20d ago

Dumber...

0

u/codeasm Arch Linux and Linux from scratch 20d ago

Its possible, but you better install a fresh copy of your os, you can make a installed softeare list on the old laptop, and try install these freshly on ghe new laptop and only copy config files, cooying your /home/[username] is supported and you can do so. Handy for most software and your customizations and configs. Maybe browser sessiosn/cookies and ssh keys transfer over fine too.

If home was a seperate partition, you could transfer it aswell.