chuggerguy

boot2label

Jun 26th, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.46 KB | Software | 0 0
  1. #!/bin/bash
  2. #Boot to drive by label
  3.  
  4. if [ "$#" -ne 1 ]; then
  5.     echo "Usage: `basename $0` labelOfDriveToBoot"
  6.     exit
  7. fi
  8.  
  9. if [ "$(id -u)" != "0" ]; then
  10.     exec sudo "$0" "$@"
  11. fi
  12.  
  13. label="$1"
  14.  
  15. partitionUUIDofLabel=$(lsblk -no label,partuuid | grep -B 99 $label | grep EFI | tail -n1 | awk '{print $2}')
  16. efiBootNumber=$(efibootmgr | grep $partitionUUIDofLabel | awk -F* '{print $1}' | awk -F"Boot" '{print $2}')
  17.  
  18. efibootmgr -n $efiBootNumber
  19.  
  20. reboot
  21.  
Advertisement
Add Comment
Please, Sign In to add comment