Eu me deparo com esse tipo de problema o tempo todo. Eu corro um monte de caixas KODI (que eu criei) que tudo inicializa a partir de um servidor dedicado via PXE. Então, muitas vezes quando eu vou atualizar minhas caixas PXE através do chroot (ou outro), eu topo com problemas de atualização do kernel. Então, recentemente eu decidi criar um script que irá criar a porcaria que o depmod / apt-get está procurando para que você possa remover esses kernels corretamente.
Para executar o script, basta copiar e colar o código em um arquivo. No terminal, torne-o executável digitando:
$> chmod +x fixKernels.sh
Com o "fixKernels.sh" sendo o nome do script.
A partir daí, execute o script digitando:
$> sudo ./fixKernels.sh
E depois basta seguir as instruções.
#!/bin/bash
####################################################
#
# NAME: fixKernels.sh
#
#
# DESCRIPTION: This script was designed to create
# fake kernel entries in places depmod and apt-get
# would normally look for existing kernels. The purpose
# of this script is to trick depmod or apt-get into
# believing these kernels exist on your system so it
# can successfully remove them without causing errors
# and preventing YOU from installing other things.
#
####################################################
# Spinner! Shows a rotating line animation
spinner()
{
sleep 1
PROC=$1
BACKSPACE='0'
SPINNER='|/-\'
INDEX=0
while [ -d /proc/$PROC ]
do
echo -n -e "${SPINNER:$INDEX:1}"
sleep 0.2
(( INDEX = ($INDEX + 1) % 4 ))
echo -n -e "$BACKSPACE"
done
}
# Check for root
cp /etc/shadow /tmp/isroot 2>/dev/null
# IF ROOT
if [ ! -f /tmp/isroot ]; then
echo "You ain't root, baby!"
exit
else
# Remove temp file
rm /tmp/isroot
fi
# Make sure parameter is not empty
if [[ $1 != "" ]] && [[ 'echo $1 | grep -i "linux"' == "" ]]; then
# Needed echo! Great for displaying purposes
echo
# Determine if uname exists
if [[ ! -d /lib/modules/'uname -r' ]]; then
# Examine all the kernels found on the system
for x in 'ls -l /lib/modules | awk '{print $9}''
do
# Determine that all the pieces exist before we use them!
if [[ -f /boot/System.map-$x ]] && [[ -f /boot/vmlinuz-$x ]]; then
# Use whatever we've got!!
UNAME=$x
fi
done
# IF the pieces aren't found... Not much else we can do!!
if [[ $UNAME == "" ]]; then
# Error
echo "There's no kernel found on your system!! How are you reading this??"
# Exit the script
exit
fi
else # We've got what we need
UNAME='uname -r'
fi
# Make sure the kernel isn't copying on top of itself
if [[ $1 != $UNAME ]]; then
# Create a fake version of that kernel
echo "Creating Fake System Map..."
sudo cp /boot/System.map-$UNAME /boot/System.map-$1 -rfap &
# Create a short animation to show user it's working
spinner $!
# Create the vmlinuz... But it's fake
echo "Creating Fake Vmlinuz..."
sudo cp /boot/vmlinuz-$UNAME /boot/vmlinuz-$1 -rfap &
# Create a short animation
spinner $!
# Create the fake modules
echo "Creating Fake Kernel Modules..."
sudo cp /lib/modules/$UNAME /lib/modules/$1 -rfap &
# Create a short animation
spinner $!
else
# Warn user
echo "This kernel exists... Skipping!"
fi
else
echo "USAGE: ./'basename $0' <kernel version>"
echo "EXAMPLE: ./'basename $0' 4.4.0-31-generic"
fi