After searching a bit I could not find a simple and good howto to do that.
The following method should work for any Linux distribution (Ubuntu, Debian, Manjaro, Archlinux, Fedora…). Source and target systems must be on the same processor architecture (though transfer from 32bit to 64bit should work).
What you need:
- 2 live USB keys (or cds)
- To speed up data transfer: good quality ethernet cables (one cable between the 2 computers is OK), or a usb key/drive with a BIG ext4 partition. You can try over wifi, but it may be slow.
1. Boot source and target machines on live USB/CD
Any live USB/CD should be OK.
On the target computer, you will need a tool to partition your hard drive, like gparted.
rsync is also required for data transfer: it’s included in many live systems.
Ubuntu live cd is OK, Manjaro live cd too.
2. Partition your target hard drive
Use a tool like gparted to partition the target hard drive, with the same partitions as your source system (slash, swap, home…).
I recommend you to assign LABELs to your partitions: for the fstab, it’s easier than UUIDs.
3. Mount all partitions on both machines
On both systems, open a root terminal. Then, for each data partition (you can ignore swap):
mkdir /mnt/slash mount /dev/sdaX /mnt/slash
If you have a home partition:
mkdir /mnt/home mount /dev/sdaY /mnt/home
4. Transfer the data (network or usb)
This part may be tricky. Choose the method you prefer.
Network
- Setup the network. Test the connectivity with ping command.
The easier is to plug the PCs on a DHCP network (like your ISP box) so that you get automatic IP addresses. If you linked the 2 pcs with a single cable, you’ll have to setup the IPs with NetworkManager (static ips, or adhoc network). - On source system, as root, create a simple
/etc/rsyncd.conf
file:uid = root gid = root use chroot = no [all] path = /
- Then start the rsync daemon server:
rsync --daemon
- On target PC, for each partition:
rsync -avHX SOURCE_IP::all/mnt/slash/ /mnt/slash/
Don’t forget ‘/’ at the end of paths.
-a
will preserve many file attributes like owner and permissions,-H
will preserve hardlinks if any,-X
will preserve extended attributes like setuid. You may also add-A
if you are using acls. What is good with rsync is that you can stop and restart the transfer whenever you want.
USB
Prepare a USB drive with a BIG ext4 partition.
- Mount the USB partition on source system (
mount /dev/sdbX /mnt/usb
) - For each partition:
rsync -avHX /mnt/slash/ /mnt/usb/slash/
- umount, unplug and remount the USB disk on the target system.
- For each partition:
rsync -avHX /mnt/usb/slash/ /mnt/slash/
5. Change fstab on target system
As root, edit /mnt/slash/etc/fstab
For each partition (including swap), replace the first field with the new UUID or LABEL (it’s straightforward with LABELs):
UUID=the-long-uuid
, or LABEL=yourlabel
2 ways to get the UUIDs / LABELs:
ls -l /dev/disk/by-uuid/ blkid /dev/sdaX
6. Reinstall Grub
We will use a chroot (changed root environment) to be able to call the grub install inside the migrated system.
First, bind mount some system directories needed by grub, then chroot:
mount --bind /proc /mnt/slash/proc mount --bind /sys /mnt/slash/sys mount --bind /dev /mnt/slash/dev mount --bind /run /mnt/slash/run chroot /mnt/slash
Then install grub in the Master Boot Record of your hard drive, and update grub config file (with the new uuids…):
grub-install /dev/sda update-grub
7. Reboot target machine
That’s it! Your system should be working on the new computer now.
Feel free to comment if you encounter problems.