Thomas
Redelberger

How to Create a Lean Debian Virtual Machine

Legal Notices

Copyright (c) 2018 Dr. Thomas Redelberger redetho@gmx.de. All rights reserved. You may quote and copy this publication provided you link back to this original web-site. Suggestions for amendments and improvements are welcome.

This information is provided as-is. I do not take any responsibility and do not grant any warranty nor do I imply any fitness for any purpose or kind, nor shall I be liable for any issues when using it.

The original version of this document was in English language. I might do a German version. People are invited to do translations to other languages. But they shall properly cite me and link back to this original web-site.

Introduction

I had created a TinyCore virtual machine for browsing the internet. As from Windows 10 1803, the performance was degraded substantially, as CPU load was close to 100% most of the time. I decided to not investigate this, but rather build a new VM. I chose Debian, because I wanted to go standard and was curious how small a "minimal" VM would be, using the standard Debian distribution.

Hyper-V Set-Up

In Hyper-V I used the same settings I had used for my TinyCore VM. I went for a 5 GB VHD as per Debian sizing guidelines.

From the Hyper-V Integration Services, I switched on:

Debian Installation

I went for the Debian 9 (aka Stretch) 64-bit iso. I had tried Debian 9 32-bit, but it would not work, presumably for the same reason I could not get TinyCore v7 to work (issue with hard disk access).

In the Debian installer, I chose:

Expert Mode allowed me to set two important details right away:

For the minimal install, I deselected everything:

[ ] Debian desktop environment
[ ] . GNOME
[ ] . Xfce
[ ] . KDE
[ ] . Cinnamon
[ ] . MATE
[ ] . LXDE
[ ] web server
[ ] print server
[ ] SSH server
[ ] Standard system utilities

As a simple file manager plus text editor I chose midnight commander, because it can also be used in text mode:

$ apt install mc
$ apt clean

Finally, in terms of size

$ df -h

showed 906 MB.

As my PC is not running round the clock, I needed to add

$ apt install anacron

This makes sure that clean-up tasks like "rotating" log files are done properly. Otherwise the directory /var/log would grow to substantial size over time.

For the X-Windows graphical system, the established standard is:

$ apt install xorg

I chose the minimal X-window manager flwm, the same as with TinyCore:

$ apt install flwm

flwm-topside, which is used in TinyCore, is not available in Debian. flwm-topside has the controls at the top of the window, whereas standard flwm has them on the left. Seems that flwm-topside requires compiling, which I am not (yet) ready to do.

To integrate the X-clipboard with mcedit - the text editor of mc - I installed xclip:

$ apt install xclip

$ apt install firefox

did not work. I had to do

$ apt install firefox-esr

This yielded version 52.5.2 which seemed quite behind the usual Firefox version. Maybe the "esr" is related to this.

For transferring files in and out of the VM, I use an FTP server. There seem to be three choices in Debian:

I went for pure-ftpd, as it was smallest and seemed most easy to use:

$ apt install pure-ftpd

This enabled FTP access to my home directory right away, with no further configuration needed.

My Customisations

Screen Resolution

In

/etc/default/grub

there is

GRUB_CMDLINE_LINUX_DEFAULT="There is probably stuff here"

I changed it to read (1280x1024 is my choice on a 1920x1200 physical screen):

GRUB_CMDLINE_LINUX_DEFAULT="quiet elevator=noop splash video=hyperv_fb:1280x1024"

followed by

$ sudo update-grub

Customised Menu of the flwm Window-Manager

The standard way to launch programs from flwm is a right-click on the desktop. To customise that pop-up menu, I created the directory

~/.wmx

If ~/.wmx exists, it replaces the default menu, which is configured under

/var/lib/flwm/wmx

which is auto-generated. I used it as a reference.

~/.wmx shall contain another directory Applications, where I put four shell scripts called Firefox, MC, MCEdit and Terminal, containing:

#!/bin/sh
exec firefox

#!/bin/sh
exec xterm -e mc

#!/bin/sh
exec xterm -e mcedit

#!/bin/sh
exec xterm

Customising my X-Session

I also created a file

~/.xsession

This file customises what happens, when I do a startx from the command line:

#!/bin/sh
xsetroot -solid \#0E5CA8
###xrdb .Xresources
# xset, xmodmap, other configuration programs
#
# flwm -x: menu will say Exit instead of Logout
flwm -x &
#
WindowManager=$!
#
# xterm, other automatically-launched programs
firefox &
/home/myusername/myClpbrdd.sh &
#
wait $WindowManager

xsetroot sets the desktop background to a colour I prefer.

flwm & starts the X-window manager. The -x will just bring me back to the terminal instead of logging me out, when I select the Exit pop-up menu item in flwm. Without -x the menu item will read Logout.

firefox &  already fires up one browser window ready to be used.

myClpbrdd.sh is a small demon I wrote to accept Windows clipboard data in the VM, and populate the X-windows clipboard. There is a corresponding VBscript file on the Windows side.

Autologin as non-privileged user

I want the system to log me in as a non-privileged user automatically. I found the following solution on the Internet:

$ mkdir /etc/systemd/system/getty@tty1.service.d
$ mcedit /etc/systemd/system/getty@tty1.service.d/override.conf

The file override.conf contains:

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin myusername --noclear %I $TERM

I am not clear, what the first ExecStart= line does.

Starting X-Windows automatically

I further add the following line to ~/.profile

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx

I could create further virtual text consoles (i.e. non-X-windows) with CTRL-ALT-F2, etc., for example to do shutdown or reboot, which only root can do. CTRL-ALT-F1 brings me back to my un-privileged desktop.

However, normally I do not need to shutdown the Debian system, as I have Hyper-V start and shutdown the VM automatically, when Windows starts and stops. However, I noticed that recent Windows versions do not seem to normally shutdown and start VMs, but rather put VMs to sleep and wake them up again, like Windows itself.

The Debian VM seems fine with this. For example, the system clock is always OK. I could not manage to get the clock synchronised in TinyCore.

Using the X-clipboard in mcedit

To be able to exchange text content between mcedit (the text editor component of mc) and the X-windows clipboard, I needed to edit the file

~/.config/mc/ini

For that I have to use the nano editor, which seems to be installed by default. I could not use mcedit itself for that task, because the file would be overwritten on exit and my changes lost.

$ nano ~/.config/mc/ini

I looked for lines

clipboard_store=
clipboard_paste=

and replaced them by

clipboard_store=xclip -i -selection clipboard
clipboard_paste=xclip -o -selection clipboard

For example, you could copy text in Firefox using CTRL-C. In mcedit you would paste it using SHFT-Insert.

In mcedit, CTRL-Insert does copy, SHFT-Del does cut.

In doubt do F9 "menu" to see the short-cuts.

X-Clipboard Integration with Windows

I created a VBscript Clpbrd-ftp-Deb.vbs to upload the Windows clipboard text content to a directory called Downloads under the home directory of my non-priv. account in the Debian VM.

In the VM the script myClpbrdd.sh

When I want to bring text from Windows into the VM, the steps are:

So it is only one more step as natively in Windows or X-Windows.

Comparison with my TinyCore VM

Effort to Set-Up

To compare the effort for setting up the TinyCore VM and the Debian VM, I use my subjective feeling how long it took and how much I needed to read, to get the tasks done:

I also hope that Debian will keep being maintained and stable for the foreseeable future.

About Versatility

I had set-up the TinyCore VM solely as a secure environment to browse the web. The Debian VM as described above has exactly the same functionality.

However, the Debian VM is based on a standard set-up that can be extended to any use easily using the well-established and documented apt tool. When you combine this with "cloning" VMs and with using Hyper-V Restore Points, you can easily generate flexible and powerful environments.

True, a TinyCore system can also be extended to any use with its built-in tools. But the delta will be much bigger and the effort higher, because you start from a "tiny" system.

Keeping the System Lean and Up-To-Date

All below needs to be done as root user.

I was curious to see how much space the Debian VM would require and I wanted to make sure I could control its size when maintaining it going forward. To see the effect, I first did

$ df -h

I removed unused packages by

$ apt autoremove

Reducing the apt Package Cache

First check how big:

$ du -sh /var/cache/apt

Then clean it up:

$ apt clean

Check Application Caches (e.g. Thunderbird, Firefox?)

$ du -sh ~/.cache

and then e.g.

$ rm -rf ~/.cache/mozilla/*

Only keep needed Language Locales

Check active locale :

$ locale

See all installed locales :

$ locales -a

This showed in my case:

C
C.UTF-8
en_US.utf8
Posix

which looks lean to me. If needed, unused locales could be removed by using the localepurge package.

Check Size Finally

$ df -h

My VM uses about 2.0 GB. Hence there is some spare space left from the total 5 GB size of the VHD. That space is available for file up/download, as files first go to the Downloads directory and then get transferred to/from Windows using FTP.

Keeping the System Up-to-Date

Using

$ apt update
$ apt upgrade

keeps the system up-to-date. This has to be done as root.


Last change: 2018-08-25
© 2002-2018 Dr. Thomas Redelberger redethogmx.de