I am running Ubuntu 12.04.1 LTS i686 on VirtulBox. Every time I check the updates, there's a new Linux kernel. If I install the new kernel, I have to install the Virtulbox Guest Additions again and reboot the server. I don't want to do this every week. I know I can manually uncheck the kernel packages from update manager, but is there a way to skip the kernel update automatically? I found an answer here, but it's for Ubuntu 10. Thanks.
7 Answers
APT (Advanced Packaging Tool) is the system that Ubuntu uses to manage all of the software installed on a system. It allows you to “pin” a package to a certain version, so that it won’t be updated when you the Update Manager runs.
To pin your kernel packages, first you must determine what version your kernel is. One way to do this is to open the Synaptic Package Manager in System > Administration.
Type in “linux-generic” in the Quick search text field and hit enter.
Make a note of the number listed in the “Installed Version” column. We’ll use it in the next step.
Next, we need to edit the file /etc/apt/preferences. Open it by pressing Alt+F2 to bring up the Run Application window and entering in:
gksudo gedit /etc/apt/preferences
This will open up a gedit window. Most likely the window will be blank, unless you’ve played around with APT before.
In the window, type in the following, replacing the version number with the version number you found in the Synaptic Package Manager.
Package: linux-generic linux-headers-generic linux-image-generic linux-restricted-modules-generic
Pin: version <insert version here>
Pin-Priority: 1001
Save the file and close gedit. If you open the Update Manager, you should see that the Linux kernel updates are now hidden!
Blocking packages with APT/DPKG
Remember the package name of your kernel from above.
Open a terminal and run:
sudo -s
And hit enter.
Enter your password for sudo:
echo kernel_package_name hold | dpkg --set-selections
Replace kernel_package_name
with the name of the kernel you want to pin.
Now run:
sudo apt-get update && sudo apt-get upgrade
To remove pin from Apt/Dpkg:
Open a terminal
sudo -s
echo kernel_package install | dpkg --set-selections
Replace kernel_package with the package you want to pin.
Now run:
sudo apt-get update && sudo apt-get upgrade
What you're trying to do is called pinning. The sources I gave you above, have the essentials on what you must do to accomplish your tasks in hand.
-
1Thanks for your reply. It seems that we are using different version. I don't have Synaptic Package Manager and /etc/apt/preferences on my Ubuntu 12.04.– garconcnAug 21, 2012 at 0:20
-
2
-
1@garconcn, you can install Synaptic and install the fix i told you, or read the question again, as i have put more info on it– LnxSlckAug 21, 2012 at 0:49
-
2@LnxSlck, I installed Synaptic and followed your instruction. It works. Thanks.– garconcnAug 21, 2012 at 0:52
In one line it is:
echo $(dpkg -l "*$(uname -r)*" | grep image | awk '{print $2}') hold | dpkg --set-selections
This will set kernel's image state from install to hold and thus will prevent updates.
The one-liner by Christoph doesn't take the extra package into account (e.g. linux-image-extra-3.13.0-45-generic). Rather use this one:
for i in $(dpkg -l "*$(uname -r)*" | grep image | awk '{print $2}'); do echo $i hold | dpkg --set-selections; done
In relation superlexx's suggestion: that line will miss the "headers" package:
dpkg -l "*$(uname -r)*" | grep image | awk '{print $2}'
linux-image-3.13.0-48-generic
linux-image-extra-3.13.0-48-generic
So how about simply using the following:
dpkg -l "*$(uname -r)*" | grep kernel | awk '{print $2}'
linux-headers-3.13.0-48-generic
linux-image-3.13.0-48-generic
linux-image-extra-3.13.0-48-generic
-
1If the extras/headers/etc packages are not marked, are there issues? Or, are you suggesting marking them as well for completeness? I'd expect that Ubuntu would not attempt to install an updated headers package, until the linux-image was installed (headers being a dependency of image). I have yet to verify this. Nov 14, 2015 at 1:02
-
2You guys could collaborate on a single one-liner instead of stacking 3 anwsers one on another. =P Just sayin Nov 12, 2016 at 0:33
-
1It's unnecesary to invoke grep if you're already using awk:
dpkg -l "*$(uname -r)*" | awk '/kernel/{print $2}'
Jun 28, 2017 at 23:15
This purges meta kernel packages that enable kernel updates:
sudo apt purge $(apt-cache rdepends -i --installed linux-{headers,image}-$(uname -r)|awk '!/[0-9]/ && /^[ ]/{print $1}')
(If you have just upgraded kernel, you have to reboot first with the new kernel, or find the latest kernel release and use it in above instead of "$(uname -r)".)
It is recommended to install kernels updates though since they are mostly security updates.
On Ubuntu 16.04.1, the following code works
for i in $(dpkg -l "*$(uname -r)*" | grep image | awk '{print $2}'); do echo $i hold | sudo dpkg --set-selections; done
the is an improvement of Superlexx's code, the sudo
is added
dpkg -l | grep linux-image
You will find:
hi linux-image-4.4.0-34-generic ...
hi linux-image-extra-4.4.0-34-generic ...
note that the tag now reads hi
, not ii
to remove pin
for i in $(dpkg -l "*$(uname -r)*" | grep image | awk '{print $2}'); do echo $i install | sudo dpkg --set-selections; done
-
Nice answer but you put
sudo
in the commentary not the command... Jan 18, 2017 at 20:49
Shorter version: (Replace "hold" with "install" to remove pin)
dpkg -l "*$(uname -r)*" | grep kernel | awk '{print $2,"hold"}' | sudo dpkg --set-selections
To see the state of all kernel images and headers, run:
dpkg --get-selections | grep "linux-"