Ubuntu Kernel Clean-Up

Ubuntu is great at “set it and forget it” maintenance. Patches come down, and generally life is good.

However, the frequency of kernel updates can fill-up a modest /boot partition.

Recently faced with an inability to install an updated kernel due to a limited /boot partition, I had to do some housekeeping. I put together two quick scripts to help with this.
 

showInactiveKernels
Of the kernels installed on the system, which are not the one currently running?

#!/usr/bin/env bash

echo "Current Kernel: $(uname -r)"
old=$(dpkg -l "linux-image*" | grep '^[i]' | awk '{print $2}' | egrep -v "linux-image-$(uname -r)|linux-image-generic")
if [ "" == "$old" ] ; then
  echo "No inactive kernels found"
  exit
fi

for o in $old; do
  echo "  inactive kernel: $o"
done

 

removeInactiveKernels
Elaborating on the last script, prompting to remove them as you go

#!/usr/bin/env bash

old=$(dpkg -l "linux-image*" | grep '^[i]' | awk '{print $2}' | egrep -v "linux-image-$(uname -r)|linux-image-generic")
if [ "" == "$old" ] ; then
  echo "No inactive kernels found"
  exit
fi

for o in $old; do
  response='no'
  echo ""
  echo "Current Kernel: $(uname -r)"
  read -p "Do you wish to remove $o? ([no]|yes) " response
  if [ "$response" == "yes" ] ; then
    echo "  ... removing $o"
    apt-get -y remove "$o"
  fi
done

 

Using these provided a quick way to identify which kernels I could consider for removal/uninstallation, allowing me to clean-up /boot in no time.

Raspberry Pi Game Console

I recently received a Raspberry Pi (model B) and decided to kick the tires on it.  Having grown-up with Nintendo, I wanted to configure it as a nostalgic game console.
 

Before I started configuring the OS, I wanted to get a couple game controllers (so that I would not be using a keyboard/mouse to play the games).  I chose to use USB controllers (SNES Retro USB by Tomee) and due to the limited power of the Pi itself, also picked-up a powered USB hub.
 

With all the parts (controllers in powered hub), I started with some basic Raspberry Pi setup:

  • Adjust Memory Split (give GPU 128 MB): sudo raspi-config
  • Update: sudo apt-get update
  • Install Git: sudo apt-get install -y git
  • Install Dialog: sudo apt-get install -y dialog

 

I then proceeded with installing RetroPie:

  • Change to home directory: cd
  • Download RetroPie: git clone git://github.com/petrockblog/RetroPie-Setup.git
  • Change to setup directory: cd RetroPie-Setup
  • Run setup (as root): sudo ./retropie_setup.sh
  • … waited several hours for RetroPie setup to finish …

 

With RetroPie setup complete, I launched Emulation Station (emulationstation on command line).  The first time it runs it will probably detect that you do not have an input configuration file (for controllers) and walk you through the setup.  Basically, follow the on-screen instructions.  If it does not quite go as planned, you can always exit Emulation Station, move ~/.emulationstation/es_input.cfg out of the way, and re-launch it to do it again.  If you are using different controllers, your configuration file may vary; however, here is mine for the controllers I am using:

JOYNAME 2Axes 11Keys Game Pad
BUTTON 1 5
BUTTON 2 6
BUTTON 4 9
BUTTON 5 10
BUTTON 8 8
BUTTON 9 7
AXISPOS 0 4
AXISPOS 1 2
AXISNEG 0 3

 

Go ahead and exit Emulation Station.  Now that the controller is setup within Emulation Station, we have to configure the controller using retroarch-joyconfig.  We want to backup the existing file, and then run the configuration tool, redirecting it’s output to append to the configuration file:

  • Backup Existing: cp ~/RetroPie/configs/all/retroarch.cfg ~/RetroPie/configs/all/retroarch.cfg.orig
  • Run Config, Redirecting Output To Append: ./retroarch-joyconfig >> ~/RetroPie/configs/all/retroarch.cfg

This again will differ depending on what controller you are using, but here is what mine looks like:

##################################################
# Tomee SNES USB Controller
##################################################
# HotKey exit if SELECT + START
input_enable_hotkey_btn = "8"
input_exit_emulator_btn = "9"
# Player 1
input_player1_joypad_index = "0"
input_player1_a_btn = "1"
input_player1_b_btn = "2"
input_player1_x_btn = "0"
input_player1_y_btn = "3"
input_player1_l_btn = "4"
input_player1_r_btn = "5"
input_player1_start_btn = "9"
input_player1_select_btn = "8"
input_player1_left_axis = "-0"
input_player1_up_axis = "-1"
input_player1_right_axis = "+0"
input_player1_down_axis = "+1"
# Player 2
input_player2_joypad_index = "1"
input_player2_a_btn = "1"
input_player2_b_btn = "2"
input_player2_x_btn = "0"
input_player2_y_btn = "3"
input_player2_l_btn = "4"
input_player2_r_btn = "5"
input_player2_start_btn = "9"
input_player2_select_btn = "8"
input_player2_left_axis = "-0"
input_player2_up_axis = "-1"
input_player2_right_axis = "+0"
input_player2_down_axis = "+1"
##################################################

You can see I added-in the HotKey configuration so that if I press both SELECT and START at the same time, it will exit the emulator, returning me to Emulation Station (this is a handy feature for getting back to your menu of games).
 

I found that my default sound configuration on the Pi was not producing any output.  I narrowed this in to the channel being muted and at 0% volume.  So, I fixed that (I’m using the audio output on the model B, and RCA video out … if you’re using HDMI, your configuration may vary):

  • Check Current Sound Mixer Settings: amixer
  • Unmute: amixer set PCM unmute
  • Turn Up Volume: amixer set PCM 100%

 

Another glitch I ran into was getting the Nintendo emulator to run.  When I attempted to run it, it displayed an error on the screen and returned to Emulation Station.  I was able to look through the logs to find the error and it was complaining about a missing library.  It appeared that the file name (or the reference to it) changed at some point, causing the mismatch.  I resolved it by soft-linking the file name it was looking for to the installed file name on disk:

  • Change directory to the Nintendo emulator: cd ~/RetroPie/emulatorcores/fceu-next/fceumm-code/
  • Create the soft-link: ln -s fceumm_libretro.so libretro.so

 

At this point, the Nintendo, Super Nintendo, and Turbo Grafx 16 emulators were all working.
 

For reference, you will want to copy your ROMs to ~/RetroPie/roms/ where the subdirectories are:

  • atari2600 – Atari 2600 (*.a26, *.bin, *.gz, *.rom, *.zip)
  • doom – Doom (*.wad)
  • duke32 – Duke Nukem 3d (*.grp)
  • gamegear – Sega Game Gear (*.gg)
  • gb – Game Boy (*.gb)
  • gba – Game Boy Advance (*.gba)
  • gbc – Game Boy Color (*.gbc)
  • mame – MAME (*.zip)
  • mastersystem – Sega Master System II (*.sms)
  • megadrive – Sega Mega Drive / Genesis (*.md, *.smd)
  • neogeo – NeoGeo (*.zip)
  • nes – Nintendo (*.nes)
  • pcengine – Turbo Grafx 16 (*.pce)
  • psx – Sony Playstation 1 (*.7z, *.img, *.pbp)
  • scummvm – ScummVM (*.exe)
  • snes – Super Nintendo (*.fig, *.smc, *.swc)
  • zxspectrum – ZX Spectrum (*.z80)