Install a Windows 10 VM on VirtualBox with vboxmanage
These steps can be used to setup a Windows 10 VirtualBox guest that can be used as the base OS for the other blog posts. The host system in my case is also Windows 10. The unattended installation process is used.
Table of Contents
Preparation
Prepare the VirtualBox environment if not already done (see: General Preparations for new VM Installations). Then download a Windows 10 64bit ISO Image and place it to a location like c:\sw\Win10_x64_22H2_en_us.iso
Install the new Windows 10 VM
Configure the Virtual Machine
Run these steps in a Windows command prompt to configure the new VM. You probably need to adjust the parameter –bridgeadapter1 to the name of your primary interface of the Windows host system (ipconfig /all => see Description)
set "VHOST=" && set "MAC="
(set /p VHOST=Enter VM name ^(e.g. lin1^):
set /p MAC=Enter the MAC address of the VM if you would like to use a dedicated MAC address. Press Enter to let VirtualBox assign a random MAC:
call vboxmanage createvm --name %VHOST% --ostype Windows10_64 --register
call vboxmanage modifyvm %VHOST% --clipboard-mode=bidirectional --drag-and-drop=bidirectional --audio-controller=hda --audio-out=on
call vboxmanage modifyvm %VHOST% --memory=8192 --cpus=4 --vram=128 --graphicscontroller=vboxsvga --accelerate-3d=on --usb-xhci=on
call vboxmanage setextradata %VHOST% GUI/ScaleFactor 2
call vboxmanage storagectl %VHOST% --name "IDE" --add ide
call vboxmanage storagectl %VHOST% --name "SATA" --add sata --bootable on
call vboxmanage createmedium disk --filename c:\vms\%VHOST%\%VHOST%_1.vdi --size 122880 --variant Standard
call vboxmanage storageattach %VHOST% --storagectl "SATA" --port 0 --device 0 --type hdd --medium c:\vms\%VHOST%\%VHOST%_1.vdi
call vboxmanage modifyvm %VHOST% --nic1 bridged --bridgeadapter1 "Intel(R) Ethernet Connection (2) I219-LM"
if defined MAC call vboxmanage modifyvm %VHOST% --mac-address1=%MAC%
call vboxmanage sharedfolder add %VHOST% --name=sw --hostpath=c:\sw --automount --auto-mount-point=s:\sw
call vboxmanage showvminfo %VHOST%|findstr /C:"NIC 1")
Perform the unattended OS installation
The next command will display all installation images contained in the iso file. Select the on you wish to install and enter the Product Key:
set "img=" && set "pkey="
(vboxmanage unattended detect --iso=c:\sw\Win10_x64_22H2_en_us.iso
set /p img=Enter the Image ^# you want to install:
set /p pkey=Enter the Windows Product Key: )
The output should be similar to:
VBoxManage.exe: info: Detected 'C:\sw\Win10_x64_22H2_en_us.iso' to be:
OS TypeId = Windows10_64
OS Version = 10.0.19045.5247
OS Flavor = Core
OS Languages = en-US
OS Hints =
Image #1 = Windows 10 Home (10.0.19045.5247 / x64 / en-US)
Image #2 = Windows 10 Home N (10.0.19045.5247 / x64 / en-US)
Image #3 = Windows 10 Home Single Language (10.0.19045.5247 / x64 / en-US)
Image #4 = Windows 10 Pro (10.0.19045.5247 / x64 / en-US)
Image #5 = Windows 10 Enterprise (10.0.19045.5247 / x64 / en-US)
Image #6 = Windows 10 IoT Enterprise (10.0.19045.5247 / x64 / en-US)
Image #7 = Windows 10 Enterprise multi-session (10.0.19045.5247 / x64 / en-US)
Image #8 = Windows 10 Education (10.0.19045.5247 / x64 / en-US)
Image #9 = Windows 10 Pro Education (10.0.19045.5247 / x64 / en-US)
Image #10 = Windows 10 Pro for Workstations (10.0.19045.5247 / x64 / en-US)
Image #11 = Windows 10 Pro N (10.0.19045.5247 / x64 / en-US)
Image #12 = Windows 10 Enterprise N (10.0.19045.5247 / x64 / en-US)
Image #13 = Windows 10 Education N (10.0.19045.5247 / x64 / en-US)
Image #14 = Windows 10 Pro Education N (10.0.19045.5247 / x64 / en-US)
Image #15 = Windows 10 Pro N for Workstations (10.0.19045.5247 / x64 / en-US)
Unattended installation supported = yes
Enter the Image # you want to install: 4
Enter the Windows Product Key: ***
Now start the unattended install. This will take about 10 minutes:
vboxmanage unattended install %VHOST% --iso=c:\sw\Win10_x64_22H2_en_us.iso --image-index=%img% --key=%pkey% --user=user1 --user-password=changeme --install-additions --additions-iso="C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso" --locale=de_DE --country=DE --time-zone="Europe/Berlin" --hostname=%VHOST%.fritz.box --start-vm=gui
rem
After a reboot your new Windows 10 VM is now ready to use. Have fun!
After the OS is installed you might perform the following:
rem to be run on the host system
rem disable monitor timeout
vboxmanage guestcontrol %VHOST% run --username=user1 --password=changeme --wait-stdout --exe "C:\Windows\System32\powercfg.exe" -- /x monitor-timeout-ac 0
rem change keyboard layout to German
vboxmanage guestcontrol %VHOST% run --username=user1 --password=changeme --wait-stdout --exe "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -- Set-WinUserLanguageList -LanguageList de-DE, en-US -force
Further information
- If there are errors during the installation you can remove the VM configuration and all files and do a complete new installation.
- This Oracle Blog post: Guide for VirtualBox VM unattended installation
Leave a Reply