Skip to content

Instantly share code, notes, and snippets.

@Firxiao
Last active July 7, 2021 12:53
Show Gist options
  • Save Firxiao/c67191831586041229d5eadaf7f3d6d1 to your computer and use it in GitHub Desktop.
Save Firxiao/c67191831586041229d5eadaf7f3d6d1 to your computer and use it in GitHub Desktop.
Grub notes

clover in grub2

[workstation] /etc/grub.d $ cat 40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'macOS' {
insmod fat
insmod part_gpt
insmod chain
insmod search_fs_uuid
set root='hd0,gpt1'
search --no-floppy --fs-uuid --set=root 3CFC-C13C
chainloader /EFI/clover/CLOVERX64.efi
}

reboot from windows

[workstation] ~ $ cat /usr/local/bin/boot_win
echo "boot from win"
echo `hostname -I|awk '{print $1}'`
sudo grub-reboot 2 && sudo reboot

check grub2 boot entry numbder

gawk  'BEGIN {                                                                                                                       
  l=0                                                                                                                                
  menuindex= 0                                                                                                                       
  stack[t=0] = 0                                                                                                                     
}                                                                                                                                    

function push(x) { stack[t++] = x }                                                                                                  

function pop() { if (t > 0) { return stack[--t] } else { return "" }  }                                                              

{                                                                                                                                    

if( $0 ~ /.*menu.*{.*/ )                                                                                                             
{                                                                                                                                    
  push( $0 )                                                                                                                         
  l++;                                                                                                                               

} else if( $0 ~ /.*{.*/ )                                                                                                            
{                                                                                                                                    
  push( $0 )                                                                                                                         

} else if( $0 ~ /.*}.*/ )                                                                                                            
{                                                                                                                                    
  X = pop()                                                                                                                          
  if( X ~ /.*menu.*{.*/ )                                                                                                            
  {                                                                                                                                  
     l--;                                                                                                                            
     match( X, /^[^'\'']*'\''([^'\'']*)'\''.*$/, arr )                                                                               

     if( l == 0 )                                                                                                                    
     {                                                                                                                               
       print menuindex ": " arr[1]                                                                                                   
       menuindex++                                                                                                                   
       submenu=0                                                                                                                     
     } else                                                                                                                          
     {                                                                                                                               
       print "  " (menuindex-1) ">" submenu " " arr[1]                                                                               
       submenu++                                                                                                                     
     }                                                                                                                               
  }                                                                                                                                  
}                                                                                                                                    
}' /boot/grub/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment