Bug#913655: grub-pc: id caching in postinst does not work
Jeroen Coekaerts
jeroen at coekaerts.be
Tue Nov 13 15:26:05 GMT 2018
Package: grub-pc
Version: 2.02+dfsg1-8
Severity: minor
On a system with almost a thousand devices (don't ask) I noticed that installing grub
takes over an hour. It was sorting device ids the whole time.
In the post install script there is a "cached_available_ids" variable set to prevent this.
But the available_ids() function gets called in a subshell like this
for id in $(available_ids) ...
so the cache variable is never set in the main script.
If I change the script to call it once in the mainscript it gets fast
--- /var/lib/dpkg/info/grub-pc.postinst 2017-02-11 16:09:19.000000000 +0100
+++ grub-pc.postinst 2018-11-13 16:12:51.884531798 +0100
@@ -44,7 +44,6 @@
# This only works on a Linux system with udev running. This is probably the
# vast majority of systems where we need any of this, though, and we fall
# back reasonably gracefully if we don't have it.
-cached_available_ids=
available_ids()
{
local id path
@@ -55,14 +54,12 @@
fi
[ -d /dev/disk/by-id ] || return
- cached_available_ids="$(
- for path in /dev/disk/by-id/*; do
- [ -e "$path" ] || continue
- printf '%s %s\n' "$path" "$(readlink -f "$path")"
- done | sort -k2 -s -u | cut -d' ' -f1
- )"
- echo "$cached_available_ids"
+ for path in /dev/disk/by-id/*; do
+ [ -e "$path" ] || continue
+ printf '%s %s\n' "$path" "$(readlink -f "$path")"
+ done | sort -k2 -s -u | cut -d' ' -f1
}
+cached_available_ids=$(available_ids)
but that probably not a universal solution.
The device_to_id() for each device looping over all ids is O(n^2) too so it is still slow ofcourse..
More information about the Pkg-grub-devel
mailing list