How do i create a virtualbox vm using the cli?



  • Determine which OS types you want to install.

    $ vboxmanage list ostypes | grep -i ubu
    ID:          Ubuntu
    Description: Ubuntu (32-bit)
    ID:          Ubuntu_64
    Description: Ubuntu (64-bit)
    

    Create a template for your vm.

    $ vboxmanage createvm --name UAT --ostype Ubuntu_64 --register
    Virtual machine 'UAT' is created and registered.
    UUID: 4ab9a2a0-dd4c-864c-ad28-f19397ddca5a
    Settings file: '/home/trainer/VirtualBox VMs/UAT/UAT.vbox'
    

    Check your settings as you go, you can see the default sizing is not practical, so needs to be changed.

    $ VBoxManage showvminfo UAT
    
    $ VBoxManage showvminfo UAT | grep -i cpu
    CPU exec cap:    100%
    Number of CPUs:  1
    CPUID Portability Level: 0
    CPUID overrides: None
    
    $ VBoxManage showvminfo UAT | grep -i mem
    Memory size:     128MB
    Configured memory balloon size:      0 MB
    
    $ VBoxManage showvminfo UAT | grep -i ram
    VRAM size:       8MB
    

    Change the memory and virtual ram size.

    $ VBoxManage modifyvm UAT --memory 1048 --vram 16
    

    Change the NIC settings.

    List current NIC settings.

    $ VBoxManage showvminfo UAT | grep -i nic
    NIC 1:           MAC: 08002799DA2E, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
    NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
    NIC 2:           disabled
    NIC 3:           disabled
    NIC 4:           disabled
    NIC 5:           disabled
    NIC 6:           disabled
    NIC 7:           disabled
    NIC 8:           disabled
    
    Change the NIC settings.
    ```bash
    $ VBoxManage modifyvm UAT --nic1 bridged --bridgeadapter1 enp0s5
    

    Check, it is now bridged.

    $ VBoxManage showvminfo UAT | grep -i nicNIC 1:           MAC: 08002799DA2E, Attachment: Bridged Interface 'enp0s5', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
    NIC 2:           disabled
    NIC 3:           disabled
    NIC 4:           disabled
    NIC 5:           disabled
    NIC 6:           disabled
    NIC 7:           disabled
    NIC 8:           disabled
    

    Create a disk for you new VM.

    $ VBoxManage createhd --filename /home/trainer/VirtualBox\ VMs/u3/u3.vdi --size 5120 --variant Fixed
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Medium created. UUID: 69f345b7-c573-4bf6-83b8-78cf35f59e53
    

    Add a storage controller to your VM

    $ VBoxManage storagectl UAT --name "SATA Controller" --add sata --bootable on
    

    Attach the disk to the disk controller.

    $ VBoxManage storageattach UAT --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium /home/unixbod/VirtualBox\ VMs/u3/u3.vdi
    

    Add a virtual cd/dvd to your VM.

    $ VBoxManage storagectl UAT --name "IDE Controller" --add ide
    

    Attach a medium to your cd/dvd ide controller.

    $ VBoxManage storageattach UAT --storagectl "IDE Controller" --port 0  --device 0 --type dvddrive --medium /home/trainer/Downloads/mini.iso
    

    Start the VM. Bring up a GUI, to continue OS installation.

    $ vboxmanage startvm UAT
    


© Lightnetics 2024