New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added grub bootloader for USB #2655
Conversation
# in prep/USB/Linux-i386/350_check_usb_disk.sh | ||
|
||
[ "$RAW_USB_DEVICE" -a "$REAL_USB_DEVICE" ] | ||
BugIfError "RAW_USB_DEVICE and REAL_USB_DEVICE should be already set" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better avoid the ...IfError functions.
They do not work fail-safe, see the comment in
usr/share/rear/lib/_input-output-functions.sh
about "Using the ...IfError functions can result unexpected behaviour in certain cases"
currently at
https://github.com/rear/rear/blob/master/usr/share/rear/lib/_input-output-functions.sh#L773
We try to replace the ...IfError functions by plain bash code
where we find them when we change code
but we keep them as is in old code that we do not touch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I carried the check over from somewhere else. Will change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine wherefrom you copied it ;-)
cf. #2644 (comment)
In particular the USB bootloader setup code is rather old code
e.g. 50% of the code in output/USB/Linux-i386/300_create_extlinux.sh
is 10 years old (from 2011 according to what 'git blame' shows)
so large parts of the USB bootloader setup code is not in compliance with
https://github.com/rear/rear/wiki/Coding-Style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not 100% sure how to rewrite that so please double check my commit for that
grub_version=$($GRUB_INSTALL --version | awk '{print $NF}' | cut -c1-1) | ||
|
||
case ${grub_version} in | ||
0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See "Paired parentheses" in
https://github.com/rear/rear/wiki/Coding-Style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments at the code places
@DEvil0000 I appreciate the new USB_BOOTLOADER config variable Installing the bootloader of the ReaR recovery system during "rear mkrescue" With clearly named config variables like USB_BOOTLOADER |
@@ -0,0 +1,64 @@ | |||
# only run for grub | |||
if [ -z $USB_BOOTLOADER ] && [[ ! $USB_BOOTLOADER =~ grub ]]; then | |||
return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not undrestand the condition. I think
if [ -z $USB_BOOTLOADER ] && [[ ! $USB_BOOTLOADER =~ grub ]]
means
if $USB_BOOTLOADER is empty AND $USB_BOOTLOADER is not "grub"
but I assume output/USB/Linux-i386/300_create_grub.s should be skipped
if $USB_BOOTLOADER is empty OR $USB_BOOTLOADER is not "grub"
e.g.
# USB_BOOTLOADER='' ; if [ -z $USB_BOOTLOADER ] && [[ ! $USB_BOOTLOADER =~ grub ]] ; then echo no grub ; else echo grub ; fi
no grub
# USB_BOOTLOADER='grub' ; if [ -z $USB_BOOTLOADER ] && [[ ! $USB_BOOTLOADER =~ grub ]] ; then echo no grub ; else echo grub ; fi
grub
# USB_BOOTLOADER='foo' ; if [ -z $USB_BOOTLOADER ] && [[ ! $USB_BOOTLOADER =~ grub ]] ; then echo no grub ; else echo grub ; fi
grub
I think the test should be simply
if $USB_BOOTLOADER is not "grub"
i.e.
# Skip when USB_BOOTLOADER is not 'grub':
test "$USB_BOOTLOADER" = "grub" || return 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the empty is in there for empty beeing previous behaviour as described in the conf file comment.
the -z is very common and readable bash to me for empty checks.
the not equal check van be written differently of course.
@@ -1,3 +1,8 @@ | |||
# Only run for syslinux and extlinux | |||
if [ ! -z $USB_BOOTLOADER ] && [[ ! $USB_BOOTLOADER =~ syslinux|extlinux ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see where USB_BOOTLOADER is set to syslinux or extlinux.
Similar as https://github.com/rear/rear/pull/2655/files#r672040064
I think the test should be simplified to
# Skip if USB_BOOTLOADER is 'grub'
# see its counterpart in output/USB/Linux-i386/300_create_grub.sh
test "$USB_BOOTLOADER" = "grub" && return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does not need to be set since empty is previous behaviour but may be set by config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests are not right.
@@ -41,7 +41,7 @@ if has_binary grub-install grub2-install; then | |||
# What version of grub are we using | |||
# substr() for awk did not work as expected for this reason cut was used | |||
# First charecter should be enough to identify grub version | |||
grub_version=$($GRUB_INSTALL --version | awk '{print $NF}' | cut -c1-1) | |||
grub_version=$(( $GRUB_INSTALL --version | awk '{print $NF}' | cut -c1-1 )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The paired parenthesis are for the case
cases
not for the command substitution.
@DEvil0000 |
feel free to do changes. |
I have write access - this is why I asked you for permit.
so the pull request sources already belong to |
Strange. @rear/contributors Because USB_BOOTLOADER is a new config variable Currently I am thinking about something like:
This is currently only some offhanded idea... |
keep in mind that efi is not very specific - it may be used with different bootloaders and efi payloads and so on. |
Yes, I have had a look at output/USB/Linux-i386/100_create_efiboot.sh
to basically run output/USB/Linux-i386/100_create_efiboot.sh as is. If needed we may later further enhance things like
|
I think EFI boot setup and BIOS boot setup What I can see is that output/USB/Linux-i386/100_create_efiboot.sh So - as far as I can currently see from plain looking at the code - it seems I wonder if that makes sense? |
I did not test or change that configuration combination / path in software. There may be good reasons for this. In case of elilo.efi it does not run the grub config part in |
@DEvil0000
but it seems USB_REAR_DIR is nowhere used USB_REAR_DIR also appears in output/USB/Linux-i386/300_create_extlinux.sh Is creating USB_REAR_DIR in output/USB/Linux-i386/300_create_grub.sh |
Maybe the directory USB_REAR_DIR should be created elsewhere but it is used to store the kernel and initrd later as well as parts of syslinux config if syslinux is used. For one of the following scripts it needed to exist. |
@DEvil0000 What a mess that old USB related code is! |
tested output usb with:
on apu2 board (coreboot/seabios) - no efi
added option to write grub bootloader to usb (no efi)
it may not be perfect but a good starting point