In this article I’ll try to get into all (okay, maybe not all) possible troubles related to using a VirtualBox guest-machine with Linux, running on a Mac OS (High Sierra, 10.13) host. But actually it’s not about Mac OS and all the steps will be the same for Windows and Linux hosts too. But anyway.

The aim is to get a Linux guest-machine running in a fullscreen mode on a dedicated desktop (screen) with a decent performance.

Install VirtualBox and create a machine

Nothing special here, except for maybe Gatekeeper (or whoever) that might block VirtualBox from installing/starting. In that case you’ll need to go to Security & Privacy and allow it (Open Anyway).

Create a new virtual machine. Give it 4 GB RAM and 128 MB video. Just in case, that’s my settings:

VirtualBox, machine settings

And I did not enable 2D/3D acceleration.

Insert Linux installation image (I usen Debian) into machine, start it and install Linux there.

Having done that you might notice that you can only have maximum 1024x768 resolution. To have more you need to download Extension Pack for VirtualBox (and install Guest Additions for guest-machine).

Install Guest Additions

Open terminal in your guest-machine and install necessary packages:

apt-get install build-essential linux-headers-$(uname -r)

Insert Guest Additions image:

VirtualBox, inserting Guest Additions

It will get mounted as a CD-ROM. Open it and copy VBoxLinuxAdditions.run from there to /tmp/. Go there in terminal and execute:

chmod +x VBoxLinuxAdditions.run
./VBoxLinuxAdditions.run

It might give you some warning about session manager and some unsupported protocols, but for me it didn’t affect anything. Reboot the guest-machine and you’ll have a proper screen resolution.

Extend the size of your VDI

I miscalculated the size of my virtual disk image (VDI). I gave it 20 GB initially, but having installed the stuff I wanted (Qt with Device Creation packages), I discovered that I have only ~4 GB left, but I needed to install even more stuff, which meant I needed to increase my VDI to at least 30 GB (add 10 GB more). But here’s problem - I created a fixed size VDI (I always create fixed ones), which is a bit problematic to resize (fixed, eh). But it is still possible.

Shutdown the guest-machine and exit VirtualBox app. Open Terminal, find VBoxManage and run modification command:

cd /Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM.app/Contents/MacOS/
./VBoxManage modifyhd --resize 30000 "/Users/YOURNAME/VirtualBox VMs/debian/debian.vdi"

Oh shit, I forgot (again) that I have a fixed VDI, so I got this error:

Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize medium operation for this format is not implemented yet!

You need to clone the disk first:

./VBoxManage clonehd "/Users/YOURNAME/VirtualBox VMs/debian/debian.vdi" "/Users/YOURNAME/VirtualBox VMs/debian/debian-dyn.vdi"

Now you can resize the cloned disk, because by default new disks are dynamic ones:

./VBoxManage modifyhd --resize 30000 "/Users/YOURNAME/VirtualBox VMs/debian/debian-dyn.vdi"

And after that make a fixed clone of it:

./VBoxManage clonehd "/Users/YOURNAME/VirtualBox VMs/debian/debian-dyn.vdi" "/Users/YOURNAME/VirtualBox VMs/debian/debian-fix.vdi" --variant fixed

Now go to your guest-machine settings and delete old disk from SATA controller. And then delete it from Virtual Media Manager. And now add your new extended disk to your machine’s SATA controller:

VirtualBox, SATA controller

But then you need to edit partitions inside the guest-machine to extend old ones to the free space. You can use GParted for that. And better to do it from a Live CD.

In my case GParted didn’t allow me to extend existing partition to the free space because I had swap area between them. So I deleted it, extended the main partition and re-created swap area back.

But after that I got the following error during the boot:

a start job is running for dev-disk-by...

It’s nothing serious, because after 90 seconds OS boots normally. But anyway it’s better to fix it: wait for the system to boot and edit /etc/fstab file: updating the GUID of deleted swap partition with the new value (you can look for it in the GParted).

By the way, don’t forget to right-click on swap partition at GParted and set Swapon option (on the screenshot it is already pressed, so you can see Swapoff):

GParted, Swapon

Switch to LXDE

So, I got my guest-machine running in fullscreen, I managed to extend its disk, but there was an annoying feeling that it wasn’t performing well. It wasn’t very responsive and even mouse pointer was moving with delays. But it was tolerable. Till the moment I ran a Knoppix Live CD, and it was really fast, so immediately I suspected my Xfce DE and decided to try some other (LXDE). Turns out, it’s quite an easy thing to do:

apt-get install lxde lxsession

And that’s it. Now simply reboot you guest-machine and choose LXDE at logon screen. For me performance of guest-machine got significantly improved.

So, that was the last of my problems and now I can easily switch between my Mac OS host and Linux virtual machine using 3-finger swipe just like this:

If video doesn’t play in your browser, you can download it here.

…Yes, I have an unregistered Sublime Text. But it’s just too damn expensive ($80) and I haven’t decided yet it will be my main editor. I’m still evaluating several others.

Exchange files with guest machine

Guest machine is running fine, but how to exchange files with it? There are ways to do it via shared folder or even drag-and-drop from host, but I prefer to use an SSH server and connect via SFTP, since it’s Linux we’re talking about anyway.

Network

By default guest machines get only NAT network, so they have access to internet, but they are “invisible” for their hosts - you can’t even ping it. To establish a direct “link” between host and guest go to the VirtualBox’s Preferences and create a host-only network like it is shown on screenshots:

VirtualBox host-only network
VirtualBox host-only network, adapter
VirtualBox host-only network, DHCP

After that you can run ifconfig on your MacOS host and see that vboxnet0 was created.

Now open Settings of your guest machine, add Adapter 2 and choose vboxnet0:

VirtualBox host-only adapter

Start your guest machine and edit network interfaces:

vi /etc/network/interfaces

Add this to the end of the file:

auto enp0s8
iface enp0s8 inet static
address 192.168.56.105
netmask 255.255.255.0

You might have different name of the interface (mine is enp0s8) - check ifconfig/ip a. And as you can see, I set a static IP for the guest machine, because I want to save connection settings in my FTP-client. So, actually there was no point in setting DHCP in VirtualBox preferences.

Save the file and reboot the guest machine (just in case). Now you should be able to ping it from your host.

SFTP

If simply connecting to the host via SSH under your username doesn’t work, then you’ll need to set-up an SSH server. I used this instruction.

Most probably you already have SSH server installed in your guest machine. If not, then install it:

apt-get install openssh-server

Add a new group and include your user (mine is vasya) to it (or you can create a new user, but that’s just a virtual machine, so I prefer to keep things easy):

groupadd sftpgroup
usermod -a -G sftpgroup vasya

Now create a folder, that will be accessed via SFTP, and then create a share folder inside it and make vasya:sftpgroup its owner:

mkdir /var/sftp
cd /var/sftp
mkdir share
chown vasya:sftpgroup share

Edit SSH server config:

vi /etc/ssh/sshd_config

Find Subsystem sftp string, comment default value and add new one:

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp

Go to the very end of file (it is important) and add settings for your share folder:

Match group sftpgroup
ChrootDirectory /var/sftp
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

Save the file and restart SSH server:

systemctl restart ssh.service

If you didn’t place Match section in the very end of the config, then you will get an error like this:

directive 'printmotd' is not allowed within a match block

Pay attention, will you? Go back and fix it.

After SSH server will restart successfully, you will be able to connect to your guest machine via any FTP client (that supports SFTP) from your host:

Transmit SFTP connection