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 Server 22.04 https://ubuntu.com/download/server
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, 10GB (minimum), click Create
-
right click, click Settings
- General: defaults are ok
- System: defaults are ok
- Display: 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.3-live-server-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
- click OK
Install Ubuntu on VM
-
click Start
-
Try or Install Ubuntu, wait for boot to finish
-
English, press Enter
- select Update to the new installer, press Enter
- keyboard selection, Done, press Enter
- tab to Search for third-part drivers, press space to select, press Done
- Network connections, Done, press Enter
- proxy, Done, press Enter
-
Archive mirror, Done, press Enter
-
takes about 1m
-
Guided storage config, Done, press Enter
- Storage Configuration, Done, press Enter
- Confirm destructive action, Continue, press Enter
- Profile setup:
- your name: guest_userid
- server name: guest_name
- username: guest_userid
- pwd: guest_password
- select Done, press Enter
- Ubuntu Pro, Continue, press Enter
- SSH setup: select Install OpenSSH Serve, press Enter to select
- tab to Done, press Enter
- third-party drivers, Continue, press Continue
-
Featured Server Snaps, no changes, Done, press Enter
-
wait... takes about 5 minutes
-
Install Complete!, Reboot Now; press Enter
-
-
"Please remove the installation medium"
- click on Devices in top menu
- Optical Drive, select Remove disk
- click inside VM and press Enter
-
reboot finishes
- if it fails to connect to ethernet:
- click Devices | Network | Connect Network Adapter
- repeat: click Devices | Network | Connect Network Adapter
- login screen: enter guest_userid and guest_password
Check VM internet connection
on guest: find the ip address
ip address
# note the ip address 10.0.0.10 (eg.)
on guest: Check it has access to the internet
ping google.com
# should see ping responses from google
Create a host ssh terminal
on host: check connection to VM
ping 10.0.0.10 (i.e. the guest_ip_address found above)
PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data.
64 bytes from 10.0.0.10: icmp_seq=1 ttl=64 time=0.494 ms
on host: set up ssh connection
sudo nano /etc/hosts
# add line:
# 10.0.0.10 guest_name
$ ssh guest_userid@guest_name
# The authenticity of host '10.0.0.10 (10.0.0.10)' can't be established.
#ECDSA key fingerprint is SHA256:<snip>.
#Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
#Warning: Permanently added '10.0.0.10' (ECDSA) to the list of known hosts.
# guest_userid@10.0.0.10's password:
-
set the IP address as a static address in your router:
- Note: I have a tp-link AX-3000 router, your instruction will be different
- open Router, goto to Advanced, DHCP Server
- find rpi_name
- add it to Address Reservation to maintain the same IP address
-
Note: setting the ip address to static will ensure that the /etc/hosts doesn't need to change, the ssl key doesn't change etc.
on guest: should be in guest terminal now
# you are in the guest terminal and do all normal bash commands ls, cd, etc.
# 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
# note: leave the VM running!
# logout of the ssh terminal
exit
Initial setup
on guest: update OS
cd ~
mkdir -p shared_dir
sudo apt update
sudo apt upgrade
sudo apt autoremove
sudo apt autoclean
on guest: install VBOX guest utils
sudo apt install virtualbox-guest-utils
sudo usermod -aG vboxsf $USER
exit
on guest: re-login and check groups is set correctly
$ ssh guest_userid@guest_name
groups
# confirm vboxsf is a group; needed for shared folders
sudo reboot
# wait 1m
# re-login again
$ ssh guest_userid@guest_name
Check shared folder
- open both a host and a guest terminal on your host PC
# on host terminal, create a file:
echo from host > ~/shared_dir/host.txt
# on guest terminal, check the file is there and the permissions are okay:
ls -al ~/shared_dir
# should see host.txt
cat ~/shared_dir/host.txt
# check the other direction
# on guest terminal, create a file:
echo from guest > ~/shared_dir/guest.txt
# on host terminal, check the file is there and the permissions are okay:
ls -al ~/shared_dir/guest.txt
# should see guest.txt
cat ~/shared_dir/guest.txt
Take a VBox snapshot
-
save VM
- click File | Close
- select Save the Machine State
-
Take a snapshot
- click Machine | Take a Snapshot
- use name: base-os
- Use this snapshot to easily revert to this point.
- Note: I use this ability to redo and recheck installation instructions