Setup a VirtualBox VM for testing projects under Ubuntu

How to create a VM Project Test

I use VirtualBox ("vbox") for testing various things. These are instructions to set up a minimal VM for testing an Ubuntu Desktop installation.

Why vbox? Because I can reset to a known state of the OS installation using snapshots. These instructions will create a "base-os" snapshot to get to a base level clean installation.

create VM

  • download Ubuntu Desktop 22.04 https://ubuntu.com/download/desktop

  • open vbox manager

    • click Machine | New
    • click New
      • name: webserver
      • type: Linux
      • version: Ubuntu (64-bit)
    • memory, select 8192MB, click Next
    • Hard Disk, create virtual hard disk, click Create
    • Hard disk file type, VDI, click Next
    • Storage, Dynamically allocated, click Next
    • File location and size, 30GB (minimum), click Create (Note: it will fail at 20GB.)
  • right click, click Settings

    • General:
      • Advanced:
        • shared clipboard: Bidirectional
        • Drag'n'Drop: Bidirectional
      • other defaults are ok
    • System: defaults are ok
    • Display:
      • Screen: Acceleration, check Enable 3D Acceleration
      • other defaults are ok
    • Storage:
      • click Controller: IDE | Empty
      • click Live CD/DVD
      • click blue disk icon
      • choose a disk file: select in Downloads: ubuntu-22.04.4-desktop-amd64.iso
      • click Open
    • Audio: defaults are ok
    • Network
      • Adapter 1:
        • Attached to: Bridged Adapter
        • Name: en01
    • Serial Ports: defaults are ok
    • USB: defaults are ok
    • Shared Folders:
      • on host: open a terminal; mkdir -p ~/vm-shared
      • click Blue Folder+ icon
        • Folder Path:
          • right menu: select Other and then locate and select /home/$host_userid/vm-shared
        • Folder Name: vm-shared
          • click Auto-mount
        • Mount-point: /home/$host_userid/vm-shared (this is on the host)
        • click OK
    • User Interface: defaults are ok
  • click OK

Install Ubuntu

  • click Start

    • "Try or Install Ubuntu", wait for boot to finish
    • dlgbox "Install", click Install Ubuntu
    • keyboard selection, click Continue
    • Updates and other software:
      • select Minimal Installation
      • select Download updates while installing Ubuntu
      • select Install third-party software
      • click continue
    • Installation type: defaults okay, click Install Now
      • dlgbox: Write the changes to disks? click Continue
    • Where are you? select timezone, click continue
    • Who are you?
      • your name: %host_userid%
      • server name: vm-2
      • username: %host_userid%
      • pwd: yaknow
      • select require my password to log in
      • click Continue
    • takes about 10m
  • dlgbox "Installation Complete", click Restart Now

  • "Please remove the installation medium"

    • click on Devices in top menu
    • Optical Drive, un-select .iso
    • click inside VM/Gui and press Enter
  • reboot finishes

  • login screen: select %host_userid%, enter pwd
    • Online Accounts, click skip
    • Ubuntu Pro, click Next
    • Help Improve, select No don't send, click Next
    • Privacy, click Next
    • click Done

Initial setup

  • Open a Terminal, add to favorites
# host
cd ~
mkdir -p projects
mkdir -p vm-shared
sudo chown $USER:$USER vm-shared

sudo apt update
sudo apt upgrade
sudo apt autoremove

sudo apt install build-essential
sudo apt install virtualbox-guest-utils
sudo usermod -aG vboxsf $USER
sudo reboot

# open a terminal
groups
# confirm vboxsf is a group
  • power off the guest
  • from vbox manager: start it up

  • open terminal

# check vm-shared permissions
cd ~
ls -al vm-shared
<snip>
drwxrwx---  1 root    vboxsf  4096 Dec 20 16:25 vm-shared/
# note the "vboxsf" group

check mouse cut-n-paste integration

  • cut-n-paste a line from the terminal onto your host machine
    • if it doesn't work, re-install build-essential and virtual-guest-utils (in that order)
    • power off the VM (not just save)
    • power on the VM from vbox manager

check shared folder

  • in host terminal: touch ~/vm-shared/x.txt
# host:
echo from host > ~/vm-shared/host.txt
# guest:
ls ~/vm-shared
cat ~/vm-shared/host.txt
# should see host.txt with content "from host"

# check the other direction
# guest:
echo from guest > ~/vm-shared/guest.txt
# host:
ls ~/vm-shared/guest.txt
cat ~/vm-shared/guest.txt
# should see guest.txt with content "from guest"

Take a snapshot

  • save VM
  • Take a snapshot: base-os
  • restart the VM

To restore to "base-os"

  • use vbox to power off the VM
  • dlgbox "Close Virtual Machine"
    • select Power off the machine.
    • check Restore current snapshot "base-os"
    • click OK

- John Arrizza