diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf
index 3be1552..b392d6d 100644
--- a/usr/share/rear/conf/default.conf
+++ b/usr/share/rear/conf/default.conf
@@ -409,6 +409,16 @@ PXE_REMOVE_OLD_LINKS=
# Default is empty which means prompting what to do next and after a timeout boot next option defined by BIOS
PXE_RECOVER_MODE=
+# Certain operation might need longer time to kick in and more retries might be desirable.
+# REAR_SLEEP_DELAY (in sec.) is general delay for operation.
+REAR_SLEEP_DELAY=1
+# REAR_MAX_RETRIES is maximum number of attempts that should be executed before operation is aborted.
+# Maximum timeout for operation calculates as REAR_SLEEP_DELAY * REAR_MAX_RETRIES
+# This retries / timeout operation is currently implemented only in get_disk_size (),
+# so if you have trouble with error messages like:
+# 'Could not determine size of disk <device> ...' tweaking of REAR_SLEEP_DELAY and REAR_MAX_RETRIES might help.
+REAR_MAX_RETRIES=5
+
##
# internal BACKUP stuff
##
diff --git a/usr/share/rear/lib/layout-functions.sh b/usr/share/rear/lib/layout-functions.sh
index 75a59bb..052a752 100644
--- a/usr/share/rear/lib/layout-functions.sh
+++ b/usr/share/rear/lib/layout-functions.sh
@@ -530,8 +530,7 @@ get_disk_size() {
local block_size=$(get_block_size ${disk_name%/*})
- [ -r /sys/block/$disk_name/size ]
- BugIfError "Could not determine size of disk $disk_name, please file a bug."
+ retry_command test -r /sys/block/$disk_name/size || Error "Could not determine size of disk $disk_name"
local nr_blocks=$( < /sys/block/$disk_name/size)
local disk_size=$(( nr_blocks * block_size ))
@@ -586,3 +585,25 @@ is_disk_a_pv() {
return 1
fi
}
+
+# retry_command () is binded with REAR_SLEEP_DELAY and REAR_MAX_RETRIES.
+# This function will do maximum of REAR_MAX_RETRIES command execution
+# and will sleep REAR_SLEEP_DELAY after each unsuccessful command execution.
+# It outputs command stdout if succeeded or returns 1 on failure.
+retry_command ()
+{
+ local retry=0
+
+ until command_stdout=$(eval "$@"); do
+ sleep $REAR_SLEEP_DELAY
+
+ let retry++
+
+ if (( retry >= REAR_MAX_RETRIES )) ; then
+ Log "retry_command '$*' failed"
+ return 1
+ fi
+ done
+ # Have no additional trailing newline for the command stdout:
+ echo -n "$command_stdout"
+}