1

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).

1 Answer 1

1

In QEMU:

Rather than a pure text based approach another possibility is to start QEMU with a VNC server. This is done with the -vnc command line option to QEMU. Then you can connect to that VNC instance from another machine via ssh proxy or whatever and get a GUI that can install any supported OS.

If you only want to use a text console then the choices will be more limited. Ubuntu install ISO's seem to try to use a graphical mode no matter what you do. The deprecated Ubuntu mini.iso may work though. Debian does work and I'll show how to use that.

This assumes you have a Debian ISO installer image available here.

# create empty virtual hard drive
qemu-img create -f qcow2 debian.qcow2 16G
# start VM
qemu-system-x86_64 -machine accel=kvm -m 1G -nographic -hda debian.qcow2 -boot d -cdrom debian-11.2.0-amd64-netinst.iso

As soon as it starts quickly press ESC (or CTRL+C works too) and you should get a boot: prompt. Then type install console=ttyS0 or use one of the other boot options with console=ttyS0 appended (press tab to list).

Modify the qemu parameters for your desired setup as far as disk configuration/network/etc.

And BTW, you can install OpenBSD (other BSD's?) in a similar fashion. At the boot> prompt type set tty com0 then press Return twice.


Notes:

  • you may need to remove -machine accel=kvm if it doesn't work
  • it is ttyS0 (the letter 'S', not the number '5')
  • when install finishes, use CTRL+AX to shutdown
  • after shutdown, to run normally without installer: qemu-system-x86_64 -m 1G -nographic -hda debian.qcow2
  • to transfer files from guest to host, follow https://unix.stackexchange.com/a/196074

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.