DEMO: System Transfer using rsync

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
User avatar
pbear
Level 9
Level 9
Posts: 2744
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

DEMO: System Transfer using rsync

Post by pbear » Wed Dec 04, 2019 9:21 pm

The question of how to transfer a Mint system to another hard drive and/or computer comes up fairly often, so for reference I’m going to describe how I did that with rsync when transferring my Mate 19.1 system to a new hard drive (twice the size of the old one). Could have reinstalled (I have very detailed setup notes), but was curioius how well this would work.

Others may find this strategy appealing if they don’t want to take the time to learn Clonezilla and/or CZ isn’t a good fit for their situation. For example, transferring to a smaller drive (HDD to SDD) is difficult with Clonezilla or any block copy solution. Also, rsync is more suitable if you want to modify your partition scheme for the new system. One advantage of doing this at file level is that rsync doesn't care tuppence about the partition table. You're copying from one place to another. To rsync, it's irrelevant whether the target is a partition or a subdirectory.

Notice this is more a demonstration than a complete tutorial. You’ll probably have to modify the steps for your situation, but something along these lines should work. For example, if attaching the target drive isn’t feasible because you’re transferring to another computer and its hard drive isn't easily removed, you could do two file transfers, first to a USB hard drive, then a second from that to the target system.

By the way, another way to do an rsync system transfer is to use Timeshift. See Demo. That method is easier than what I describe here, but also more limited. A hybrid solution would be to use Timeshift for the system and rsync for /home and/or partitions other than root.

--------------------------------------

There are four phases: Preparation, File Transfer, Edit fstab, and Install Grub. For reference, I did the work with the old drive still installed, so that was sda. Live session (below) was booted from sdb. Target drive, attached by SATA-to-USB cable, was sdc.

Preparation. Before the transfer, I updated the system so it was fully current. Also, I cleaned up a bit. Like moving your house, more efficient to cull before moving than after. You might want to trim or even delete Timeshift snapshots, as there's not much point to transferring those.

File Transfer. Boot a live session, preferably one matching the installed system. I have four partitions: System, Timeshift, Home and Data. System is the root partition. I didn't bother to transfer Timeshift, but I did include it on the partition table for the target drive. So, first step is to open GParted, set up partitions on the target drive and label them. Labels are very useful here, as they make the rsync commands simpler. For ease of reference, I changed the labels on the source drive to things like System-Old. Close Gparted.

o Open File Manager. Mount both the source and target partitions. Mount points will be something like /media/mint/System-Old. Then I ran a separate rsync command for each partition being transferred. You'll have to adjust, of course, for your partition labels.
sudo rsync -axHAX --info=progress2 /media/mint/System-Old/ /media/mint/System/
sudo rsync -axHAX --info=progress2 /media/mint/Home-Old/ /media/mint/Home/
sudo rsync -axHAX --info=progress2 /media/mint/Data-Old/ /media/mint/Data/
Per the man page, -a = archive (implies -rlptgoD, i.e., recursive (include sub-directories); copy symlinks; preserve permissions, timestamps, groups, owner, devices and specials); -x = one file system (don’t cross filesystem boundaries); -H = preserve hardlinks (symlinks covered by -a); -A = preserve Access Control Lists; -X = preserve extended attributes. Not sure actually need all those, but recommended by various sources. Using sudo because copying as user “mint”; no need for a password, though, as it’s a live session. Experienced rsync users might notice the absence of exclusions like /sys and /proc for the root partition; again, that’s because it’s a live session.

o FYI, info=progress2 provides feedback to confirm command is running. Note: % complete refers to each file, so pretty much useless. If want to monitor overall progress, notice aggregate size of files being copied beforehand and compare with amount completed at any point in time.

o To confirm copy, run each command again (use up-arrow to retrieve); should go very quickly as mostly just comparing file lists and attributes.

Revise fstab. Need to revise /etc/fstab with new UUIDs. Run sudo blkid to generate list. Open fstab with sudo nano /media/mint/System/etc/fstab. Or, for a GUI text editor, you could use xed admin:///media/mint/System/etc/fstab. Copy in new UUID for each mount point. Close and save. Note: fstab is a configuration file used by the system to mount partitions at boot. For more information, see man page, Ubuntu Help and How-To Geek. It needs to be modified here because the file as transferred refers to the old hardware.

Install Grub. Here's where it gets fun! To install Grub to the target drive from a live session, we need a moderately advanced tool called chroot, which permits the live session to act as root of the target drive. Recommendations vary for how exactly to install Grub with chroot. I based my commands mainly on askubuntu and How to Ubuntu, with some tweaks for the UEFI scenario I worked out by trial-and-error.

o BIOS. As mentioned, in my case, target was sdc, of which the first partition (sdc1) was root.
$ sudo mount /dev/sdc1 /mnt
$ for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
$ sudo chroot /mnt
# grub-install /dev/sdc
# update-grub
# exit
$ for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
$ sudo umount /mnt/boot/efi
$ sudo umount /mnt
FYI, the second line is merely a compact way of binding mount points. It's the equivalent of four lines in the form sudo mount --bind /dev /mnt/dev, etc. The third line from the end is the same thing in reverse, i.e., sudo umount /mnt/sys, etc. Try not to get bogged down in how chroot works or why. It's black magic, just roll with it. Actually, it's a natural extension of the Linux model, where root = all powerful admin. BTW, sudo isn’t needed in the chroot environment because, as far as the target is concerned, chroot is root.


o UEFI. My Mint system is BIOS, but here’s how to do the same thing in UEFI. First, you need to install grub-efi-amd64 in the live session, so open Terminal and run apt install grub-efi-amd64. (Curiously, this package is in the ISO - you don't need an internet connection to get it - but it has to be installed manually to the live session.) Now you can run pretty much the same chroot commands as for BIOS install, except you also have to mount the EFI partition. Assuming the EFI partition is sdc1 and the root partition is sdc2:
$ sudo mount /dev/sdc2 /mnt
$ sudo mount /dev/sdc1 /mnt/boot/efi
$ for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
$ sudo chroot /mnt
# grub-install /dev/sdc
# update-grub
# exit
$ for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
$ sudo umount /mnt/boot/efi
$ sudo umount /mnt
If transferring from a BIOS computer to a UEFI computer, there are two extra steps. First, you need an EFI partition, at least 200 MB, formatted fat32 and flagged boot/esp. Second, you’re missing a folder on target which the Grub installer needs and apparently isn’t programmed to create. After installing the grub-efi-amd64 package, open File Manager as Administrator; from View, open Extra Pane; in the left pane, navigate to the usr/lib/grub folder of the live session; in the right pane, navigate to the same folder on target; right-click x86_64 in the left pane and copy to the right pane; close File Manager. I’ve not seen this documented anywhere, but spent a lot of time on a similar problem in the context of full install to USB drive. There might be another solution, even a more elegant one, but this one does the job.

Cleanup. Shut down the live session. Remove the old hard drive and install the new one. Boot (fingers crossed). You may find (I did) that Mint is listed as Ubuntu in the Grub menu. Running sudo update-grub will take care of that. Also, you probably want to take a manual Timeshift snapshot, so you have a baseline as of the transfer date.
Time flies like an arrow. Fruit flies like a banana.
If your problem has been solved, please edit the thread title.

Post Reply

Return to “Tutorials”