My root partition was on /dev/sda1 and I changed the root partition to /dev/sda2. I updated the entry in /etc/fstab with the UUID of /dev/sda2.

But, I am not sure, how would the grub know that the root partition has changed to the new UUID i.e. /dev/sda2? Where else should changes be made apart from /etc/fstab, so that the grub can locate the root partition and hence boot the system?

Since, I want to learn stuff, I would also like to know the steps other than a simple command update-grub.

Do I have to change things somewhere else?

I am just running Linux.

  • Interesting to get a downvote without any explanation. – infoclogged Dec 12 '18 at 14:51

Assuming you are using grub2, the most important configuration file is grub.cfg (usually located in /boot/grub directory for bios based systems and /boot/efi/EFI/<os name>/ for efi systems). When computer starts grub follows instructions from that file. This is just a text file, so you can edit it by hand, or use some automatic tool (a shell script) grub-mkconfig (a.k.a. grub2-mkconfig) which creates configuration according to rules defined in a /etc/default/grub file and /etc/grub.d/ directory.

Anyway, if you've changed root partition there are a few things to take care of. First of all linux kernel parameters: grub directly is not affected by root partition, but it needs to pass correct path to the kernel, so look for a line like this

linux /vmlinuz-4.19.5 root=/dev/sda1

and change it to /dev/sda2.

It can also be passed in UUID way:

linux /vmlinuz-4.19.5 root=UUID=abcdefgh-ijkl-mnop-qrst-uvwxyz

You can test your root UUID with grub's command:

grub-probe --target=fs_uuid /

Second thing to check/change is a kernel file itself. It can reside on separate partition (usually /boot), or on root (/) one. In later case you need to search for a line

set root='hd0,gpt1'

and change gpt1 to gpt2. (I assumed here that you have only one disk hd0 and you are using GUID partition table, a standard nowadays).

Depending on you configuration you may also need to change filesystem UUID and a hint string to find proper path to the kernel. It could look like

search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt1' --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci0,gpt1  abcd-efgh
search --no-floppy --fs-uuid --set=root abcd-efgh

New UUID you already know, use grub-probe --target=hints_string / to find proper value of hints-string.

  • 1
    For what it's worth, on EFI installations grub.cfg is located under: /boot/efi/EFI/fedora/grub.cfg (in my case I use fedora, but insert your distro there). The command would also be grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg. Great answer though! :) – bgregs Dec 12 '18 at 16:22

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.