Skip to content
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

Correctly choose /boot or / prefix for 'Relax-and-Recover' GRUB 2 menu entry #948

Merged
merged 1 commit into from
Aug 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions usr/share/rear/output/default/94_grub2_rescue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ is_true "$GRUB_RESCUE" || return
# (grub-probe or grub2-probe only exist in GRUB 2)
# in particular do not run this script when GRUB Legacy is used
# (for GRUB Legacy output/default/94_grub_rescue.sh is run):
type -p grub-probe >&2 || type -p grub2-probe >&2 || { LogPrint "Skipping GRUB_RESCUE setup for GRUB 2 (no GRUB 2 found)." ; return ; }
if [[ ! $( type -p grub-probe ) && ! $( type -p grub2-probe ) ]]; then
Copy link
Member Author

Choose a reason for hiding this comment

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

This was changed to make grub(2)-probe quiet.
Previous test made output (/usr/sbin/grub-probe) to rear logfile.

Copy link
Member

Choose a reason for hiding this comment

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

I liked to have the 'type -p' stdout output in the log file.
I thought having a verbose log file is good in general.
In contrast by default rear should be silent
on the terminal where rear was launched
cf. #929
Therefore I redirected stdout to stderr because
stderr gets logged but not shown on the terminal
cf. #885

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, OK
I just thought that pure /usr/sbin/grub-probe in log file (without any further information or date) is just typo ...

Will correct it then.

Copy link
Member

@jsmeix jsmeix Aug 2, 2016

Choose a reason for hiding this comment

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

No need to correct it.
I merged it as is.

It is a matter of personal taste what should be in the log.

In my old log it was:

++ type -p grub-probe
++ type -p grub2-probe
/usr/sbin/grub2-probe

In the current log it is:

+++ type -p grub-probe
++ [[ ! -n '' ]]
+++ type -p grub2-probe
++ [[ ! -n /usr/sbin/grub2-probe ]]

For my personaly eyes the current log looks
less clean than the old one - but again - this
is a matter of personal taste.

Copy link
Member Author

@gozora gozora Aug 2, 2016

Choose a reason for hiding this comment

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

Now I start to understand.
You are talking about "cleanness" when debugging enabled :-) that explains a lot.
I was looking more on situation, when debugging was disabled.

Copy link
Member

@jsmeix jsmeix Aug 2, 2016

Choose a reason for hiding this comment

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

Oh - yes - I should have mentioned
that I always run it as "rear -d -D ..."

I simply ignore the log (when things worked well)
but when something failed or looked suspicious
then I need the log with debug info already in it.

Cf. "Debugging issues with Relax-and-Recover (rear)"
in https://en.opensuse.org/SDB:Disaster_Recovery

But currently I miss stdout in the log because I would need
that to get the complete picture in the log. Therefore
I did #885

I need the complete picture in the log so that I could
better understand customer isssues when I only
get the customer's log file.

LogPrint "Skipping GRUB_RESCUE setup for GRUB 2 (no GRUB 2 found)."
return
fi

# Now GRUB_RESCUE is explicitly wanted and this script is the right one to set it up.
local grub_rear_menu_entry_name="Relax-and-Recover"
Expand All @@ -28,12 +31,28 @@ test -r $initrd_file || Error "Cannot setup GRUB_RESCUE: Cannot read initrd '$in
function total_filesize {
stat --format '%s' $@ | awk 'BEGIN { t=0 } { t+=$1 } END { print t }'
}

local kernel_name="rear-kernel"
local initrd_name="rear-initrd.cgz"

local boot_dir="/boot"
local boot_kernel_file="$boot_dir/rear-kernel"
local boot_initrd_file="$boot_dir/rear-initrd.cgz"
local boot_kernel_file="$boot_dir/$kernel_name"
local boot_initrd_file="$boot_dir/$initrd_name"
local available_space=$( df -Pkl $boot_dir | awk 'END { print $4 * 1024 }' )
local used_space=$( total_filesize $boot_kernel_file $boot_initrd_file )
local required_space=$( total_filesize $KERNEL_FILE $initrd_file )
local grub_boot_dir=$boot_dir

if mountpoint -q $boot_dir ; then
# When /boot is on its own partition
# i.e. a filesystem on /dev/sdaN
# that will be under Linux mounted as /boot
# then GRUB uses the filesystem on /dev/sdaN directly
# and in that filesystem there is no such thing as /boot
# so that for GRUB the files are in the root of that filesystem:
grub_boot_dir=""
fi

if (( available_space + used_space < required_space )) ; then
required_MiB=$(( required_space / 1024 / 1024 ))
available_MiB=$(( ( available_space + used_space ) / 1024 / 1024 ))
Expand Down Expand Up @@ -81,26 +100,7 @@ blkid -U $grub_boot_uuid > /dev/null 2>&1 || Error "$grub_boot_uuid is not a val
local grub_rear_menu_entry_file="/etc/grub.d/45_rear"
local grub_rear_menu_entry_linux_value=""
local grub_rear_menu_entry_initrd_value=""
# Different Linux distributions specify in /boot/grub2/grub.cfg
# the linux and initrd values differently
# see https://github.com/rear/rear/pull/942#issuecomment-235507831
# At least for now (until a generic solution is found)
# we differentiate depending on the Linux distribution.
# SUSE SLE and openSUSE use the absolute path for the linux and initrd values.
# It seems Red Hat and Red Hat based Linux distributions (e.g. CentOS)
# use the basename plus a leading '/' for the linux and initrd values
# see https://github.com/rear/rear/issues/703#issuecomment-235404491
# For SUSE SLE and openSUSE the OS_VENDOR is commonly set to 'SUSE_LINUX'
# (by default the 'lsb_release -i -s' output via the SetOSVendorAndVersion function
# or explicitly specified in /etc/rear/os.conf e.g. via RPM spec file).
# For all others we assume Red Hat behaviour as default/fallback:
if test "SUSE_LINUX" = "$OS_VENDOR" ; then
grub_rear_menu_entry_linux_value="$boot_kernel_file"
grub_rear_menu_entry_initrd_value="$boot_initrd_file"
else
grub_rear_menu_entry_linux_value="/$( basename $boot_kernel_file )"
grub_rear_menu_entry_initrd_value="/$( basename $boot_initrd_file )"
fi

# Create a GRUB 2 menu config file:
( echo "#!/bin/bash"
echo "cat << EOF"
Expand All @@ -116,9 +116,9 @@ else
fi
( echo " search --no-floppy --fs-uuid --set=root $grub_boot_uuid"
echo " echo 'Loading kernel $boot_kernel_file ...'"
echo " linux $grub_rear_menu_entry_linux_value $KERNEL_CMDLINE"
echo " linux $grub_boot_dir/$kernel_name $KERNEL_CMDLINE"
echo " echo 'Loading initrd $boot_initrd_file (may take a while) ...'"
echo " initrd $grub_rear_menu_entry_initrd_value"
echo " initrd $grub_boot_dir/$initrd_name"
echo "}"
echo "EOF"
) >> $grub_rear_menu_entry_file
Expand Down