Como apagar um kernel no Ubuntu

Publicado por Fernando Mazureki do Bem em 14/10/2009

[ Hits: 20.224 ]

 


Como apagar um kernel no Ubuntu



Com o passar do tempo vão surgindo novas atualizações de kernel, isso vai enchendo o HD de imagens, deixando os kernels antigos ociosos no computador, acumulando espaço. Aqui vou deixar uma maneira bem rápida de como remover estes kernels que não são mais usados por você.

O primeiro passo é listar todas as versões de kernel instaladas. Para isso devemos utilizar o comando:

dpkg --get-selections | grep linux-image

Vai aparecer uma lista com todas as imagens de kernel instaladas, então é só identificar aquelas que você quer apagar. Depois use o comando:

sudo aptitude purge nome_do_pacote

Este comando serve para desinstalar o pacote do HD. Mas se preferir desinstalar em modo gráfico é só abrir o gerenciador de pacotes Synaptic e digitar no campo "Busca rápida" o nome do kernel que quer desinstalar.

Se preferir não desinstalar, mas só retirar da inicialização do Grub (caso tenha boot com Windows e/ou outros), edite o menu.lst e remova as imagens que você quer que não apareçam no boot. Utilize este comando para abrir o menu.lst do grub:

sudo gedit /boot/grub/menu.lst

Exemplo com base no meu menu.lst após digitar o comando:

sudo gedit /boot/grub/menu.lst:

# menu.lst - See: grub(8), info grub, update-grub(8)
#            grub-install(8), grub-floppy(8),
#            grub-md5-crypt, /usr/share/doc/grub
#            and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use 'savedefault' or your
# array will desync and will not let you boot your system.
default      0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout      5

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line)  and entries protected by the
# command 'lock'
# e.g. password topsecret
#      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title      Windows 95/98/NT/2000
# root      (hd0,0)
# makeactive
# chainloader   +1
#
# title      Linux
# root      (hd0,1)
# kernel   /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
##      kopt_2_6_8=root=/dev/hdc1 ro
##      kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro

## default grub root device
## e.g. groot=(hd0,0)
# groot=a92fdbc4-b35e-426f-b283-798a3674bd53

## should update-grub create alternative automagic boot options
## e.g. alternative=true
##      alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
##      lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
##      lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
##      howmany=7
# howmany=all

## specify if running in Xen domU or have grub detect automatically
## update-grub will ignore non-xen kernels when running in domU and vice versa
## e.g. indomU=detect
##      indomU=true
##      indomU=false
# indomU=detect

## should update-grub create memtest86 boot option
## e.g. memtest86=true
##      memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## should update-grub add savedefault to the default options
## can be true or false
# savedefault=false

## ## End Default Options ##


title      Ubuntu 9.04, kernel 2.6.28-15-generic
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/vmlinuz-2.6.28-15-generic root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro quiet splash
initrd      /boot/initrd.img-2.6.28-15-generic
quiet

title      Ubuntu 9.04, kernel 2.6.28-15-generic (recovery mode)
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/vmlinuz-2.6.28-15-generic root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro  single
initrd      /boot/initrd.img-2.6.28-15-generic

title      Ubuntu 9.04, kernel 2.6.28-14-generic
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/vmlinuz-2.6.28-14-generic root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro quiet splash
initrd      /boot/initrd.img-2.6.28-14-generic
quiet

title      Ubuntu 9.04, kernel 2.6.28-14-generic (recovery mode)
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/vmlinuz-2.6.28-14-generic root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro  single
initrd      /boot/initrd.img-2.6.28-14-generic

title      Ubuntu 9.04, memtest86+
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title      Other operating systems:
root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title      Windows XP
rootnoverify   (hd0,0)
savedefault
makeactive
chainloader   +1

Reparem na linha:

## ## End Default Options ##

As imagens são listadas após ela.

Neste caso eu só quero apagar duas imagens do menu.lst, então vou apagar após a opção:

## ## End Default Options ##

toda a linha, title, uuid, kernel e initrd, ficando assim:

## ## End Default Options ##

title      Ubuntu 9.04, kernel 2.6.28-15-generic
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/vmlinuz-2.6.28-15-generic root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro quiet splash
initrd      /boot/initrd.img-2.6.28-15-generic
quiet

title      Ubuntu 9.04, kernel 2.6.28-15-generic (recovery mode)
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/vmlinuz-2.6.28-15-generic root=UUID=a92fdbc4-b35e-426f-b283-798a3674bd53 ro  single
initrd      /boot/initrd.img-2.6.28-15-generic


title      Ubuntu 9.04, memtest86+
uuid      a92fdbc4-b35e-426f-b283-798a3674bd53
kernel      /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title      Other operating systems:
root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title      Windows XP
rootnoverify   (hd0,0)
savedefault
makeactive
chainloader   +1

Se quiser alterar o tempo de espera para entrar no Linux, vá para a opção timeout. Ex.:

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).

timeout      5

Altere o timeout para quantos segundos quiser, no meu caso deixei com 5, mas você escolhe no seu.

Se você quer alterar a ordem do boot, vá para a opção default. Ex.:

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use 'savedefault' or your
# array will desync and will not let you boot your system.

default      6

Observe o número 6, isso quer disser que a title número 7 será a iniciada por padrão, no meu caso seria o Windows XP, antes de ter retirado as outras title.

Por que a 7 e não 6?
Porque ele começa a contar a partir do 0, e o 0 é o número inicial da sua contagem, que para nós seria o 1. Se você deixar o número 0 (zero) ele vai iniciar por padrão a title mais recente instalada, ou seja, o kernel mais recente.

Se você quer alterar o nome que aparece na hora do boot, é só alterar o nome que aparece depois do title. No meu caso fiz com a title do Windows, que era:

# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title      Microsoft Windows XP Profissional
rootnoverify   (hd0,0)
savedefault
makeactive
chainloader   +1

E deixei somente assim:

# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title      Windows XP
rootnoverify   (hd0,0)
savedefault
makeactive
chainloader   +1

Espero ter ajudado!

Outras dicas deste autor
Nenhuma dica encontrada.
Leitura recomendada

Compilar kernel

7 cursos gratuitos - Python, JavaScript, Linux e Segurança

Criando terminal para acesso remoto no Linux

Criação de 1° super usuário no PostgreSQL

DL0002 - LPIC-1 - Prova 101 - Tópico 101: Arquitetura de Sistema

  

Comentários
[1] Comentário enviado por jrlaporta em 02/03/2010 - 13:37h

CARA VALEW MESMO, SOU INICIANTE NO LINUX E A CADA DIA QUE APRENDO ALGUMA COISA FICO FASCINADO E CADA VEZ MAIS CERTO DE ESTOU NUMA NOVA ERA MESMO. E QUANTO SUA INFORMAÇÃO ME AJUDOU BASTANTE POIS TODA VEZ Q IA INICIAR MEU PC APARECIA DOIS KERNEL E NÃO SABIA COMO RETIRAR OBRIGADO E VIVA O LINUX!!!!

[2] Comentário enviado por shamyr em 19/06/2010 - 11:13h

oi td bem, e o seguinte eu tinha uma versão do ubunto anterior e atualizei um amigo me passou esses comandos para tirar a versão anterior do boot, so que agora não estou conseguindo inicializar nenhuma versão do linux alguém pode me ajudar, estou querendo evitar instalar de novo, pois ja tinha instalado alguns softwares e drivers.



//obs: ubunto instalado dentro do windows.

A mensagem de erro e essa:

GNU GRUB version 1.97 beta4
[Minimal BASH- like comand completions. anywhere else TAB list possible device/file completions.]

sh:grub> _

[3] Comentário enviado por cordobel em 14/02/2011 - 17:57h

como faço para desinstalar a versão corrente do kernel e voltar a usar uma mais antiga?



Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts