February 13, 2019

OpenBSD: qemu

Sometimes I need to use a programme which is not available on OpenBSD because of a number of reasons. While I have a partition with linux on my laptop as well to do these things, it’s cumbersome to have to shutdown the laptop and reboot. This is why I decided to use qemu.

The installation itself

First, create an image of about 10G:

$ qemu-img create ubuntu.img 10G

Pick up the mini.iso from ubuntu (http://cdimage.ubuntu.com/netboot/) and install it with:

$ qemu-system-x86_64 -hda ubuntu.img -boot d -cdrom /path/to/mini.iso -m 640

The script to launch qemu is

$ cat QEMU.sh
#!/bin/sh

# Necessary to allow for memory larger than 640
# Check zsh ulimit -a
# -d: data seg size (kbytes)
ulimit -d 6000000

# Run qemu
qemu-system-x86_64 -m 2G \
-vga vmware \
-show-cursor \
-machine type=pc \
-usb \
-net nic \
-net user,hostfwd=tcp::2222-:22 \
-soundhw all \
/home/pau/QEMU/ubuntu.img

Access your VM with ssh

Set up ssh in the virtual machine (you need both, the server and the client)

$ sudo apt-get install openssh-client openssh-server

Edit /etc/ssh/sshd_config and uncomment port 22.

This allows to ssh/copy files from the host to the virtual machine via

$ scp -P 2222 FILE pau@localhost:

I mostly connect to the virtual machine to work, because it’s faster:

$ ssh -p 2222 -XYC pau@localhost

To ssh without a password, simple copy/append your id_rsa.pub to the authorized_keys of your vm. Before that, run in your vm:

$ ssh-keygen -t rsa

Install software

As a reminder to myself of the software I’m using on the VM
$ sudo apt install vim openssh-client openssh-server zsh texlive-font-utils texlive-extra-utils \
python-pip debian-goodies gfortran libgfortran4 gcc-7-base lubuntu-desktop

The last package will install an insane amount of things, including libreoffice etc but it’s interesting anyway. Remove large packages later by sorting them by size with

$ dpigs

This command is provided by debian-goodies. An alternative is

$ dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n

One thing I have installed on this VM is skype. The steps are

$ wget https://repo.skype.com/latest/skypeforlinux-64.deb

Add gdebi

$ sudo apt-get install gdebi

And finally

$ sudo gdebi skypeforlinux-64.deb

Starting X

I remove the login managers,

$ apt purge gdm3* sddm*

because I prefer to connect via ssh and I don’t want to have X running. Also, I use openbox as the wm because it’s light and fixes a number of things that e.g. xfce4 has, like a disappearing cursor.

Keep it updated

Using this script

#!/bin/sh
sudo apt update
sudo apt -y upgrade
sudo apt autoclean
sudo apt clean
sudo apt -y autoremove

# old kernels
# sudo apt install byobu
sudo purge-old-kernels

Getting in and out

If you click on the VM, your cursor will be in that window. To get out and back to your host,

Ctrl+Alt g