Ubuntu: Questions and Answers (2014)
Skip to questions, Wiki by user jrg
What Questions Should Have This Tag?:
· Questions on how to edit, repair, or troubleshoot GRUB2
· Questions on how GRUB2 works
Some Basic Definitions:
Bootloader - This is a program which loads the Operating System(OS) or other software, after POST (Power On Self Test).
Boot Record - Contains information on which OS(s)/program(s) to "boot", and information about where these are located.
Brief Introduction to the Subject:
From the Ubuntu Wiki page for GRUB2:
GRUB 2's major improvements over the original GRUB include:
· Scripting support including conditional statements and functions
· Dynamic module loading
· Rescue mode
· Custom Menus
· Graphical boot menu support and improved splash capability
· Boot LiveCD ISO images directly from hard drive
· New configuration file structure
· Non-x86 platform support (such as PowerPC)
· Universal support for UUIDs (not just Ubuntu)
Important Links for Learning More:
· Ubuntu Wiki Page for GRUB2
· How do I change the GRUB boot order?
· How do I set the grub timeout and the grub default boot entry?
Q: How do I remove or hide old kernel versions to clean up the boot menu?
Every time I install a new Linux kernel, it gets left in the grub_config, making the boot menu longer each time.
I know I can manually search through the installed packages and remove them.
Does Ubuntu provide any easier way to clean them up or keep them from showing in the boot list?
Answer by fossfreedom
11.10 and newer versions of Ubuntu
GRUB2 and its display of all kernels
The latest versions of Grub2 installed in Ubuntu automatically display the latest kernel and hides the older kernels that you may have installed.
If you do not see your grub - then remember to press Shift whilst booting.
As you can see, only the latest kernel is displayed.
If you select the option shown (press Enter) then all the old kernels become visible and available to boot from.
How to permanently delete ALL older kernels using the shell
This will remove ALL versions but the current:
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
Or you can run this command as a cron job, if you want this done automatically without confirmation:
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
However this is not wise, as you should ALWAYS have an old kernel or two to fall back to (just in case the new one doesn't work with your system). At the very least, if you've just upgraded the kernel, reboot before deleting the older versions. Read on for a safer, more manual way.
How to permanently delete older kernels
First boot with the latest available kernel.
There are a number of ways to delete old kernels. Personally, I wouldn't touch Computer Janitor since this is acknowledged to break your computer with its suggestions.
An alternative is Synaptic (sudo apt-get install synaptic)
search for linux-image, right-click a kernel and choose complete removal and finally click the Apply button to delete the kernel.
Repeat the search but this time for linux-header - you can delete the associated headers for the kernel image chosen previously.
Synaptic though will not attempt to verify what you are trying to remove... you could inadvertently delete your newest kernel - or even delete all of your kernels via this tool leaving you with an unbootable Ubuntu!.
Remember to check which kernel you are using type:
The result would be similar to:
Remember the result and the number - make sure you don't delete the corresponding image or header.
IMHO, the best GUI tool is Ubuntu-Tweak
It is not available from the standard repositories. To install you need to use the author's PPA:
sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak
Choose the options shown by the arrows.
Select both the headers and image with the same version number.
It will not allow you to delete the current kernel you are booted with since the current kernel is not displayed.
My recommendation is to keep at least two or preferably three kernels including the latest. The reason for the recommendation is that you will have at least one/two other kernels to boot with, if for what-ever reason the latest kernel you are unable to boot with or introducing a regressed capability such as broken wireless.
Answer by penreturns
Open terminal and check your current kernel:
DO NOT REMOVE THIS KERNEL!
Next, type the command below to view/list all installed kernels on your system.
dpkg --list | grep linux-image
Find all the kernels that lower than your current kernel. When you know which kernel to remove, continue below to remove it. Run the commands below to remove the kernel you selected.
sudo apt-get purge linux-image-x.x.x.x-generic
Finally, run the commands below to update grub2
Reboot your system.
Answer by karthick87
Removing Entries from Grub 2 Entries should be removed by editing or removing files in the /etc/grub.d folder. The /boot/grub/grub.cfg file is read-only and should not normally require editing.
Too Many Kernels?
· If you are not sure of the kernel you are currently using, in a terminal type uname -r.
· Kernels removed via APT (Synaptic, "apt-get remove", etc.) will automatically update grub.cfg and no user action is required.
· A great tool for removing kernels (and menu entries) is Ubuntu-Tweak, a safe and easy-to-use GUI app.
· Install ubuntu tweak
· Ubuntu-Tweak will be available under Applications > System Tools.
Remove Older Kernel Entries
· Select "Package Cleaner" on the left and "Clean Kernel" from the right panel.
· Press the "Unlock" button at the lower right, enter your password.
· Select from the displayed list the kernel images and headers you wish to remove. The kernel in use is not listed.
· Press the "Cleanup" button at the lower right to remove the selected kernel images and headers.
Remove Operating Systems from the Grub menu
· Other Operating Systems which have been removed from the computer will also be removed from the menu once "update-grub" is run as root.
· Menu items are placed on the Grub2 menu by scripts. If you don't want other Operating Systems to be entered in the menu, disable /etc/grub.d/30_osprober
· Run this command to stop the script from running
sudo chmod -x /etc/grub.d/30_os-prober
· DISABLE_30_OS-PROBER='true' in /etc/default/grub
Remove Memtest86+ from the Grub Menu
sudo chmod -x /etc/grub.d/20_memtest86+
· Run the update-grub command to allow the changes to be incorporated in grub.cfg
Note: After kernel updates a new entry is added to the GRUB menu.You can remove the older one if you want.However, most experienced users will advise you to keep at least one spare entry in case something goes wrong with an upgrade and you need to boot an older kernel version for troubleshooting purposes.
Alternate way to remove Kernel entries (prior to 10.04)
for GRUB not GRUB2
You can find it under System>>Administration>>
You see in the second screenshot you can select how many kernels to show? I generally just keep it on 1, but when I get a kernel upgrade I always change it to 2 before restarting so I can select the older kernel if the new kernel has problems with my hardware. Once I know the new kernel is working well I change it back to 1.
Q: How do I remove or hide old kernel versions to clean up the boot menu?
Q: How can I repair grub? (How to get Ubuntu back after installing Windows?)
Q: How do I change the GRUB boot order?
Q: How do I set the grub timeout and the grub default boot entry?