Closed Zesko closed 1 year ago
The issue would be the GRUB header /etc/grub.d/00_header
which would create the same comment with no snapshot-entry , but all snapshot-entries are outside of /boot/grub/grub.cfg
, they are in /boot/grub/grub-btrfs.cfg
I did a trick to remove the old grub.cfg and create a new grub.cfg when update grub
I created a new executable GRUB script:
#!/bin/sh
if [ -f "/boot/grub/grub.cfg" ]; then rm /boot/grub/grub.cfg fi
The script name "00_clear_grub_cfg" has the highest priority in GRUB order.
2. <kbd>$ sudo chmod +x /etc/grub.d/00_clear_grub_cfg</kbd>
3. <kbd>$ sudo grub-mkconfig -o /boot/grub/grub.cfg</kbd>
I think the trick is not recommended.
Maybe you have idea that duplicate comment should be cleaned away?
This trick is unreliable. I get the warning when the grub.cfg was initially deleted.
grep: /boot/grub/grub.cfg: No such file or directory
WARNING: 'grub-mkconfig' needs to run at least once to generate the snapshots (sub)menu entry in grub the main menu. After that this script can run alone to generate the snapshot entries.
Create a new executable GRUB script:
#!/bin/sh
file=/boot/grub/grub.cfg
# Find all duplicate lines and store in array
duplicates=$(grep -n "41_snapshots-btrfs ###" $file | cut -d: -f1)
count=0
i=0
# Loop through duplicates and remove all but the first two comments
for line_num in $duplicates; do
if [ "$i" -gt 1 ]; then
# Delete the line if it contains "41_snapshots-btrfs ###"
line_num=$((line_num - count))
sed -i "$line_num"d "$file"
count=$((count + 1))
fi
i=$((i + 1))
done
It removes all duplicates, leaving the first two comments.
Thanks for your issue and also the provided solution. I am a bit hesitant to use it, though, because it is rather fighting the symptom down the line instead of going after the root cause.
Have you found out what is causing this?
I too am seeing the same entries added at the end of grub.cfg after every run of grub-mkconfig on Arch Linux with latest grub and grub-btrfs from repos. grub 2.06.r499 and grub-btrfs 4.12 Edit: If I comment out the last 3 lines in 41_snapshots-btrfs (eliminating the warning check) then I do not get duplicate entries in grub.cfg
The warning check comes after the 41_snapshots-btrfs script is closed with fi. This seems to cause grub-mkconfig to see it as a second script and add the begin and end comments. This seems to fix it for me:
if [ -e "$grub_btrfs_directory/grub-btrfs.cfg.bkp" ]; then
mv -f "$grub_btrfs_directory/grub-btrfs.cfg.bkp" "$grub_btrfs_directory/grub-btrfs.cfg"
print_error "Syntax errors were detected in generated ${grub_btrfs_directory}/grub-btrfs.new file. The old grub-btrfs.cfg file (if present) have been restored."
fi
# warn when this script is run but there is no entry in grub.cfg
grep "snapshots-btrfs" "${grub_directory}/grub.cfg" || printf "\nWARNING: '%s' needs to run at least once to generate the snapshots (sub)menu entry in grub the main menu. \
After that this script can run alone to generate the snapshot entries.\n\n" "${GRUB_BTRFS_MKCONFIG:-grub-mkconfig}" >&2 ;
fi
The warning check comes after the 41_snapshots-btrfs script is closed with fi. This seems to cause grub-mkconfig to see it as a second script and add the begin and end comments. This seems to fix it for me:
if [ -e "$grub_btrfs_directory/grub-btrfs.cfg.bkp" ]; then mv -f "$grub_btrfs_directory/grub-btrfs.cfg.bkp" "$grub_btrfs_directory/grub-btrfs.cfg" print_error "Syntax errors were detected in generated ${grub_btrfs_directory}/grub-btrfs.new file. The old grub-btrfs.cfg file (if present) have been restored." fi # warn when this script is run but there is no entry in grub.cfg grep "snapshots-btrfs" "${grub_directory}/grub.cfg" || printf "\nWARNING: '%s' needs to run at least once to generate the snapshots (sub)menu entry in grub the main menu. \ After that this script can run alone to generate the snapshot entries.\n\n" "${GRUB_BTRFS_MKCONFIG:-grub-mkconfig}" >&2 ; fi
Oh yeah, thanks for figuring that out. I think I know whats going on.
I will release a quick fix.
I notice there are a lot of duplicate comments in
/boot/grub/grub.cfg
: :point_down:More than 200 same comments in it.
That would cause GRUB processing to slow down.
How to reproduce the issue:
For
grub 2.06.r499
andgrub-btrfs 4.12
users.cp /boot/grub/grub.cfg /boot/grub/grub.cfg_backup
grub-mkconfig -o /boot/grub/grub.cfg
diff grub.cfg_backup grub.cfg
Difference output: