How to remove old Linux kernel entries from Grub menu

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Brahim Salem

How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

I have installed Linux Mint 13 in the place of Linux Mint 14 Cinnamon 64bit. Now I'm running a dual-boot of Mint 13 Mate + Mint 14 Mate but after installing the system I've noticed old Linux kernel entries in the grub menu. I've installed grub customizer and tried to remove them but it couldn't remove them all, and so I installed Ubuntu Tweak, but when I tick old kernel and start the janitor it says "Cool your system is cleam!" and we know now it is not. This is the output of:

Code: Select all

sudo update-grub

Code: Select all

mint@mint-Inspiron-N5040 ~ $ sudo update-grub
[sudo] password for mint: 
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-23-generic
Found initrd image: /boot/initrd.img-3.2.0-23-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Linux Mint 14 Nadia (14) on /dev/sda5
done
mint@mint-Inspiron-N5040 ~ $ 

and this is the output of :

Code: Select all

dpkg --list | grep linux-image

Code: Select all

mint@mint-Inspiron-N5040 ~ $ dpkg --list | grep linux-image
ii  linux-image-3.2.0-23-generic           3.2.0-23.36                             Linux kernel image for version 3.2.0 on 64 bit x86 SMP
ii  linux-image-generic                    3.2.0.23.25                             Generic Linux kernel image
mint@mint-Inspiron-N5040 ~ $ 
this is my /boot/grub/grub.cfg:

Code: Select all

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}

function load_video {
  insmod vbe
  insmod vga
  insmod video_bochs
  insmod video_cirrus
}

insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set=root 985ee9f7-b28d-4275-a38e-aee80160d370
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  insmod part_msdos
  insmod ext2
  set root='(hd0,msdos7)'
  search --no-floppy --fs-uuid --set=root 985ee9f7-b28d-4275-a38e-aee80160d370
  set locale_dir=($root)/boot/grub/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ]; then
  set timeout=-1
else
  set timeout=10
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/06_mint_theme ###
set menu_color_normal=white/black
set menu_color_highlight=white/light-gray
### END /etc/grub.d/06_mint_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
	set gfxpayload="$1"
	if [ "$1" = "keep" ]; then
		set vt_handoff=vt.handoff=7
	else
		set vt_handoff=
	fi
}
if [ ${recordfail} != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
if [ "$linux_gfx_mode" != "text" ]; then load_video; fi
menuentry 'Linux Mint 13 MATE 64-bit, 3.2.0-23-generic (/dev/sda7)' --class linuxmint --class gnu-linux --class gnu --class os {
	recordfail
	gfxmode $linux_gfx_mode
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos7)'
	search --no-floppy --fs-uuid --set=root 985ee9f7-b28d-4275-a38e-aee80160d370
	linux	/boot/vmlinuz-3.2.0-23-generic root=UUID=985ee9f7-b28d-4275-a38e-aee80160d370 ro   quiet splash $vt_handoff
	initrd	/boot/initrd.img-3.2.0-23-generic
}
menuentry 'Linux Mint 13 MATE 64-bit, 3.2.0-23-generic (/dev/sda7) -- recovery mode' --class linuxmint --class gnu-linux --class gnu --class os {
	recordfail
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos7)'
	search --no-floppy --fs-uuid --set=root 985ee9f7-b28d-4275-a38e-aee80160d370
	echo	'Loading Linux 3.2.0-23-generic ...'
	linux	/boot/vmlinuz-3.2.0-23-generic root=UUID=985ee9f7-b28d-4275-a38e-aee80160d370 ro recovery nomodeset 
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-3.2.0-23-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/10_lupin ###
### END /etc/grub.d/10_lupin ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+_proxy ###
### END /etc/grub.d/20_memtest86+_proxy ###

### BEGIN /etc/grub.d/30_os-prober_proxy ###
menuentry "Linux Mint 14 Cinnamon 64-bit, 3.5.0-17-generic (/dev/sda7) (on /dev/sda7)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-3.5.0-17-generic--336e1d12-d432-4d67-a35a-aeb0b5d06835 (on /dev/sda5)" --class gnu-linux --class gnu --class os {
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos5)'
	search --no-floppy --fs-uuid --set=root b69a7ab7-593e-476c-bfdd-f53ba3d17d08
	linux /boot/vmlinuz-3.5.0-17-generic root=UUID=336e1d12-d432-4d67-a35a-aeb0b5d06835 ro quiet splash $vt_handoff
	initrd /boot/initrd.img-3.5.0-17-generic
}
menuentry "Linux Mint 14 Nadia (14) (on /dev/sda7)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-3.5.0-17-generic--336e1d12-d432-4d67-a35a-aeb0b5d06835 (on /dev/sda5)" --class gnu-linux --class gnu --class os {
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos5)'
	search --no-floppy --fs-uuid --set=root b69a7ab7-593e-476c-bfdd-f53ba3d17d08
	linux /boot/vmlinuz-3.5.0-17-generic root=UUID=b69a7ab7-593e-476c-bfdd-f53ba3d17d08 ro quiet splash $vt_handoff
	initrd /boot/initrd.img-3.5.0-17-generic
}
menuentry "Linux Mint 14 MATE 64-bit, 3.5.0-17-generic (/dev/sda5) (on /dev/sda5)" --class gnu-linux --class gnu --class os {
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos5)'
	search --no-floppy --fs-uuid --set=root b69a7ab7-593e-476c-bfdd-f53ba3d17d08
	linux /boot/vmlinuz-3.5.0-17-generic root=UUID=b69a7ab7-593e-476c-bfdd-f53ba3d17d08 ro quiet splash $vt_handoff
	initrd /boot/initrd.img-3.5.0-17-generic
}
menuentry "Linux Mint 14 MATE 64-bit, 3.5.0-17-generic (/dev/sda5) -- recovery mode (on /dev/sda5)" --class gnu-linux --class gnu --class os {
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos5)'
	search --no-floppy --fs-uuid --set=root b69a7ab7-593e-476c-bfdd-f53ba3d17d08
	linux /boot/vmlinuz-3.5.0-17-generic root=UUID=b69a7ab7-593e-476c-bfdd-f53ba3d17d08 ro recovery nomodeset
	initrd /boot/initrd.img-3.5.0-17-generic
}
### END /etc/grub.d/30_os-prober_proxy ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
and the section I want to remove is :

Code: Select all

menuentry "Linux Mint 14 Cinnamon 64-bit, 3.5.0-17-generic (/dev/sda7) (on /dev/sda7)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-3.5.0-17-generic--336e1d12-d432-4d67-a35a-aeb0b5d06835 (on /dev/sda5)" --class gnu-linux --class gnu --class os {
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos5)'
	search --no-floppy --fs-uuid --set=root b69a7ab7-593e-476c-bfdd-f53ba3d17d08
	linux /boot/vmlinuz-3.5.0-17-generic root=UUID=336e1d12-d432-4d67-a35a-aeb0b5d06835 ro quiet splash $vt_handoff
	initrd /boot/initrd.img-3.5.0-17-generic
}
menuentry "Linux Mint 14 Nadia (14) (on /dev/sda7)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-3.5.0-17-generic--336e1d12-d432-4d67-a35a-aeb0b5d06835 (on /dev/sda5)" --class gnu-linux --class gnu --class os {
	insmod part_msdos
	insmod ext2
	set root='(hd0,msdos5)'
	search --no-floppy --fs-uuid --set=root b69a7ab7-593e-476c-bfdd-f53ba3d17d08
	linux /boot/vmlinuz-3.5.0-17-generic root=UUID=b69a7ab7-593e-476c-bfdd-f53ba3d17d08 ro quiet splash $vt_handoff
	initrd /boot/initrd.img-3.5.0-17-generic
}
and:

Code: Select all

uname -r
gives:

Code: Select all

mint@mint-Inspiron-N5040 ~ $ uname -r
3.2.0-23-generic

Heeelp! I've spent a long time pimping the new OS and I don't want to redo that again if I have to reinstall it :cry: :cry: :cry:
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
wayne128

Re: How to remove old Linux kernel entries from Grub menu

Post by wayne128 »

Can you boot computer with Mint DVD, run Live mode, then do these commands and post terminal output?

1. sudo os-prober

2. sudo fdisk -l
d00med

Re: How to remove old Linux kernel entries from Grub menu

Post by d00med »

Remove unused kernels

Code: Select all

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
Just list them

Code: Select all

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

d00med wrote:Remove unused kernels

Code: Select all

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
Just list them

Code: Select all

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
I did that but Istill have these 2 lines on the Grub menu:

Code: Select all

Linux Mint 14 Cinnamon 64-bit, 3.5.0-17-generic (/dev/sda7) (on /dev/sda7)' --class gnu-linux --class gnu --class os 
Linux Mint 14 Nadia (14) (on /dev/sda7)' --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-
:(
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

wayne128 wrote:Can you boot computer with Mint DVD, run Live mode, then do these commands and post terminal output?

1. sudo os-prober

2. sudo fdisk -l
this is the output when I run these commands from Linux Mint 13 Mate intalled to HDD because I don't have a Mint DVD :D :

Code: Select all

mint@mint-Inspiron-N5040 ~ $ sudo os-prober
[sudo] password for mint: 
/dev/sda5:Linux Mint 14 Nadia (14):LinuxMint:linux
mint@mint-Inspiron-N5040 ~ $ sudo fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1baf0215

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2046   390572031   195284993    5  Extended
/dev/sda4       390572280   976768064   293097892+   7  HPFS/NTFS/exFAT
/dev/sda5            2048   186523647    93260800   83  Linux
/dev/sda6       186525696   195313663     4393984   82  Linux swap / Solaris
/dev/sda7       195315712   381837311    93260800   83  Linux
/dev/sda8       381839360   390572031     4366336   82  Linux swap / Solaris
mint@mint-Inspiron-N5040 ~ $ 
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

These are the installed kernels in the Synaptic Package Manager:
Image

and these are thentries in Grub Customizer:
Image
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

heeeeeeeeeeeeeeeeelp :shock:
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

I got rid of them by removing these entries in grub.cfg file present in /boot/grub/ without running

Code: Select all

update-grub
because this command reconfigures grub.cfg file and includes again old kernel entries :D

Will this cause future boot problems?? :roll: :roll:
wayne128

Re: How to remove old Linux kernel entries from Grub menu

Post by wayne128 »

Do not delete things in grub.cfg.
When next grub update, kernel update etc, it will return and you will be back to square one.


Try this way

1. Boot and run from Mint from /dev/sda5
2. then use synaptic, search linux-image-3.2.0 , identify all those you wish to uninstall, then check them and uninstall them.
The one you are running can be seen by uname -r on terminal, you cannot remove this one.. :mrgreen:

3. when unwanted kernels are removed, do a update-grub
4. then do a grub-install /dev/sda, so that this /dev/sda5 take over MBR

5. reboot, check that /dev/sda have only left the kernel you want to keep.

6. reboot, select /dev/sda7, then, use the same method as in step2, use synaptic, search those kernel you do not want to keep, uninstall them.
When unwanted kernels have been uninstalled, do a update-grub, it should clean up grub.cfg file
then, do a grub-install /dev/sda so that /dev/sda7 now take over MBR

7. reboot, choose /dev/sda7 and confirm that you now have those kernel lines you wish to keep.

The above seems lenghty but it is quite simple to execute. It contains duplicate works too, but at the end, I think it should clear those that are unwanted for you.
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

Tries that but didn't work!! nothing is showing in synaptic besides my current kernel :roll:
dRaiser

Re: How to remove old Linux kernel entries from Grub menu

Post by dRaiser »

You could use Ubuntu Tweak (works with Linux Mint w/o any problems). It's GUI application with "cleaning" option which deletes old kernels.

http://ubuntu-tweak.com/

Edit: Sorry, missed info in first post :oops:
Last edited by dRaiser on Sat Mar 23, 2013 10:45 am, edited 1 time in total.
Brahim Salem

Re: How to remove old Linux kernel entries from Grub menu

Post by Brahim Salem »

Also tried that. didn't work for me :(
Locked

Return to “Installation & Boot”