How do I migrate my main filesystem to a new drive?
I want to switch hard drives. How do I migrate my root FS from the drive it's on, to the new one, so that everything is exactly as it is?
3 answers
Gnome disks can create a disk image, and then restore it to the new one.
The new drive has to be same size or larger, although this is obvious. If it is larger, the partition will still be small, but I find it easier to resize it after the fact.
It's better if the sector size also matches: https://wiki.archlinux.org/title/Advanced_Format
There are also other tools listed in https://wiki.archlinux.org/title/Disk_cloning
Note that, if you want to clone the root filesystem, it will usually be necessary to boot from a Live USB and do the cloning from there. Disk cloning tools will generally require unmounting the original filesystem first, because "hot" cloning is much more complicated. Using a live boot makes it possible to keep the root filesystem unmounted (since the OS is no longer running from it). GParted offers a specialized (and small) Live USB for this purpose.
0 comment threads
I'll add a specific, simple way that worked for me:
- Create some kind of Linux Live USB
- Boot into Live OS
- Use
lsblk
andblkid
to figure out which drive exactly is the old and new one. Stay in the same Live session (don't reboot) in case the drives move around between boots. - Double and triple check, because if you mess up here you can lose all your data forever
- Suppose your old drive is
/dev/sda
and the new drive is/dev/sdb
. Go into a terminal, and typepv /dev/sda > /dev/sdb
.
When it is done, everything on your old drive will be copied exactly to the new drive. In fact, even partition UUIDs will be identical, which ordinarily is not supposed to happen - it's not a unique identifier if multiple partitions have it. So for example, if you have an fstab identifying partitions by UUID, this may not work right after you clone a drive in this way. My solution is to have a "follow up" process like this:
- After clone is done, shutdown the computer. Do not boot into your hard drive.
- Physically disconnect the old drive (pull out the data cable)
- Boot up from the new drive, and check that everything works as before, and shut down.
- Re-connect the old drive, and boot into the Live USB.
- Delete partitions on the old drive.
This way all your data will be on the new drive exactly as it was on the old, down to the UUIDs.
Of course, the new drive cannot be smaller for this to work. If it is larger, the partitions won't take up the whole drive. After the clone is complete, you can use some other partition tool to resize them so they can use the larger capacity of your drive.
0 comment threads
To migrate your main filesystem to a new drive, utilize disk cloning software or backup utilities like Clonezilla or EaseUS Todo Backup for a perfect transfer.
1 comment thread