Summary
Steps on how to install and configure Ubuntu Server 22.04 running on a VirtualBox VM ("virtual machine").
- host: is the PC that runs VirtualBox (Vbox).
- guest: is the VM that is running in VBox.
Note I run VirtualBox (Vbox) on my host PC which is also Ubuntu 22.04. But it should work correctly on Windows or macOS.
Initial
- download Ubuntu 22.04 Desktop https://ubuntu.com/download/desktop
Guest info
- choose a username for your guest account: e.g. guest_userid
- choose a password for your guest account: e.g. guest_password
- choose a name for the guest VM: e.g. guest_name
Shared directory
- a directory name to share e.g. "shared_dir"
- choose a directory on your host PC for the shared directory e.g. /home/host_userid/shared_dir
- choose a directory on the guest VM for the shared directory e.g. /home/guest_userid/shared_dir
- you can have different names, but it is much easier to remember the same name on both host and guest.
Ethernet access
- I assumed that you may want to connect to the VM from multiple PC's on your local internet e.g. on a second PC.
- I also assumed you can assign a fixed IP address to the VM via your router e.g. 10.0.0.10
create VM
-
open vbox
- click Machine
- click New
- name: guest_name
- type: Linux
- version: Ubuntu (64-bit)
- click Next
- memory, select 8192MB, click Next
- Hard Disk, create virtual hard disk now, click Create
- Hard disk file type, VDI, click Next
- Storage, Dynamically allocated, click Next
- File location and size, 30GB (minimum), click Create
-
right click, click Settings
- General:
- Advanced:
- shared clipboard: Bidirectional
- Drag'n'Drop: Bidirectional
- other defaults are ok
- Advanced:
- 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
- Adapter 1:
- Serial Ports: defaults are ok
- USB: defaults are ok
- Shared Folders:
- on host: open a terminal; mkdir -p ~/shared_dir
- click Blue Folder+ icon
- Folder Path:
- right menu: select Other and then locate and select /home/$host_userid/shared_dir (this is on the host)
- Folder Name: shared_dir
- click Auto-mount
- Mount-point: /home/$guest_userid/shared_dir (this is on the guest)
- click OK
- Folder Path:
- User Interface: defaults are ok
- General:
- click OK
Install Ubuntu on VM
-
click Start
- Get "GNU GRUB" menu; select Try or Install Ubuntu, wait for boot to finish takes about 1m
- Get "Install" dlgbox; click Install Ubuntu
- keyboard selection, click Continue
- Updates and other software:
- select:
- Normal Installation: with browser, media players, games, etc.
- Minimal Installation: excludes all those
- select Download updates while installing Ubuntu
- select Install third-party software
- click continue
- select:
- Installation type: "Erase disk and install Ubuntu" default 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
- wait... takes about 15m
-
dlgbox "Installation Complete", click "Restart Now"
-
logoff screen: "Please remove the installation medium"
- click on Devices in top menu
- Optical Drive, select "Remove disk from virtual drive"
- click inside VM and press Enter
-
system reboots; wait 1m...
- login screen: select $host_userid, enter pwd
- dlgbox "Online Accounts", click skip
- "Ubuntu Pro", click Next
- "Help Improve Ubuntu", select No don't send, click Next
- "Privacy", click Next
- "Ready to go!", click Done
initial setup
-
Note: if you get the update software dlgbox, close it, going to do that below.
-
Open Terminal, add to favorites
-
check internet connection
# guest
ip address
# note the ip address 10.0.0.10 (for example)
# to test connection to internet
ping google.com
# should see ping responses from google
-
if it fails to connect to ethernet:
- click Devices | Network | Connect Network Adapter
- repeat: click Devices | Network | Connect Network Adapter
-
update to latest versions
cd ~
mkdir -p projects # this is what I put all of my projects into on all my machines. YMMV.
mkdir -p shared_dir
sudo chown $USER:$USER shared_dir
sudo apt update
sudo apt upgrade
# takes about 5m; may take more...
sudo apt autoremove
sudo apt autoclean
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
-
open Devices
- Insert Guest Additions CD image...
- the Guest Additions icon should appear
- right click, select "New Window"
- there should be an "autorun.sh" file; right click on it
- click "Run as a program"
- enter the root password (same as your password)
- a terminal opens
- "Do you wish to continue", enter "yes", press enter
- wait 20s...
- "Press Return to close this window", press enter
-
power off the guest either by closing the VM window or by click File | Close in the VM menu
- dlgbox "Close Virtual Machine"
- select "Power off the machine"
- click OK
- from vbox manager: start it up
- login
-
the VBOX CD icon should still be there
- right click, select unmount
- right click, select eject
- Or, you can also use Devices | Optical Drives | Remove disk from virtual drive
-
open terminal
check mouse cut-n-paste integration
- cut-n-paste a line from the terminal onto your guest machine
- if it doesn't work
- re-install build-essential and virtual-guest-utils (in that order)
- power off and power on the VM
- if it doesn't work
check shared_dir permissions
cd ~
ls -al shared_dir
<snip>
drwxrwx--- 1 root vboxsf 4096 Dec 20 16:25 shared_dir/
# the key is the "vboxsf" group
check shared folder
- in host terminal: touch ~/shared_dir/x.txt
# host:
echo from host > ~/shared_dir/host.txt
# host:
ls ~/shared_dir
# should see host.txt
cat ~/shared_dir/host.txt
# if fails, check Devices | Shared Folders | Shared Folder Settings
# ensure Auto-mount is selected; click OK
# then in the terminal "sudo mount -a"
# check the other direction
# host:
echo from host > ~/shared_dir/host.txt
# host:
ls ~/shared_dir/host.txt
# should see host.txt
cat ~/shared_dir/host.txt
set date/time and timezone
- useful to have your guest VM and your host PC on the same date/time and timezone
sudo apt install -y ntpdate
sudo timedatectl set-ntp off
sudo timedatectl set-ntp on
# Note: change to your appropriate timezone
sudo timedatectl set-timezone America/Edmonton
date
# confirm the date-time is correct
# open a browser and go to https://time.is
# should say "Your time is exact"
Take a VBox snapshot
-
Take a snapshot:
- click Machine
- Take Snapshot...
- enter "base-os" for Snapshot Name
- click OK
- Use this snapshot to easily revert to this point.
- Note: I use this ability to redo and recheck installation instructions
-
shutdown the VM window; select "Save the machine state", click OK