0

My context (to avoid the XY problem)

I have a 500GB SSD that may be failing and is now too small. After a thorough backup, I will replace it with a 1 TB drive in the same slot and move the 500GB to the other slot for backup & less important data. I will use Clonezilla on a live USB to clone the old drive to the new drive, but that means the partitions will have identical UUIDs on both drives. So I will boot Kubuntu from a live USB and use gparted to generate new UUIDs for the partitions on the old drive. I will mount the old root partition and edit etc/fstab to change the duplicated UUIDs to the freshly-generated ones.

FYI the old drive has 4 partitions: nvme0n1p0 is /boot/efi, ...p1 is Ubuntu 20.04 as a backup (can't have too many), ...p3 is the 20.04 /home, and ...p4 is Kubuntu 22.04, including a /home mostly symlinked to the 20.04 /home.

The question

After duplicating a drive with Clonezilla in the same PC, generating new UUIDs for the partitions on one of the drives, and updating fstab, you still need to tell GRUB the new UUID for the root partition on that drive, so that it can find /boot. How do you safely do that?

Research on existing questions & answers

There are two questions that look similar but are not, because the PC does not have identical, cloned partitions. Repair Grub after Clonezilla concerns transfers between PCs; How to configure the fstab and grub file after restoring Ubuntu with a clonezilla image deals with restoring a partition.

The closest earlier question asked about Moving entire Linux installation to another drive. The answers recommend using Clonezilla, editing fstab and updating GRUB, so that is the plan, as explained above. But as thomasrutter puts it in one of the comments, "I feel as if 99% of the complexity in this is contained within the innocent-sounding 'install grub to the new drive'." This question is more narrowly focused on that 99% of the complexity, following the procedure suggested in the top answer to the relevant question on Stack Exchange Meta.

There was more help in Clonezilla Copy Ubuntu 20.04 install to another computer. The only answer explains how to edit fstab but does not address GRUB. However, a helpful comment points to an earlier question, How to change UUID in the /boot/grub/grub.cfg. This is superficially similar to this one, but there are two significant differences.

Firstly, the question assumes that the best procedure is to manually edit /boot/grub/grub.cfg. But this file can only be read, never mind written, by root, and begins "DO NOT EDIT THIS FILE" (capitals in original). Ubuntu's GRUB documentation says "the grub.cfg file is not normally edited directly" and warns that "manual edits are subject to being overwritten by the system". These are the Ubuntu equivalent of a warning sign that "here be dragons": editing this should be a last resort. So that assumption may be unwarranted or even harmful, and indeed the questioner found that their edits were being overwritten. The assumption also means that the question is suboptimal for other Ubuntu users, since users may not find it until they have started to go down the wrong path. Secondly, the accepted answer says that the question did not accurately describe the current state of that user's system, which causes some confusion in the answers.

User WinEunuuchs2Unix left comments under those posts suggesting a completely different approach. Instead of using Clonezilla, they suggest using a Bash script they have kindly written that clones the root and /home partitions and uses sed to edit fstab and grub.cfg. The script is in this answer, where it has been updated to 20.04 Focal, and in this GitHub repository. However, there is little evidence that this script is well-tested and maintained. There is one recent bug report reporting it runs well, but there is also a bug report which draws attention the fact that this script does not clone the /boot/efi partition, which is critical for my use case, and that the instructions for the script are vague on that point. That bug report was closed (by the reporter) without the instructions being updated, which is concerning. In addition, it to edits grub.cfg directly, bringing in the concerns raised above. So this question is limited to duplication with Clonezilla.

ioMatrix's answer to the grub.cfg question appears to give a simpler way to configure GRUB. It says to add the following line to etc/default/grub:

GRUB_DEVICE_UUID=***INSERT NEW UUID HERE***

and then run sudo update-grub. This looks perfect! However, there are three concerns. The first is which /etc/default/grub you should be editing. If you have duplicated a drive with Clonezilla, you shouldn't be booting from either drive while they have identical UUIDs, so you need to run from a live system in order to generate fresh UUIDs & configure GRUB. If you apply this answer on the live system, the /etc/default/grub on the duplicated drives is unchanged and the next time you run update-grub on the Ubuntu system using the fresh UUIDs, you will lose the change. So I think you would at least need to boot the live system then chroot to the root partition with a fresh UUID. Secondly, the GRUB_DEVICE_UUID key is not mentioned at all in the configuration sections of the GRUB manual nor anywhere in the Ubuntu documentation. There are a few references to it elsewhere on this site, but I am nervous about relying on an undocumented feature. Thirdly, the answer says "This won't change the hint entry for search but that won't match anyway so it should work. If someone wants to research a way to alter that part, I would be curious to know." I don't understand this at all, but it suggests that ioMatrix doesn't fully understand the command either.

Even after GRUB has been updated with the new UUIDs, it is possible that the wrong version of Ubuntu will be started by default, but answers are provided in How to change the order on my dual booting distros.

Matthew
  • 515
  • 1
    I always suggest a new install & restore from your backup. Verifies you have good backup while you still have old install to get any missing info. This user just did something similar. https://ubuntuforums.org/showthread.php?t=2491830 You may need to chroot or use Boot-Repair's advanced mode to reinstall grub in your new install after changing UUIDs in fstab. – oldfred Oct 25 '23 at 19:25
  • I think you are massively overthinking this. On which drive are you going to change the UUID’s ? In the first paragraph you say the old drive, in the third paragraph you say one of the drives. If you change the old drive then it should just work as long as the BIOS/UEFI is set to boot the new drive. I see no reason to need to update grub at all. If I were you I would make backups, clone the old to the new, remove the old, check the new boots correctly, add the old and wipe it. – PonJar Oct 26 '23 at 21:22
  • @PonJar Thank you for the fresh perspective. My context is changing UUIDs on the old drive, but the question arises with either old or new, does it not? Your solution requires me to open up my PC twice, and if the new drive doesn't work, I have an unbootable system. I'm trying to make a low-risk, low-stress step-by-step plan in advance. – Matthew Oct 27 '23 at 15:58
  • The suggestion to open up a second time is optional. It is purely to check that the new drive works correctly independently. With both drives in the PC it’s possible to boot using the old grub installation and the system on the new drive . You may only find that when you have wiped the old and can’t boot the new. This issue is much less likely on a UEFI installation so you could just ignore it. A bigger issue may be expanding your partition(s) on the new drive. You haven’t told us what the layout is. Before you do that bit do what @oldfred says and make good backups – PonJar Oct 28 '23 at 08:36
  • You are fully at liberty to edit grub.cfg. The warnings about not doing so are because the next time you update grub your changes will be overwritten – PonJar Oct 28 '23 at 08:39

0 Answers0