{"id":1065,"date":"2018-10-24T23:35:08","date_gmt":"2018-10-24T20:35:08","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1065"},"modified":"2024-03-11T19:59:32","modified_gmt":"2024-03-11T16:59:32","slug":"automate-virtual-machine-installation-on-virtualbox","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/automate-virtual-machine-installation-on-virtualbox\/","title":{"rendered":"Automate Virtual Machine Installation on VirtualBox"},"content":{"rendered":"\n
In this tutorial, you will learn how to automate virtual machine installation on VirtualBox. Many times, not once, not twice when you would want to create virtual machine on VirtualBox. So just imagine how tedious and time consuming it is to create a VM manually every time you need a virtual lab to play with. No, that manual procedure is not for you.<\/p>\n\n\n\n
To automate virtual machine creation on VirtualBox, we are going to use the unattended install<\/a><\/strong> feature of VBoxManage command. With this feature, you can get the VM automatically installed with very little human interaction while setting up installation variables.<\/p>\n\n\n\n You can also script the whole of this procedure to achieve full blown automation.<\/strong><\/p>\n\n\n\n To begin with, you need to have installed VirtualBox on your host system. You can check the link below on how to install VirtualBox;<\/p>\n\n\n\n How to install VirtualBox on Linux system<\/a><\/p>\n\n\n\n As a first step on how to automatatically install a virtual machine on VirtualBox, run the command below to create and register the vm.<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n Once you have registered a VM, create a storage medium as shown below.<\/p>\n\n\n\n VirtualBox usually uses SATA controller as the default for newly created virtual machines. To add a SATA controller to VM, run the command below.<\/p>\n\n\n\n IDE ATA provides support CD-ROM drives and other types of removable media. It enables you to attach upto four virtual storage devices to your vm. One of these four virtual storages can be preconfigured to be the machine’s virtual CD\/DVD drive.<\/p>\n\n\n\n Next, we are going to define various properties of the registered VM. To achieve this, we are going to us the modifyvm<\/strong> command. Most of the properties that this command makes available correspond to the VM settings that VirtualBox graphical user interface displays in each VM’s “Settings” dialog.<\/p>\n\n\n\n Allocate the vm a specific RAM as well as nvram size as shown below;<\/p>\n\n\n\n With IO APIC enabled, the OS can use more than 16 interrupt requests (IRQs) thus avoiding IRQ sharing for improved reliability.<\/p>\n\n\n\n Run the command below to define the vm boot order.<\/p>\n\n\n\n Since this is a server, there is no point of having audio enabled.<\/p>\n\n\n\n Since I am not planning on using USB with my VM, am choosing to disable this. The case may be different for you.<\/p>\n\n\n\n In this case, am going to assign my VM two NICs;<\/p>\n\n\n\n You can define as many settings as it pleases you.<\/p>\n\n\n\n Once you are done, it is time to install the VM unattended. Run the following command to start the VM auto-installation.<\/p>\n\n\n\n Sample command output;<\/p>\n\n\n\n What the command does is that, it launches and configure the VM with all the variable set. The breakdown of the same command is as in below;<\/p>\n\n\n\n That is all it takes to automate virtual machine installation on VirtualBox. The process may not seem automated due to various settings being made. Therefore, consider putting all these steps in bash script to achieve full automation.<\/p>\n\n\n\nInstall VirtualBox on your Host system<\/h3>\n\n\n\n
Create and Register a Virtual Machine<\/h3>\n\n\n\n
VBoxManage createvm --name ubuntu18server --ostype Ubuntu_64 --register<\/code><\/pre>\n\n\n\n
Virtual machine 'ubuntu18server' is created and registered.\nUUID: 41d12b9c-10b2-46a1-8710-7f00a9a02de7\nSettings file: '\/home\/kifarunix\/VirtualBox VMs\/ubuntu18server\/ubuntu18server.vbox'<\/code><\/pre>\n\n\n\n
\n
VBoxManage list ostypes | less<\/code><\/pre>\n\n\n\n
\n
Setup the Virtual Machine Storage Medium<\/h2>\n\n\n\n
VBoxManage createmedium \\\n--filename \/home\/kifarunix\/VirtualBox\\ VMs\/ubuntu18server\/ubuntu18server.vdi \\\n--size 10240<\/code><\/pre>\n\n\n\n
\n
Add and Attach SATA and IDE Storage Controllers<\/h3>\n\n\n\n
VBoxManage storagectl ubuntu18server --name SATA --add SATA --controller IntelAhci<\/code><\/pre>\n\n\n\n
VBoxManage storageattach ubuntu18server \\\n--storagectl SATA --port 0 --device 0 --type hdd \\\n--medium \/home\/kifarunix\/VirtualBox\\ VMs\/ubuntu18server\/ubuntu18server.vdi<\/code><\/pre>\n\n\n\n
VBoxManage storagectl ubuntu18server --name IDE --add ide<\/code><\/pre>\n\n\n\n
VBoxManage storageattach ubuntu18server \\\n--storagectl IDE --port 0 --device 0 --type dvddrive \\\n--medium \/home\/kifarunix\/Downloads\/iso\/Debian\/ubuntu-22.04-desktop-amd64.iso<\/code><\/pre>\n\n\n\n
\n
Define the VM General Settings<\/h2>\n\n\n\n
Set the VM RAM and Virtual graphics card RAM size<\/h4>\n\n\n\n
VBoxManage modifyvm ubuntu18server --memory 1024 --vram 16<\/code><\/pre>\n\n\n\n
Enable IO APIC<\/h4>\n\n\n\n
VBoxManage modifyvm ubuntu18server --ioapic on<\/code><\/pre>\n\n\n\n
Define the boot order for the virtual machine<\/h4>\n\n\n\n
VBoxManage modifyvm ubuntu18server --boot1 dvd --boot2 disk --boot3 none --boot4 none<\/code><\/pre>\n\n\n\n
Define the number of virtual CPUs for the VM<\/h4>\n\n\n\n
VBoxManage modifyvm ubuntu18server --cpus 2<\/code><\/pre>\n\n\n\n
Disable Audio for the VM<\/h4>\n\n\n\n
VBoxManage modifyvm ubuntu18server --audio none<\/code><\/pre>\n\n\n\n
Disable USB. USB2.0, USB3.0 controllers.<\/h4>\n\n\n\n
VBoxManage modifyvm ubuntu18server --usb off\nVBoxManage modifyvm ubuntu18server --usbehci off\nVBoxManage modifyvm ubuntu18server --usbxhci off<\/code><\/pre>\n\n\n\n
Define the Networking settings for the VM<\/h2>\n\n\n\n
\n
VBoxManage modifyvm ubuntu18server --nic1 bridged --bridgeadapter1 wlp0s20f3 --nic2 nat<\/code><\/pre>\n\n\n\n
Virtual Machine Unattended Installation<\/h2>\n\n\n\n
VBoxManage unattended install ubuntu18server \\\n--user=kifarunix --password=P@SSWORD \\\n--country=US --time-zone=EST \\\n--language=en-US \\\n--hostname=ubuntu18server.kifarunix.com \\\n--iso=\/home\/kifarunix\/Downloads\/iso\/Debian\/ubuntu-22.04-desktop-amd64.iso \\\n--start-vm=gui<\/code><\/pre>\n\n\n\n
\nVBoxManage: info: Starting unattended installation of Ubuntu_64 in machine 'ubuntu18server' (0875d510-dbe1-456f-8e72-ee2ee28757ad).\nVBoxManage: info: Using values:\n isoPath = \/home\/kifarunix\/Downloads\/iso\/Debian\/ubuntu-22.04-desktop-amd64.iso\n user = kifarunix\n password = P@SSWORD\n fullUserName = \n productKey = \n additionsIsoPath = \/usr\/share\/virtualbox\/VBoxGuestAdditions.iso\n installGuestAdditions = false\n validationKitIsoPath = \n installTestExecService = false\n locale = en_US\n country = US\n timeZone = EST\n proxy = \n hostname = ubuntu18server.kifarunix.com\n packageSelectionAdjustments = \n auxiliaryBasePath = \/home\/kifarunix\/vol01\/VirtualBox VMs\/ubuntu18server\/Unattended-0875d510-dbe1-456f-8e72-ee2ee28757ad-\n imageIndex = 1\n scriptTemplatePath = \/usr\/share\/virtualbox\/UnattendedTemplates\/ubuntu_preseed.cfg\n postInstallScriptTemplatePath = \/usr\/share\/virtualbox\/UnattendedTemplates\/debian_postinstall.sh\n postInstallCommand = \n extraInstallKernelParameters = auto=true preseed\/file=\/cdrom\/preseed.cfg priority=critical quiet splash noprompt noshell automatic-ubiquity debian-installer\/locale=en_US keyboard-configuration\/layoutcode=us languagechooser\/language-name=English localechooser\/supported-locales=en_US.UTF-8 countrychooser\/shortlist=US --\n language = en-US\n detectedOSTypeId = Ubuntu_64\n detectedOSVersion = 18.04.1 LTS \"Jammy Jellyfish\"\n detectedOSFlavor = Ubuntu-Server \n detectedOSLanguages = en-US\n detectedOSHints = \nVBoxManage: info: Waiting for VM 'ubuntu18server' to power on...\nVBoxManage: info: VM 'ubuntu18server' (0875d510-dbe1-456f-8e72-ee2ee28757ad) has been successfully started.\n<\/code><\/pre>\n\n\n\n
\n
Other Tutorials<\/h2>\n\n\n\n