My machine is an UEFI enabled ubuntu 20.04, with three partitions:

/dev/nvme0n1p1 boot (grub2+initrd+kernel)
/dev/nvme0n1p2 OS
/dev/nvme0n1p3 home

I'm in a situation, that from time to time I need to attach a secondary USB HDD, which is an older replica of my integrated main NVME drive and reboot the PC.

The problem is that all partition names, their UUIDs and etc are identical on both HDDs and the UEFI BIOS upon booting the GRUB2 from the integrated main NVME HDD, will mark it as HD1 and the USB HDD is marked as HD0, thus initrd and kernel booting from the USB HDD, instead of the NVME HDD, which has the latest initrd and kernel. This is the row in my grub.cfg, which makes the issue

insmod efi_uga
insmod efi_gop
insmod gzio
insmod ext2
insmod search_label
insmod search_part_label
search --no-floppy --set root --part-label some_boot_label --hint-efi=hd0,gpt1

Do you know of a dynamic way to identify (search) the nvme0n1p1 and use it, instead of hd0,gpt1 which is static?

device.map will not work, as it is a static file (hostdisk//dev/nvme0n1,gpt1) and reorderring occurs, when USB is inserted. My only guess is to disable the *hci.mod modules, which load the USB devices, but not sure if this is a good idea.

Your help is very welcome

  • You just cannot have duplicate UUIDs when you boot. Better to reinstall on external & sync /home, installed apps & perhaps some settings in /etc from your normal backup. You may be able to change UUIDs in external and totally reinstall grub in external. External needs to have its own ESP and fstab in external needs to use that ESP before reinstalling grub.
    – oldfred
    Sep 29, 2021 at 22:48
  • I can surely implement this, but later HDD clones, will require a lot of manual efforts on my side, I have to do them each time I do a replica of the NVME drive. As grub2 modules configuration is very limited, my question is focused on finding a way to distinguish between two block devices and boot only from the NVME type of block device.
    – tio78
    Sep 30, 2021 at 9:18
  • You have to start before grub. Your UEFI uses the unique GUID or partUUID of your ESP - efi system partition to know which ESP to use to find boot files. You cannot have duplicate GUID as well as UUIDs. And external drive can be directly booted from /EFI/Boot/bootx64.efi. But with full install that uses the same grub.cfg as an Ubuntu entry. To see partUUID. lsblk -e 7 -o name,fstype,size,fsused,label,partlabel,mountpoint,uuid,partuuid I can do a total new install in about an hour. If you do an install & rsync your /home & and data partitions it will be very quick after the first time.
    – oldfred
    Sep 30, 2021 at 14:07


You must log in to answer this question.

Browse other questions tagged .