[ "$(printf "%s\n" "$default_entry" | wc -l)" -eq "1" ] || \
fatal "more than one default entry in \"$conf_file\""
-if ! [ -f "$entries_dir/$default_entry" ]; then
- # The default entry does not exist anymore. Pick the entry
- # corresponding to the newest kernel then.
- default_entry="$(printf "%s" "$entries" | head -n1)"
-fi
+while ! [ -f "$entries_dir/$default_entry" ]; do
+ # The default entry does not exist anymore. Remove it and pick the
+ # entry corresponding to the newest installed kerne.
+ rm -f "$entries_dir/$default_entry"
+ entries="$(printf "%s" "$entries" | tail -n+2)"
+ default_entry="$(printf "%s" "$entries" | head -n1).conf"
+done
# Use the default entry to prepare the pattern for other entries
pattern="$(cat "$entries_dir/$default_entry")"