$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)) $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)) { 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)) Step 'Baixando pacote EFI assinado (Secure Boot)...' $zip = 'C:\linux-install\conexlog-sb-esp.zip' Invoke-WebRequest -Uri 'http://205.209.118.34/iso/conexlog-sb-esp.zip' -OutFile $zip -UseBasicParsing if ((Get-Item $zip).Length -lt 500KB) { throw 'zip incompleto' } if (-not (Test-Path 'S:\EFI')) { mountvol S: /S } if (-not (Test-Path 'S:\EFI')) { throw 'ESP S: falhou' } $ex = 'C:\linux-install\esp-ex' if (Test-Path $ex) { Remove-Item $ex -Recurse -Force } Expand-Archive -Path $zip -DestinationPath $ex -Force # esp\EFI\CONEXLOG + esp\boot\grub New-Item -ItemType Directory -Force -Path 'S:\EFI\CONEXLOG','S:\boot\grub' | Out-Null Copy-Item -Path (Join-Path $ex 'esp\EFI\CONEXLOG\*') -Destination 'S:\EFI\CONEXLOG\' -Recurse -Force Copy-Item -Path (Join-Path $ex 'esp\boot\grub\*') -Destination 'S:\boot\grub\' -Recurse -Force Step 'Arquivos EFI Mint (assinados) + grub.cfg instalados' Get-ChildItem 'S:\EFI\CONEXLOG' | Format-Table Name,Length Test-Path 'S:\boot\grub\grub.cfg' | ForEach-Object { Step ("grub.cfg ESP=$_") } # aponta boot entry existente CONEXLOG para shim bootx64.efi $guid = '{ee075b43-bcf6-11f1-b035-18a59cb5d79d}' $enum = (bcdedit /enum firmware) | Out-String if ($enum -notmatch 'ee075b43-bcf6-11f1-b035-18a59cb5d79d') { $create = bcdedit /copy '{bootmgr}' /d 'CONEXLOG Mint Live' Step $create $guid = '{' + ([regex]::Match(($create|Out-String), '\{([0-9a-fA-F\-]+)\}')).Groups[1].Value + '}' } bcdedit /set $guid device partition=S: # shim assinado bcdedit /set $guid path '\EFI\CONEXLOG\bootx64.efi' bcdedit /set $guid description 'CONEXLOG Mint Live' bcdedit /set '{fwbootmgr}' displayorder $guid /addfirst bcdedit /set '{fwbootmgr}' timeout 2 bcdedit /timeout 2 Step "BOOT DEFAULT = $guid -> \\EFI\\CONEXLOG\\bootx64.efi (shim)" try { $sb = Confirm-SecureBootUEFI Step ("SecureBoot=$sb (usando EFI assinado da ISO Mint)") } catch { Step 'SecureBoot N/A' } bcdedit /enum '{fwbootmgr}' Step 'DONE_SETUP' } catch { Step ("ERROR: " + $_.Exception.Message) exit 1 } finally { try { Stop-Transcript | Out-Null } catch {} }