大佬教程收集整理的这篇文章主要介绍了ubuntu – 如何非破坏性地检查grub2是否安装在引导扇区中或者是否被grub1链式加载,而不重启?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有什么比做硬盘驱动器的早期块的hexdump更容易并尝试识别特定于grub2的字节?
#!/bin/bash set -e if [ "$UID" -ne "0" ]; then echo Must be run as root exit 99 fi scan_grub2() { if ! dd if="$1" bs=512 count=1 2>/dev/null | grep -aq GRUB; then # No version of GRUB is installed. echo Grub Could not be found return 1 fi # The GRUB boot sector always starts with a JMP instruction. initial_jmp="$(dd if="$1" bs=2 count=1 2>/dev/null | od -Ax -tx1 | \ head -n1 | cut -d' ' -f2,3)" [ "$initial_jmp" ] || return 1 initial_jmp_opcode="${initial_jmp%% *}" [ "$initial_jmp_opcode" = eb ] || return 1 initial_jmp_operand="${initial_jmp#* }" case $initial_jmp_operand in 47|4b|4c|63) # I believe this covers all versions of GRUB 2 up to the package # version where we gained a more explicit mechanism. GRUB Legacy # always had 48 here. return 0 ;; esac return 1 } if scan_grub2 "/dev/sda"; then echo Found grub 2 else echo Did not find grub 2 #Uncomment the next line to upgrade #upgrade-from-grub-legacy fi
以上是大佬教程为你收集整理的ubuntu – 如何非破坏性地检查grub2是否安装在引导扇区中或者是否被grub1链式加载,而不重启?全部内容,希望文章能够帮你解决ubuntu – 如何非破坏性地检查grub2是否安装在引导扇区中或者是否被grub1链式加载,而不重启?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。