Last active
October 22, 2023 02:15
-
-
Save rkitover/e32b34ab17901bfa62841fe6441b14aa to your computer and use it in GitHub Desktop.
trivial script to delete GRUB env to boot Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to remove the GRUB environment file, resetting the default GRUB entry | |
# to what is usually the user's latest Linux kernel. | |
$grubenv = 'z:/grub/grubenv' | |
# Relaunch as an elevated process. | |
if (-not ([security.principal.windowsprincipal] [security.principal.windowsidentity]::getcurrent() ` | |
).isinrole([security.principal.windowsbuiltInrole]::administrator) ` | |
) { | |
$pwsh = [system.diagnostics.process]::getcurrentprocess().mainmodule.filename | |
start-process $pwsh '-noprofile', '-executionpolicy', 'bypass', ` | |
'-windowstyle', 'hidden', ` | |
'-file', $myinvocation.mycommand.path -verb runas | |
exit | |
} | |
function diskpart([string]$script) { | |
$script | out-file (new-temporaryfile -outvariable script_file) | |
diskpart.exe /s $script_file | |
remove-item $script_file | |
} | |
diskpart @" | |
select disk 0 | |
select partition 1 | |
assign letter=z | |
"@ | |
if (test-path $grubenv) { | |
@" | |
# GRUB Environment Block | |
# WARNING: Do not edit this file by tools other than grub-editenv!!! | |
################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################## | |
"@ -replace '\r','' | out-file $grubenv -nonewline | |
} | |
diskpart @" | |
select disk 0 | |
select partition 1 | |
remove letter=z | |
"@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment