Skip to content

Instantly share code, notes, and snippets.

@rkitover
Last active October 22, 2023 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkitover/e32b34ab17901bfa62841fe6441b14aa to your computer and use it in GitHub Desktop.
Save rkitover/e32b34ab17901bfa62841fe6441b14aa to your computer and use it in GitHub Desktop.
trivial script to delete GRUB env to boot Linux
# 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