{"id":211,"date":"2025-11-01T06:00:00","date_gmt":"2025-11-01T09:00:00","guid":{"rendered":"https:\/\/euclides.me\/?p=211"},"modified":"2025-11-01T06:00:01","modified_gmt":"2025-11-01T09:00:01","slug":"script-para-habilitar-vt%e2%80%91x-amd%e2%80%91v-no-virtualbox","status":"publish","type":"post","link":"https:\/\/euclides.me\/?p=211","title":{"rendered":"script para habilitar VT\u2011x\/AMD\u2011V no VirtualBox"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"723\" height=\"257\" src=\"https:\/\/euclides.me\/wp-content\/uploads\/2025\/11\/image.png\" alt=\"\" class=\"wp-image-212\" style=\"width:539px;height:auto\" srcset=\"https:\/\/euclides.me\/wp-content\/uploads\/2025\/11\/image.png 723w, https:\/\/euclides.me\/wp-content\/uploads\/2025\/11\/image-300x107.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/figure>\n\n\n\n<p>Este codigo em Powershell habilita automaticamente em todas suas VMs a op\u00e7\u00e3o.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;#\n.SYNOPSIS\n  Habilita Nested VT-x\/AMD-V em todas as VMs do VirtualBox (sem valida\u00e7\u00e3o).\n\n.DESCRIPTION\n  - Localiza VBoxManage\n  - Lista todas as VMs\n  - Para cada VM:\n      * Se estiver rodando, envia poweroff (best-effort)\n      * Executa: VBoxManage modifyvm \"&lt;VM>\" --nested-hw-virt on\n      * (Opcional) Ajusta paravirtualiza\u00e7\u00e3o para kvm (\u00fatil para Linux\/Ubuntu)\n\n.NOTES\n  Execute como Administrador. Feito para Windows host.\n#>\n\n# ---------- Utilidades de sa\u00edda ----------\nfunction Info($msg) { Write-Host \"&#91;INFO] $msg\" -ForegroundColor Cyan }\nfunction Ok($msg)   { Write-Host \"&#91;OK]   $msg\" -ForegroundColor Green }\nfunction Warn($msg) { Write-Host \"&#91;AVISO] $msg\" -ForegroundColor Yellow }\nfunction Err($msg)  { Write-Host \"&#91;ERRO] $msg\" -ForegroundColor Red }\n\n# ---------- Encontrar VBoxManage ----------\n$VBoxManage = \"${env:PROGRAMFILES}\\Oracle\\VirtualBox\\VBoxManage.exe\"\nif (-not (Test-Path $VBoxManage)) { $VBoxManage = \"VBoxManage.exe\" }\nif (-not (Get-Command $VBoxManage -ErrorAction SilentlyContinue)) {\n    Err \"VBoxManage n\u00e3o encontrado. Instale o VirtualBox ou adicione-o ao PATH.\"\n    exit 1\n}\n\n# ---------- Obter VMs ----------\n$allVmsRaw = &amp; $VBoxManage list vms 2>$null\nif (-not $allVmsRaw) {\n    Warn \"Nenhuma VM encontrada.\"\n    exit 0\n}\n\n# Converte linhas do tipo:  \"VM Name\" {UUID}  ->  objeto com Name e Uuid\n$allVms = $allVmsRaw | ForEach-Object {\n    if ($_ -match '^\\s*\\\"(.+?)\\\"\\s+\\{(&#91;0-9a-fA-F-]+)\\}\\s*$') {\n        &#91;PSCustomObject]@{ Name = $Matches&#91;1]; Uuid = $Matches&#91;2] }\n    }\n} | Where-Object { $_ -ne $null }\n\nInfo \"Total de VMs: $($allVms.Count)\"\n\n# Lista de VMs rodando\n$runningRaw = &amp; $VBoxManage list runningvms 2>$null\n$runningNames = @()\nif ($runningRaw) {\n    $runningNames = ($runningRaw | ForEach-Object {\n        if ($_ -match '^\\s*\\\"(.+?)\\\"\\s+\\{') { $Matches&#91;1] }\n    })\n}\n\n# ---------- Processar cada VM ----------\nforeach ($vm in $allVms) {\n    Write-Host \"`n=== VM: $($vm.Name) ===\" -ForegroundColor White\n\n    # Se estiver em execu\u00e7\u00e3o, tenta poweroff (best-effort)\n    if ($runningNames -contains $vm.Name) {\n        Info \"VM em execu\u00e7\u00e3o. Enviando poweroff\u2026\"\n        try {\n            &amp; $VBoxManage controlvm \"$($vm.Name)\" poweroff | Out-Null\n            Start-Sleep -Seconds 3\n        } catch {\n            Warn \"N\u00e3o foi poss\u00edvel desligar automaticamente. Tentarei aplicar mesmo assim.\"\n        }\n    }\n\n    # Habilitar nested virtualization (sem checagem)\n    try {\n        Info \"Habilitando nested VT-x\/AMD-V\u2026\"\n        &amp; $VBoxManage modifyvm \"$($vm.Name)\" --nested-hw-virt on | Out-Null\n        Ok \"Nested habilitado.\"\n    } catch {\n        Err \"Falha ao aplicar nested em '$($vm.Name)'. Detalhe: $($_.Exception.Message)\"\n        continue\n    }\n\n    # (Opcional) Ajuste de paravirtualiza\u00e7\u00e3o \u2013 \u00fatil p\/ guests Linux\/Ubuntu\n    try {\n        &amp; $VBoxManage modifyvm \"$($vm.Name)\" --paravirtprovider kvm | Out-Null\n        Ok \"Paravirtualiza\u00e7\u00e3o ajustada para 'kvm'.\"\n    } catch {\n        Warn \"N\u00e3o foi poss\u00edvel ajustar paravirtualiza\u00e7\u00e3o (ignorado).\"\n    }\n}\n\nWrite-Host \"`nConclu\u00eddo.\" -ForegroundColor Green\nWrite-Host \"Inicie suas VMs e, no Linux convidado, voc\u00ea pode conferir com:\"\nWrite-Host \"  egrep -c '(vmx|svm)' \/proc\/cpuinfo   # >0 = OK\"\nWrite-Host \"  lscpu | findstr \/i virtualization\"<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Este codigo em Powershell habilita automaticamente em todas suas VMs a op\u00e7\u00e3o.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_regular_price":[],"currency_symbol":[],"footnotes":""},"categories":[27],"tags":[],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-script"],"aioseo_notices":[],"post_slider_layout_featured_media_urls":{"thumbnail":"","post_slider_layout_landscape_large":"","post_slider_layout_portrait_large":"","post_slider_layout_square_large":"","post_slider_layout_landscape":"","post_slider_layout_portrait":"","post_slider_layout_square":"","full":""},"_links":{"self":[{"href":"https:\/\/euclides.me\/index.php?rest_route=\/wp\/v2\/posts\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/euclides.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/euclides.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/euclides.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/euclides.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":1,"href":"https:\/\/euclides.me\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/euclides.me\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/euclides.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/euclides.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/euclides.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}