Skip to content

Instantly share code, notes, and snippets.

@wisedier
Last active August 18, 2023 14:56
Show Gist options
  • Save wisedier/8af0fbd64e87cacfcfab7b73e40daee0 to your computer and use it in GitHub Desktop.
Save wisedier/8af0fbd64e87cacfcfab7b73e40daee0 to your computer and use it in GitHub Desktop.
Create headless Ubuntu 18.04 virtual machine with Oracle Virtualbox only using command line in offline environment

Installation VirtualBox

  1. Download Ubuntu 18.04 image at here

    I used Kakao Ubuntu mirror server in Korea.

  2. Download Oracle VirtualBox package at here

  3. Download Oracle VirtualBox Extension Pack at here

  4. Install the package

    I constructed a local ubuntu mirror server so that I can use apt install. If you did not do this, you are supposed to move all of dependencies one by one to offline environment from online environment.

    sudo dpkg -i virtualbox-6.0_6.0.14-133895_Ubuntu_bionic_amd64.deb
    sudo apt install --fix-broken  
  5. Sign kernel modules of VirtualBox

    Physical access to the host machine is required to enroll singing key using MOK manager EFI utility. Signing process is at here.

  6. Configure VirtualBox

    sudo /sbin/vboxconfig
    sudo reboot
  7. Install Oracle VirtualBox Extension Pack

    sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-6.0.14.vbox-extpack 

Creating Ubuntu virtual machine

  1. Create network

    There are five modes of network for VirtualBox. I will use NAT Network. You can check other modes in Table 6.1. Overview of Networking Modes. If you want bi-directional communication between host and guest, you have to set the bridge network.

    VBoxManage natnetwork add --netname natnet --network "192.168.1.0/24" --enable --dhpc on
    VBoxManage natnetwork start --netname natnet1
  2. Create virtual machine

    cd some_where_create_a_virtual_machine   
    VBoxManage createvm --name Ubuntu_1804 --ostype Ubuntu_64 --register --basefolder $(pwd)
    VBoxManage modifyvm Ubuntu_1804 --memory 16384 --cpus 4 --boot1 dvd --nic1 natnetwork --nat-network1 natnet1 --hwvirtex on --vrde on --vrdeport 5001
    VBoxManage storagectl Ubuntu_1804 --name "Ubuntu_1804_SATA" --add sata
    VBoxManage createhd --filename $(pwd)/Ubuntu_1804/Ubuntu_1804.vdi --size 131072 --format VDI --variant Standard
    VBoxManage storageattach Ubuntu_1804 --storagectl Ubuntu_1804_SATA --port 1 --type hdd --medium $(pwd)/Ubuntu_1804/Ubuntu_1804.vdi
    VBoxManage storageattach Ubuntu_1804 --storagectl Ubuntu_1804_SATA --port 0 --type dvddrive --medium /tmp/ubuntu-18.04.3-live-server-amd64.iso
    VBoxManage startvm Ubuntu_1804 --type headless
  3. Connect to the Ubuntu Server using Remote Desktop Protocol (RDP)

    • Ctrl + R (Run) - Enter "mstsc" - Enter "[Host IP Address]:5001"

    • Install Ubuntu Server 18.04

  4. Notes

    • Control

      VBoxManage controlvm
      VBoxManage controlvm Ubuntu_1804 pause|resume|reset|poweroff|savestate
    • Port Forward

      To port-forward to some port between 1-1024 (well-known ports), you may need root permission.

      VBoxManage natnetwork modify --netname natnet1 --port-forward-4 "ssh:tcp:[127.0.0.1]:10022:[192.168.1.4]:22"
      ssh [username]@localhost -p 10022
      VBoxManage natnetwork modify --netname natnet1 --port-forward-4 delete ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment