Ubuntu/Debian: Not enough free space on disk ‘/boot’ when updating the OS

My /boot partition is only 512MB and I get this error message every now and then when updating:

Not enough free space

The upgrade needs a total of xx.x M free space on disk ‘/boot’. Please free at least an additional xx.x M of disk space on ‘/boot’. You can remove old kernels using ‘sudo apt autoremove’, and you could set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs.

The obvious process is to expand /boot to be at least 1GB and be more careful in the future when partitioning during the OS installation.

Luckily there are a couple of things to try before repartitioning.

Try cleaning old kernels automatically:

# apt autoremove

Compress your initramfs by editing /etc/initramfs-tools/initramfs.conf

# vim /etc/initramfs-tools/initramfs.conf

and change the COMPRESS entry to:

COMPRESS=xz

You might need to rebuild your initramfs for the compression to start applying.

If after doing the above you still don’t have enough free space you can manually delete old kernels.

First check which Linux kernel you are on:

# uname -r

4.15.0-76-generic

In the example above the current kernel is 4.15.0-76. It is really important that the current used kernel is left untouched on the system. Under no circumstances should it be removed.

Check which kernels are on your system:

# dpkg -l | grep linux-image

rc  linux-image-4.15.0-55-generic              4.15.0-55.60                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-58-generic              4.15.0-58.64                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-60-generic              4.15.0-60.67                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-62-generic              4.15.0-62.69                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-64-generic              4.15.0-64.73                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-65-generic              4.15.0-65.74                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-66-generic              4.15.0-66.75                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-69-generic              4.15.0-69.78                                     amd64        Signed kernel image generic
rc  linux-image-4.15.0-70-generic              4.15.0-70.79                                     amd64        Signed kernel image generic
ii  linux-image-4.15.0-72-generic              4.15.0-72.81                                     amd64        Signed kernel image generic
ii  linux-image-4.15.0-74-generic              4.15.0-74.84                                     amd64        Signed kernel image generic
ii  linux-image-4.15.0-76-generic              4.15.0-76.86                                     amd64        Signed kernel image generic
ii  linux-image-generic                        4.15.0.76.78                                     amd64        Generic Linux kernel image

The first column of the output provides a 2-3 letter code with useful information on the status of each package.

For reference this is their meaning:

First letter. Desired package state:

u ... unknown
i ... install
r ... remove/deinstall
p ... purge (remove including config files)
h ... hold

Second letter. Current package state:

n ... not-installed
i ... installed
c ... config-files (only config files are installed)
U ... unpacked
F ... half-configured (configuration failed for some reason)
h ... half-installed (installation failed for some reason)
W ... triggers-awaited (package is waiting for a trigger from another package)
t ... triggers-pending (package has been triggered)

Third letter. Error state:

R ... reinstallation-required (package broken, reinstallation required)

From the previous output we know that there are some config files left around (rc header), and that several kernel images are still installed (ii header).

The ii ones are the ones consuming the space we need to free up. We need to remove some of those.

We have to keep the current kernel version and at least one or two previous versions as good practice.

So based on all of the above and in this example:

To remove
linux-image-4.15.0-55-generic
linux-image-4.15.0-58-generic
linux-image-4.15.0-60-generic
linux-image-4.15.0-62-generic
linux-image-4.15.0-64-generic
linux-image-4.15.0-65-generic
linux-image-4.15.0-66-generic
linux-image-4.15.0-69-generic
linux-image-4.15.0-70-generic
linux-image-4.15.0-72-generic

To keep
linux-image-4.15.0-74-generic (previous)
linux-image-4.15.0-76-generic (current)

You can remove them one by one:

# apt purge linux-image-4.15.0-55-generic
# apt purge linux-image-4.15.0-58-generic
# apt purge linux-image-4.15.0-60-generic
.
.
.

Or all of them in one go with:

# apt purge linux-image-4.15.0-{55,58,60,62,64,65,66,69,60,72}-generic

This will free up enough space of /boot until you repartition.




Linux: Configure locale and keyboard layout when remotely accessing from a Mac

At work I have to remote into several different Linux systems from a Mac and there is always the pain of having to handle different keyboard layouts if using Synergy or VMs.

The conversion from a Mac keyboard layout doesn’t translate correctly when the Linux system has the keyboard configured as a PC.

First find out what the current configuration is.

$ localectl

The output in a British system is:

  System Locale: LANG=en_GB.UTF-8
                 LANGUAGE=en_GB:en
     VC Keymap : n/a
     X11 Layout: gb
      X11 Model: pc105
    X11 Options: terminate:ctrl_alt_bksp

Note that the last line might not show in Ubuntu systems.

Unfortunately if you are accessing from a Mac this layout will not work and basic things like |pipe| will not be easy to find.

You can edit the locale and keyboard layout of the system you are accessing so the mapping matches your Mac keyboard layout.

The ideal configuration should be like this:

  System Locale: LANG=en_GB.UTF-8
                 LANGUAGE=en_GB:en
     VC Keymap : n/a
     X11 Layout: gb
      X11 Model: macintosh
    X11 Variant: mac
    X11 Options: lv3:alt_switch

Ubuntu 18.04 / Ubuntu 20.04 / Debian 9 / Debian 10

Edit the following file:

/etc/default/keyboard

With these entries:

XKBMODEL="macintosh"
XKBLAYOUT="gb"
XKBVARIANT="mac"
XKBOPTIONS="lv3:alt_switch"

The XKBOPTIONS I have here are for Synergy to keep the Control and Alt keys on the Mac working the same on the Linux systems. You might not need or want it. Just remove it from the commands if that is the case.

You can also do a text GUI configuration of the keyboard with:

# dpkg-reconfigure keyboard-configuration

If your environment isn’t in English the menus won’t be either. You can force the language output of the application launched to be in the default one. That would be English in most cases. The same command as above but forcing the output to be in English:

# LC_ALL=C dpkg-reconfigure keyboard-configuration

An internet search of LC_ALL will show you more languages and options if needed.

CentOS 6

I have only been able to change the keyboard to a British layout, the Mac layout doesn’t seem to work.

Edit the following file:

/etc/sysconfig/i18n

with the following:

LANG="en_GB.UTF-8"
SYSFONT="latarcyrheb-sun16"
SUPPORTED="en_GB.UTF-8:en_GB:en"

Or type the following command:

# loadkeys uk

You might need to restart if editing i18n, but the change should be automatic with loadkeys.

CentOS 7

Edit the following file:

/etc/locale.conf

with the following:

LANG="en_GB.UTF-8"

Or type the following command:

# localectl set-locale LANG=en_GB.UTF-8

Set the keymap:

# localectl set-x11-keymap gb macintosh mac lv3:alt_switch

In CentOS 7 it isn’t necessary to reboot, the above command automatically loads the key mappings.

CentOS 8

The same commands used for CentOS 7 fail. I suspect that there is a file or folder with the keyboard mappings that has been moved. It might be a bug or a deprecated feature.

Just in case I opened a bug report with CentOS.

Regardless, the following will set the locale and the keyboard mappings correctly:

# localectl set-locale LANG=en_GB.UTF-8
# localectl set-keymap gb-mac

There is no need to reboot.




Linux: Adding a GUI to headless/server installs

Server and minimal installs are normally headless and have no graphical interface.

If needed you can add a GUI manually. The process is slightly different depending on the distro.

RedHat / CentOS 7.x

# yum update
# yum groupinstall "Server with GUI"

RedHat / CentOS 8.x

# dnf update
# dnf groupinstall workstation

Ubuntu 18.04.x LTS

# apt update

[Install minimum GNOME desktop]
# apt install --no-install-recommends ubuntu-desktop

[Install full desktop with associated applications]
(Long process and too many extras installed)

# apt install ubuntu-desktop

[There are other alternative desktops and installations possible:]

[Generic Gnome desktop]
# apt install vanilla-gnome-desktop

[Mate]
# apt install ubuntu-mate-desktop

[Xfce]
# apt install xubuntu-desktop

[KDE]
# apt install kubuntu-desktop

[LightDM]
# apt install --no-install-recommends lightdm

Debian 9.x

# apt update
# apt install gnome-core

Debian 10.x

# apt update
# apt install gnome-core

All the above distros use systemd as their init system and you set the default run level with the same set of commands.

[Enable run level 5 by default]
systemctl  set-default graphical.target

[Enable run level 3 by default]
systemctl  set-default multi-user.target

Despite systemd you can still use init to start the graphical interface without having to reboot.

# init 5



Ubuntu: Change default language/dictionary in Firefox

If you install Firefox via repositories it might not install with your preferred language/settings. If your distro is in English it will default to American English as the main language and other English variations as additional spelling dictionaries.

You can change this from the CLI. The below examples will leave British English as the default buy it can be easily be adapted to your needs.

Be warned that the spellchecker is shared with other applications like LibreOffice.

Check which spellchecker is installed on your system. Older versions used myspell and current ones use hunspell.

$ apt list --installed | grep myspell
$ apt list --installed | grep hunspell

Older versions

# apt remove myspell-en-au myspell-en-us myspell-en-za myspell-en-ca

# apt install myspell-en-gb

Current versions

# apt remove hunspel-en-au hunspell-en-us hunspell-en-za hunspell-en-ca

# apt install hunspell-en-gb



Ubuntu: Installing/fixing TP-Link AC1200 (T4UH 1.0) drivers in Ubuntu

[Updated instructions for Ubuntu 20.04 here]

I have had this USB wireless adapter working fine on Ubuntu 18.04 LTS for a while. A system update stopped it from working.

Re-installing the OS provided drivers (Software & Updates / Additional Drivers) made no difference. I tested the adapter in other operating systems and it worked fine.

It seems that from kernel version 4.15 onwards the drivers provided with Ubuntu no longer work, but the GUI shows as if the driver is correctly installed, it can see wireless networks and it even tries to connect to them. It will invariably fail to connect to any of them.

Others have encountered and solved this issue before me:

https://www.learningpenguin.net/2018/01/30/install-realtek-rtl8812au-wifi-driver-linux/

https://github.com/gnab/rtl8812au

Find below the steps to troubleshoot similar issues and a summary of the steps to install the correct driver as per the above links.

Check the hardware

Unplug and re-plug the adapter and check the output of:

dmesg

The following commands will also help in showing if the adapter is correctly detected.

$ lsusb
Bus 004 Device 002: ID 1058:25e1 Western Digital Technologies, Inc. 
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 2357:0103  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The Bus 003 Device 002: ID 2357:0103 entry is the one that is the USB wifi adapter on my system even if it isn’t showing an identifier. You can remove the adapter and issue the command again and compare results to help you identify it.

For non-USB adapters you can use:

$ lspci

More detailed information about the device can be obtained with the lshw command.

$ lshw -C network
WARNING: you should run this program as super-user.
  *-network                 
       description: Ethernet interface
       product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
       vendor: Realtek Semiconductor Co., Ltd.
       [output truncated]
    *-network:2
       description: Wireless interface
       physical id: 4
       bus info: usb@3:1
       logical name: enx18d6c70fbacc
       serial: 18:d6:c7:a1:22:ab
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=rtl8812au ip=192.168.x.2 multicast=yes wireless=IEEE 802.11AC
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.

This last command is really useful because it will give really important information about what driver to use.

In this case the chipset and driver to use is identified in this string driver=rtl8812au.

Check the drivers

Now check that the driver is loaded, you need to look for a string that is similar to the driver string above.

$ lsmod | grep 8812
8812au                999424  0

If the module isn’t loaded you can use modprobe modulename to load it.

# modprobe 8812au

Installing updated drivers

But in my case all of the above was correct but the card would still not work. This was caused by an incompatibility of the the drivers provided with Ubuntu and the updated kernel.

I should have checked the system logs earlier as I believe there was an entry there indicating a problem.

Uninstall the system provided drivers from the GUI .

  • Go to Software & Updates
  • Select Additional Drivers
  • Find the entry for the wifi adapter (rtl8812-au) and select Do not use the device

You can do the same from the CLI:

[find the one you have installed]

# apt list rtl8812au*

[and uninstall]

# apt purge rtl8812au-dkms

Get the updated drivers from github:

$ git clone https://github.com/gnab/rtl8812au.git

Install the drivers with one of these two commands. They will work as long as you are pointing to the directory generated by the previous git command.

At the time of writing the latest release of the drivers are 4.2.3. Your output might vary.

[this command]

# dkms add ./rtl8812au/

[or this command]

# dkms add -m 8812au -v 4.2.3

Build and install the drivers:

# dkms build -m 8812au -v 4.2.3
# dkms install -m 8812au -v 4.2.3

Check that they were installed correctly:

# dkms status

And finally add the module to autoload during boot.

# echo 8812au | tee /etc/modules

You should now be able to join your wireless network without problems. As the driver is installed via dkms if there is a kernel update it will automatically update and recompile the driver for the new release.

If you ever need to uninstall the driver you can do it with:

# dkms remove -m 8812au -v 4.2.3 --all

You will also need to edit out the entry in /etc/modules.

One additional thing that caught me off was that if the adapter is connected to a USB 3.1 port it won’t work. USB 3.0 ports are fine.




Ubuntu: Fixing the “error: no video mode activated” message on boot

During boot of your system and just after the BIOS messages Ubuntu might display a black screen with an error: no video mode activated message. The system boots normally but it is annoying.

GRUB by default hides the boot menu and this message can show up if there is no video mode set. It seems to be a known bug when the hidden option is active. I think you can just dismiss is it with ESC or ignore it as it has no adverse effect.

If you find it annoying you can get rid of it with the following steps.

Activate the menu option in GRUB.

vim /etc/default/grub

Make the following changes. Adjust your timeout to the number of seconds you want the boot menu to be displayed. Values below 5 seconds are difficult to catch.

#GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10

Update the changes:

$ sudo update-grub

Reboot and check that the changes have been applied correctly.




Ubuntu: Fixing network interfaces not showing in GUI on Ubuntu Server

Ubuntu Server and Ubuntu Desktop use different network managers. Ubuntu Server uses networkd which doesn’t have a GUI component. So after adding a desktop to Ubuntu Server you won’t be able to see or change the configuration via the GUI by default.

Ubuntu Desktop Ubuntu Server
Configuration tool netplan netplan
CLI manager nmcli networkd
GUI manager NetworkManager n/a

For you to be able to see the network settings on the GUI you need to switch from networkd to NetworkManager.

Install NetworkManager:

apt install network-manager network-manager-gnome network-manager-openvpn network-manager-openconnect network-manager-openvpn-gnome

Check which systemd network daemons are active:

systemctl list-unit-files | grep -i network

Disable/stop networkd services:

systemctl disable systemd-networkd.service
systemctl disable networkd-dispatcher.service
systemctl stop systemd-networkd
systemctl stop systemd-networkd.socket
systemctl stop systemd-networkd.service
systemctl stop network-dispatcher.service

Remember that nmcli can be used for CLI NetworkManager control also.

Network interfaces are listed in yaml files in /etc/netplan/

Edit /etc/netplan/50-cloud-init.yaml and edit the line or add a line after the version: 2 entry to be renderer: Networkmanager.

network:
  ethernets:
    eno1:
      dhcp4: true
  version: 2
  renderer: NetworkManager

Check the changes and apply them:

netplan generate
netplan try / netplan apply