Skip to content

Conversation

@schabrolles
Copy link
Contributor

@schabrolles schabrolles commented May 20, 2016

1- Grub2: Using search --fs-uuid instead of hardcoded root='hd0,msdos1'

Actually we found that ppc64 and ppc64le are not aware of "hd0,msdos1", current grub2 rescue does not work without the above option in ppc64 and ppc64le. Since this search option is used even in x86 grub2 distro menu, so it would be better to handle as platform independent option.

By the way, this search option allows to use GPT formated disk ! Which is not the case of 'hd0,msdos1'

2- Changing the way REAR grub2 menuentry is created. By using the standard /etc/grub.d directory to store the REAR menu, we are sure that it will not be removed by a manual grub-mkconfig (or an automated one after a kernel upgrade.)

Actually we found that ppc64 and ppc64le are not aware of
"hd0,msdos1", current grub2 rescue does not work without the above option in ppc64 and ppc64le. Since this search option is used even in x86 grub2 distro menu, so it would be better to handle as platform independent option.
Using /etc/grub.d/45_rear to store REAR grub menuentry.
This prevent REAR menu entry to be erased is case of grub2-mkconfig (or grub-mkconfig) is run (like after a kernel update).
@schabrolles schabrolles changed the title Grub2: Using search --fs-uuid instead of hardcoded root='hd0,msdos1' Grub2: REAR Improvements proposal May 22, 2016
@gdha gdha added the enhancement Adaptions and new features label May 23, 2016
@gdha gdha added this to the Rear v1.19 milestone May 23, 2016
@gdha gdha self-assigned this May 23, 2016
fi

#Finding UUID of filesystem containing /boot
grub_boot_uuid=$(df /boot | awk 'END {print $1}' | xargs blkid -s UUID -o value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schabrolles I know of Linux systems where the /boot file system is not always mounted. Then the variable would be empty.
What happens in such cases? You would get an invalid grub entry.
Perhaps, foresee a sanity check here?
Gratien

Copy link
Contributor Author

@schabrolles schabrolles May 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdha. df /boot | awk 'END {print $1}' returns the file system on which /boot stands : either /boot (if it is a file system) or / (if it is only a directory).
So, if /boot is not mounted, the UUID return by the command will be / UUID (and not /boot).

grub-mkconfig has the same behavior. it uses grub2-probe --target=device /boot to get the name of the boot device. If /boot is not mounted, it returns / device instead and grub.cfg generation won't be good.
It is not a good idea to not mount /boot, grub-mkconfig can be automatically run after some packages upgrade (kernel for example); if /bootis not mounted, grub.cfg won't be updated.

Anyway, your point is correct and we should may be test if a directory like /boot/grub* exist.
If not, we can exist and avoid to generate a bad grub.cfg

#Test if /boot is mounted 
if ls -ld /boot/grub* > /dev/null 2>&1 ; then
    grub_boot_uuid=$(df /boot | awk 'END {print $1}' | xargs blkid -s UUID -o value)
    ....
else
    echo "Error: /boot is empty, or may be not mounted..."
    exit 1     
fi

Your feedback is welcomed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schabrolles You could make the test easier (and we use this a lot in rear):

ls -ld /boot/grub* > /dev/null 2>&1
StopIfError "/boot is empty, or may be not mounted..."

Thank you for reviewing the code once more.

Copy link
Contributor Author

@schabrolles schabrolles May 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdha

I check again the code, there is several test before to check /boot/grub/grub.cfg, verify that this one is writable etc ...
example line 66 67

[[ -w "$grub_conf" ]]
StopIfError "GRUB2 configuration cannot be modified."

Normally, if we pass this test, this mean that /boot/grub* exists (/boot is mounted or directory not empty). It is may be useless to add another test. What do you think ?

Another question : What is the difference between StopIfErrorand BugIfError ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you - testing once is enough.
BugIfError function is mainly used when we think there might be a bug report needed against rear. StopIfError is meant to force an exit out of rear when there is a condition not met (missing executable or file or something else which is not caused by a bug)

@schabrolles
Copy link
Contributor Author

schabrolles commented May 24, 2016

@gdha I apply the changes in 94_grub2_rescue.sh.

  • creating a /etc/grub.d/45_rear file in order to store rear grub menuentry, then grub-mkconfig create the complete grub.cfg file with rear included.
  • using fs UUID with fs search function to detect /boot instead of hd0,msdos1. rear grub is now working on GPT partitioned disk and on Power system (including PowerVM and PowerKVM)
  • /boot UUID is checked before adding it into grub.cfg.

I put a bit of mess in my git branch ... If it is an issue I can redo the job... just tell me what is best to do. (a new pull request ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adaptions and new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants