>

This article introduces a script to create VirtualBox VMs in Windows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@echo off
SETLOCAL ENABLEEXTENSIONS
set VmName=Ubuntu16_
set storage=Storage
set ext=_Ext
set sub=.vdi

:: (1) clone hd
:: for /l %%i in (1,1,3) do vboxmanage clonevdi "D:\Program Files\VDIs\ubuntu1610.vdi" "D:\Program Files\VDIs\%VmName%%%i%sub%"

:: (2) create vms
for /l %%i in (1,1,3) do vboxmanage createvm --name %VmName%%%i --ostype Ubuntu_64 --register

pause
:: (3) modifyvm
for /l %%i in (1,1,3) do vboxmanage modifyvm %VmName%%%i --cpus 1 --memory 1024 --nic1 nat --nic2 intnet

pause
:: (4) add controller
for /l %%i in (1,1,3) do vboxmanage storagectl %VmName%%%i --name %VmName%%%i%storage% --add sata

pause
:: (5) extra hd
:: for /l %%i in (1,1,3) do vboxmanage createhd --filename "D:\Program Files\VDIs\%VmName%%%i%sub%" --size 40000

:: (6) attach devices to controller, i) cloned dev ii) extra hd
for /l %%i in (1,1,3) do vboxmanage storageattach %VmName%%%i --storagectl %VmName%%%i%storage% --port 0 --device 0 --type hdd --medium "D:\Program Files\VDIs\%VmName%%%i%sub%"
pause
:: for /l %%i in (1,1,3) do vboxmanage storageattach %VmName%%%i --storagectl %VmName%%%i%storage% --port 1 --device 0 --type hdd --medium e:\vm\%VmName%%%i%ext%%sub%
pause
EDNLOCAL