Ubuntu – How to change UUID in the /boot/grub/grub.cfg

bootgrub2mountpartitioninguuid

I am asking how to change uuid in /boot/grub/grub.cfg, so that grub can load OS on a specified partition.

I have two disks:

  • SSD /dev/sda1 with uuid d7f0cf11-3edf-4859-b65a-3b5bc60ea7b9
  • HDD /dev/sdb1 with uuid 47d9205b-00a8-40e5-88d6-e8b9571799a7

Both disks contain the same content (a Ubuntu root) but different partition uuids, as content of sda1 is cloned from sdb1 by clonezilla

The problem is /boot/grub/grub.cfg, which is automatically generated, contains:

           if [ x$feature_platform_search_hint = xy ]; then
              search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos1 --hint-efi=hd1,msdos1 --hint-baremetal=ahci1,msdos1  47d9205b-00a8-40e5-88d6-e8b9571799a7
            else
              search --no-floppy --fs-uuid --set=root 47d9205b-00a8-40e5-88d6-e8b9571799a7
            fi
            echo    'Loading Linux 4.4.0-146-generic ...'
            linux   /boot/vmlinuz-4.4.0-146-generic root=UUID=47d9205b-00a8-40e5-88d6-e8b9571799a7 ro  quiet splash $vt_handoff

indicating that grub chooses Ubuntu root from sdb1 instead of sda1, while i want it to choose sda1.

I tried replace all 47d9205b-00a8-40e5-88d6-e8b9571799a7 by d7f0cf11-3edf-4859-b65a-3b5bc60ea7b9 directly, and then run update-grub, but then everything is reverted back.

So is there any other better solution? the /boot/grub/grub.cfg is actually generated automatically. If I detached the sdb1, grub was unable to launched, as it could not find the uuid of sdb1.

Thanks


Updates:

shijiex@shijie:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=d7f0cf11-3edf-4859-b65a-3b5bc60ea7b9  /               ext4    errors=remount-ro 0       1

#UUID=47d9205b-00a8-40e5-88d6-e8b9571799a7 /old_os               ext4    errors=remount-ro 0       2
# /backup was on /dev/sda5 during installation
UUID=d36e69de-3af8-4302-a2b1-f32c2538493d /backup         ext4    defaults        0       0
# /home was on /dev/sda7 during installation
UUID=95ffe5be-ed1c-4d2b-b745-e31ba62ca63d /home           ext4    defaults        0       2
#UUID=e2ae897d-62b1-45d3-a17a-49e7a1b8fbe7 /home           ext4    defaults        0       2

# /vm was on /dev/sda8 during installation
#UUID=222bf555-b2d3-4607-a856-f5fd785b1862  /vm            ext4    defaults        0       2
# /opt was on /dev/sda8 during installation
UUID=ffbc1ea0-f426-4def-9349-a6f68b486b2f  /opt       ext4    defaults        0       0
# /other was on /dev/sda6 during installation
UUID=657778bc-fde8-4261-9fe6-4134c6a7fb3f /other          ext4    defaults        0       0


# /other was on /dev/sda6 during installation
#UUID=6db98036-2350-4289-b9ef-8e0a2ae52eeb /win           ext4    defaults        0       2


# swap was on /dev/sda9 during installation
UUID=71c498b2-3484-4d5b-b64a-270cc352841b  none            swap    sw              0       0
#UUID=05f1ba29-4188-40d1-8597-de708b48ed50  /tmp           swap    sw              0       0

and blkid:

 shijiex@shijie:~$ sudo blkid 

[sudo] password for shijiex: 
/dev/sda1: UUID="d7f0cf11-3edf-4859-b65a-3b5bc60ea7b9" TYPE="ext4" PARTUUID="2fe05ff9-01"
/dev/sda3: UUID="95ffe5be-ed1c-4d2b-b745-e31ba62ca63d" TYPE="ext4" PARTUUID="2fe05ff9-03"
/dev/sda4: UUID="8d114eed-5ce4-4d6f-8a28-8a7092b01d46" TYPE="ext4" PARTUUID="2fe05ff9-04"
/dev/sda5: UUID="94b0fb65-f56d-426d-81f9-d05a8ac783eb" TYPE="ext4" PARTUUID="2fe05ff9-05"
/dev/sdb1: UUID="47d9205b-00a8-40e5-88d6-e8b9571799a7" TYPE="ext4" PARTUUID="0001c588-01"
/dev/sdb10: LABEL="New Volume" UUID="6db98036-2350-4289-b9ef-8e0a2ae52eeb" TYPE="ext4" PARTUUID="0001c588-0a"
/dev/sdb11: UUID="ffbc1ea0-f426-4def-9349-a6f68b486b2f" TYPE="ext4" PARTUUID="0001c588-0b"
/dev/sdb5: UUID="d36e69de-3af8-4302-a2b1-f32c2538493d" TYPE="ext4" PARTUUID="0001c588-05"
/dev/sdb6: UUID="657778bc-fde8-4261-9fe6-4134c6a7fb3f" TYPE="ext4" PARTUUID="0001c588-06"
/dev/sdb7: UUID="e2ae897d-62b1-45d3-a17a-49e7a1b8fbe7" TYPE="ext4" PARTUUID="0001c588-07"
/dev/sdb8: UUID="222bf555-b2d3-4607-a856-f5fd785b1862" TYPE="ext4" PARTUUID="0001c588-08"
/dev/sdb9: UUID="71c498b2-3484-4d5b-b64a-270cc352841b" TYPE="swap" PARTUUID="0001c588-09"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"

Best Answer

You indicated that you cloned your HDD to SDD. However when I look at sudo blkid and cat /etc/fstab, not much of it correlates. Partitions don't match. UUID's don't match. I suspect that you've done more changes than just a clone and boot.

Without knowing exactly what/how you did what you did, it's difficult to come up with a concise answer for you... but you can try this...

  • turn on your machine, and get to the GRUB menu
  • hit the e key to enter edit mode
  • use the arrow keys to locate "quiet splash"
  • find the UUID=xxxx at the beginning of that same line
  • change the entire UUID=xxxx portion to /dev/sda1
  • control+x or F10 to continue to boot after the edit
  • once booted, sudo update-grub, then reboot
  • enter the BIOS boot menu and select SDA to boot from, or change the boot order to CD-ROM/SDA/SDB/etc.
  • at the GRUB menu, select the proper disk to boot from
Related Question