3

Context

I have a laptop with a SATA (sdb/hd1) slot and an m.2 (sda/hd0) slot. I had an SSD on the hd0 slot with the boot and EFI partition, and an HHD on the hd1 with the /, /home and swap partitions on it.

I recently bought a bigger SSD to replace the old one. And when replacing it, I did a backup (using clonezilla) of all the partitions on the SSD, plus the /root partition on the HDD ; I then restored all those partitions on the new drive. I also kept the old / partition on the HDD in case a problem would occur.

I did those changes after the restore:

  • On the /boot/grub.cfg file, I changed all the lines referencing the old /root partition (/dev/sdxn) or its UUID (UUID=[old partition's uuid]) to reference the new one.
  • On /etc/fstab (on the new partition), I also changed all the UUID's of the old partitions to the new ones.

Problem

These changes allowed me to boot correctly on the new SSD, but after every update, the /boot/grub.cfg file goes back to referencing the old partition. I am guessing that there's still some file responsible for generating the grub configuration that still has the old partition informations, but I can't manage to find it.

Marco
  • 893
Blumer
  • 33
  • UEFI or BIOS install? If BIOS, look at this: #To see what drive grub2 uses see this line - grub-pc/install_devices: sudo debconf-show grub-pc # for BIOS with grub-pc But that does not exist with UEFI as it uses fstab for mount of ESP & /efi/ubuntu/grub.cfg in ESP has UUID of full grub in your install. – oldfred Jan 09 '21 at 15:19
  • UEFI, and the /efi/ubuntu/grub.cfg had the correct UUID. It appears I was having this problem because the two / partitions had the same UUID's, so both of them were added as GRUB entries but with exactly the same UUID and the old one was always the one chosen by grub – Blumer Jan 10 '21 at 14:01
  • You cannot have duplicate UUID. This is why I typically suggest a new install, so then you have new UUID and avoid issues. And if you restore from your backup, you can have confidence that your backup procedure is complete. And just in case you still have old install. Also does house clean of old logs and other cruft that builds up over time. You can change UUID on old install, but then it will not be bootable without reinstalling grub in it and editing several files including fstab with new UUID. – oldfred Jan 10 '21 at 15:43

1 Answers1

2

On Debian/Ubuntu, /boot/grub/grub.cfg is normally auto-generated by grub-mkconfig, which is invoked by update-grub on every kernel update.

grub-mkconfig gets its configuration from /etc/default/grub, and uses scripts in /etc/grub.d/ directory to build up the /boot/grub/grub.cfg file. You did not mention checking these locations, so you should do that. Both places may contain customizations.

On an UEFI system, there is also /boot/efi/EFI/ubuntu/grub.cfg which contains the UUID of the filesystem that contains the /boot/grub directory (whether it's the root filesystem or a separate /boot filesystem). This file just instructs grubx64.efi to find that filesystem and read the "real" GRUB configuration file from there.

telcoM
  • 96,466
  • I did some tests with the /etc/grub.d/os-prober script, and I noticed that it was always detecting the two partitions, but they had the same UUID (clonezilla restore must have done so), and were both referenced by their common UUID on both entries on GRUB. I generated a new UUID for the old partition, and now I have two grub entries that work correctly for both. Since the problem was more about me not noticing the UUIDs and less about grub, should I just delete the question or edit it to be more clear about that ? – Blumer Jan 10 '21 at 14:09
  • 1
    When cloning a partition, the default assumption is that the new one will be 100% identical to the original... including any filesystem UUIDs. When cloning an entire disk, any UUIDs in the partition table will likewise be copied, unless you specifically take steps to re-uniquify them. This question has a list of filesystem-specific commands for changing the UUIDs. I'd suggest not deleting the question, as it might be helpful to someone else. – telcoM Jan 10 '21 at 19:08