$ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' New-Item -ItemType Directory -Force -Path 'C:\linux-install' | Out-Null Start-Transcript -Path 'C:\linux-install\setup-grub.log' -Force | Out-Null function Step($m){ Write-Host ("[{0}] {1}" -f (Get-Date -Format HH:mm:ss), $m) } try { $id = [Security.Principal.WindowsIdentity]::GetCurrent() $prin = New-Object Security.Principal.WindowsPrincipal($id) Step ("User={0} Admin={1}" -f $id.Name, $prin.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) if (-not $prin.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Precisa Admin/SYSTEM' } # ISO $src = @( 'C:\Users\felipe.almeida\Downloads\linuxmint-CONEXLOG-rustdesk-live.iso', 'C:\Users\nubiway\Downloads\linuxmint-CONEXLOG-rustdesk-live.iso' ) | Where-Object { Test-Path $_ } | Select-Object -First 1 if (-not $src) { throw 'ISO nao encontrada' } if (-not (Test-Path 'C:\conexlog-mint.iso') -or ((Get-Item 'C:\conexlog-mint.iso').Length -lt 2GB)) { Step "Copiando ISO..." Copy-Item -LiteralPath $src -Destination 'C:\conexlog-mint.iso' -Force } Step ("ISO OK {0:N2}GB" -f ((Get-Item 'C:\conexlog-mint.iso').Length/1GB)) # EFI app $efiLocal = 'C:\linux-install\CONEXLOG.efi' Step 'Baixando CONEXLOG.efi do VPS' Invoke-WebRequest -Uri 'http://205.209.118.34/iso/CONEXLOG.efi' -OutFile $efiLocal -UseBasicParsing if ((Get-Item $efiLocal).Length -lt 1MB) { throw 'CONEXLOG.efi incompleto' } Step ("EFI {0:N1}MB" -f ((Get-Item $efiLocal).Length/1MB)) # Mount ESP $esp = 'S:' if (-not (Test-Path 'S:\EFI')) { Step 'Montando ESP em S:' mountvol S: /S if (-not (Test-Path 'S:\EFI')) { throw 'Falha mountvol S: /S — PC sem UEFI?' } } $destDir = 'S:\EFI\CONEXLOG' New-Item -ItemType Directory -Force -Path $destDir | Out-Null Copy-Item $efiLocal (Join-Path $destDir 'grubx64.efi') -Force Copy-Item $efiLocal (Join-Path $destDir 'bootx64.efi') -Force # tambem no BOOT padrao como backup (nao sobrescreve microsoft) Step 'EFI copiado para S:\EFI\CONEXLOG\' # Cria boot entry firmware # Apaga entrada antiga se existir (best-effort) $fw = bcdedit /enum firmware | Out-String Step 'Criando entrada BCD EFI' $create = bcdedit /copy '{bootmgr}' /d 'CONEXLOG Mint Live' Step $create # /copy {bootmgr} may not work on all; try create for EFI $guid = ([regex]::Match(($create|Out-String), '\{[0-9a-fA-F\-]+\}')).Value if (-not $guid) { # metodo alternativo: bcdedit /create /d ... /application EFIAPP? # Windows usa: $out = cmd /c "bcdedit /create /d `"CONEXLOG Mint Live`" /application app" Step $out $guid = ([regex]::Match($out, '\{[0-9a-fA-F\-]+\}')).Value } if ($guid) { bcdedit /set $guid device partition=S: bcdedit /set $guid path '\EFI\CONEXLOG\grubx64.efi' # firmware boot manager order bcdedit /set '{fwbootmgr}' displayorder $guid /addfirst bcdedit /set '{fwbootmgr}' timeout 2 # tambem bootmgr windows timeout curto bcdedit /timeout 2 Step "BOOT DEFAULT EFI = $guid" } else { # fallback: aponta bootmgr path direto (mais agressivo) Step 'Fallback: set bootmgr path para CONEXLOG' bcdedit /set '{bootmgr}' path '\EFI\CONEXLOG\grubx64.efi' bcdedit /timeout 2 } # Secure Boot try { $sb = Confirm-SecureBootUEFI Step ("SecureBoot=$sb") if ($sb) { Step 'ALERTA: Secure Boot LIGADO — pode bloquear nosso GRUB. Desligar na BIOS se nao bootar.' } } catch { Step 'SecureBoot N/A' } Step '=== VERIFY EFI ===' Get-ChildItem 'S:\EFI\CONEXLOG' | Format-Table Name,Length bcdedit /enum '{fwbootmgr}' bcdedit /enum '{bootmgr}' Step 'DONE_SETUP' Step 'Reboot vai subir Mint Live sozinho em ~2s (se Secure Boot off).' } catch { Step ("ERROR: " + $_.Exception.Message) $_ | Format-List * -Force | Out-String | Write-Host exit 1 } finally { try { Stop-Transcript | Out-Null } catch {} }