As something of a follow-up post to the previous entry, here’s a quick recipe for creating a Virtual Machine using the VirtualBox command line tools:
We’re using Windows Server 2008 64bit as an example, modify to taste.
$ VM='Windows-2008-64bit'
Create a 32GB “dynamic” disk.
$ VBoxManage createhd --filename $VM.vdi --size 32768
You can get a list of the OS types VirtualBox recognises using:
$ VBoxManage list ostypes
Then copy the most appropriate one into here.
$ VBoxManage createvm --name $VM --ostype "Windows2008_64" --register
Add a SATA controller with the dynamic disk attached.
$ VBoxManage storagectl $VM --name "SATA Controller" --add sata \
> --controller IntelAHCI
$ VBoxManage storageattach $VM --storagectl "SATA Controller" --port 0 \
> --device 0 --type hdd --medium $VM.vdi
Add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive:
$ VBoxManage storagectl $VM --name "IDE Controller" --add ide
$ VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 \
> --device 0 --type dvddrive --medium /path/to/windows_server_2008.iso
Misc system settings.
$ VBoxManage modifyvm $VM --ioapic on
$ VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none
$ VBoxManage modifyvm $VM --memory 1024 --vram 128
$ VBoxManage modifyvm $VM --nic1 bridged --bridgeadapter1 e1000g0
Configuration is all done, boot it up! If you’ve done this one a remote machine, you can RDP to the console via vboxhost:3389.
$ VBoxHeadless -s $VM
Once you have configured the operating system, you can shutdown and eject the DVD.
$ VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 \
> --device 0 --type dvddrive --medium none
Finally, it’s a good idea to take regular snapshots so that you can always revert back to a known-good state rather than having to completely re-install.
$ VBoxManage snapshot $VM take <name of snapshot>
And, if you need to revert back to a particular snapshot:
$ VBoxManage snapshot $VM restore <name of snapshot>
Thanks for sharing this.
I ran into two problems, one I was able to resolve, or at least I think I was able to resolve.
First I ran into this error because of an non-existent
e1000g0
interface.I resolved it by running the following and looking for a bridge interface which for me was
bridge0
:The second problem was being able to "RDP to the console via
vboxhost:3389
". Although I assumedvboxhost
was not a valid host name I tried it to confirm it and it was not, at least not for me. I was instead able to shutdown the VM using the VirtualBox app and then restart it after which I could use the built-in VirtualBox VM app to interact with the Windows UI but I would be curious how to use RDP instead.FYI though, I ended up using Packer to do what I needed in a more robust way, so I don't really need a solution but it would be nice to learn how to RDP in anyway.
BTW, I am on macOS 10.15.7 Catalina.