1

I read somewhere that after using rsync to copy a partition from one device to other one, it is important to edit the UUID, since devices cannot coexist with the same UUID.

Is it true? How do I do it?

1
  • 2
    rsync works on files located on a file-system, the UUID is related to the file-system itself and is a lower level than the files that can then be stored on it. Different levels of the 'stack'
    – guiverc
    Nov 22, 2019 at 23:48

2 Answers 2

5

rsync does not copy partitions

rsync is a file and folder copying/syncing tool. It is great for syncing a local folder with a folder in a remote computer or backing up folders and files in one computer to another computer.

One thing it does not do is clone a partition. Therefore there is no need to worry about UUID of the partitions while using rsync.

Use gparted (or dd) to clone a partition

If you want to copy a partition, use GUI gparted or commandline dd. It will make an exact copy of the original partition with the exact size and free space as in the original. The copy will also have the same UUID.

This is a problem when a system tries to mount a partition by its UUID, such as using the /etc/fstab file and finds two partition with the same UUID. If the original and the copy are in two different computers, or if the copy replaces the original then the same UUID should not be a problem.

To give the copied partition a new UUID from within gparted:

  1. Select the copied partition. Make sure it is not mounted
  2. Go to Partition in the top menu or right click on the partition in the diagram
  3. Click on New UUID
  4. Click Apply to make the change

To assign a new UUID using the command line (for ext4 partitions only)

$ tune2fs -U $(uuidgen) /dev/sdXN

or

$ tune2fs -U random /dev/sdXN

where X is a letter, and N is a number specific to the partition of interest.

See answers to this question in Stackexchange for more on changing UUID using the commandline.

Hope this helps

14
  • 1
    Note that copying a partition or disk with dd and dc3dd for that matter will also copy the UUID(s) which may need to be changed
    – Elder Geek
    Nov 23, 2019 at 0:29
  • Thanks @EldeeGeek! This is a good point. I will add a section for command line based partition copying and UUID changing section based on your link.
    – user68186
    Nov 23, 2019 at 3:46
  • 1
    If newer gpt partitioning best not to copy just one partition. You also have GUID in the partition that must match primary & backup partition table. If you do copy it then you also have to update/change GUIDs.
    – oldfred
    Nov 23, 2019 at 3:47
  • 1
    @user68186: Do not know about gparted and copying GUIDs. I think it was a answer by Rod Smith who posts here and is author of gdisk on copying partitions. You can copy entire drive, but safer with partition to create it and copy data. Rsync has many, many parameters see man rsync. My first bash file with rsync commands, I included the description of parameters so I could remember what I was doing.
    – oldfred
    Nov 23, 2019 at 14:53
  • 1
    If not sure what parameter does always check. -H preserve hard links, not seen that normally used and n is dry run or no changes. Your -a excludes -H so it do not know which is is really using. askubuntu.com/questions/545655/…
    – oldfred
    Nov 23, 2019 at 16:42
3

rsync can clone your entire /

But with both rsync and dd or another cloning method you must change /etc/fstab and /etc/default/grub and by extension /boot/grub/grub.cfg for Ubuntu to work properly.

From this script: Bash script to backkup/clone Ubuntu to another partition

rsync is called like this:

rsync -haxAX --stats --delete --info=progress2 --info=name0 --inplace  \
      /* "$TargetMnt"                                                   \
      --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}

Notice the many directories that you do not want to copy specified with the --exclude directive. These directories are either recreated at boot time (virtual file system) or are pointers to other partitions (like /mnt and /media). You might also want to exclude the Trash folder from copying too.

After rsync completes you need to change the aforementioned files like this:

sudo sed -i "s/$SourceUUID/$TargetUUID/g" "$TargetMnt"/etc/fstab
sudo sed -i "s/$SourceUUID/$TargetUUID/g" "$TargetMnt"/boot/grub/grub.cfg
sudo sed -i "s/quiet splash/nosplash/g" "$TargetMnt"/boot/grub/grub.cfg

Where:

  • SourceUUID= The UUID of your current partition
  • TargetUUID= The UUID of your target / clone partition
  • TargetMnt= The mount point of your clone partition
  • s/quiet splash/nosplash/g line is optional so that when you boot your clone you see a difference with system messages displayed and no splash screen.

Finally to add a GRUB menu option pointing to your new cloned Ubuntu use:

sudo update grub
1
  • 1
    This is a valid point. Even though rsync does not copy partitions, it can copy all the contents of a partition. If that copied partition happens to be a root files system (/) partition. One would need to change reference to the UUID of the source partition to the new destination partition's UUID within the copied files so that the system files can work properly and use the new partition as the system partition.
    – user68186
    Nov 24, 2019 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.