Saturday 6 May 2023

Ubuntu 22.04 installation on VirtualBox using command line

We use VirtualBox for process of preparing VM images for our product. Sadly some things had to be done manually and we're heading towards full automation and it was an attempt to prepare VM for Ubuntu 22.04 installation from ISO using only command line interface.

NB! If you have IPv4 disabled on your machine you have to enable it as otherwise VM will not have connection and installer may fail. 

Set some variables shared by next steps:

export VM_NAME=Ubuntu2204_TEST_OVA

export VM_ROOT_FOLDER="/home/pavel/VirtualBoxVMs"


By default VirtualBox uses path with nasty space in it and that's why I changed it to custom one without spaces as I do not like spaces and bash agrees with me about it. 

Create VM and register it in VirtualBox:

VBoxManage createvm --name $VM_NAME  --register  --ostype=Ubuntu22_LTS_64 --basefolder=$VM_ROOT_FOLDER

If you plan to use another OS then you can get all list of all OS types using this command:

VBoxManage list ostypes

Then set some basic hardware options:

VBoxManage modifyvm $VM_NAME --ioapic on                     

VBoxManage modifyvm $VM_NAME --memory 16384  --vram 128       

VBoxManage modifyvm $VM_NAME --cpus 8

VBoxManage modifyvm $VM_NAME  --nic1 nat

Then create 150G disk for VM and attach it to it:

VBoxManage createhd --filename $VM_FOLDER/disk.vdi --size 150000 --format VDI

Add SATA controller: 

VBoxManage storagectl $VM_NAME  --name "SATA Controller" --add sata --controller IntelAhci

And attach our disk to it: 

VBoxManage storageattach $VM_NAME  --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium  $VM_FOLDER/disk.vdi

Then add IDE controller to mount ISO disk with installer: 

VBoxManage storagectl $VM_NAME  --name "IDE Controller" --add ide --controller PIIX4 

VBoxManage storageattach $VM_NAME --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium ~/Downloads/ubuntu-22.04.2-live-server-amd64.iso 

VBoxManage modifyvm $VM_NAME  --boot1 dvd --boot2 disk --boot3 none --boot4 none

Then you can run VM:

VBoxManage startvm $VM_NAME

Based on this guide

No comments :

Post a Comment

Note: only a member of this blog may post a comment.