On a Ubuntu Desktop host, how can I install and run Ubuntu Server guest completely headlessly using a terminal/vboxmanage? (this means no GUI at all, not even for the initial Ubuntu Server setup)
I am aiming for a text user interface (TUI)-only guest (to run commands, like apt-get update in guest), with a shared folder to host (to transfer files from guest to host).
This is the script I have so far that creates a virtual machine (VM) and starts it:
vm_iso="ubuntu-server-20.04.iso"
vm_name="UbuntuServerTest"
vm_vdi="$HOME/virtualbox/${vm_name}.vdi"
curl -o "$vm_iso" "https://releases.ubuntu.com/20.04.4/ubuntu-20.04.4-live-server-amd64.iso"
vboxmanage createvm \
--ostype Ubuntu_64 \
--basefolder "$HOME/virtualbox" \
--register \
--name "$vm_name"
# VBoxManage showvminfo "$vm_name"
vboxmanage modifyvm "$vm_name" \
--memory 1024 \
--nic1 nat \
--vrde on --vrdeport 33890
vboxmanage createhd \
--filename "$vm_vdi" \
--format VDI --size 10240
vboxmanage storagectl "$vm_name" \
--name "SATA" \
--add sata
vboxmanage storageattach "$vm_name" \
--storagectl SATA --port 0 --type hdd \
--medium "$vm_vdi"
vboxmanage storageattach "$vm_name" \
--storagectl SATA --port 15 --type dvddrive \
--medium "$vm_iso"
vboxmanage startvm "$vm_name" --type headless
# vboxmanage sharedfolder add "$vm_name" --name shared --hostpath "shared_path" --automount
# vboxmanage controlvm "$vm_name" pause --type headless
# vboxmanage controlvm "$vm_name" resume --type headless
# vboxmanage controlvm "$vm_name" poweroff --type headless
Although the script uses VirtualBox, I am okay with QEMU or other software (as long as I can run arbitrary commands headlessly, transfer files from guest to host headlessly, and the kernel is virtualized).