Monday, May 6, 2024
22
rated 0 times [  22] [ 0]  / answers: 1 / hits: 6906  / 3 Years ago, fri, june 25, 2021, 8:46:37

I got a notification of updates to Ubuntu 20.04. I always check the list of updates to decide how serious a backup I need to do before updating. Today's kernel update (5.13.0.28.31~20.04.15) needs half a gigabyte of extra disk space:


$ sudo apt upgrade 
...
The following NEW packages will be installed:
linux-headers-5.13.0-28-generic linux-hwe-5.13-headers-5.13.0-28
linux-image-5.13.0-28-generic linux-modules-5.13.0-28-generic
linux-modules-extra-5.13.0-28-generic
The following packages will be upgraded:
linux-generic-hwe-20.04 linux-headers-generic-hwe-20.04
linux-image-generic-hwe-20.04 linux-libc-dev
4 to upgrade, 5 to newly install, 0 to renove and 0 not to upgrade
Need to get 95.0 MB of archives.
After this operation, 508 MB of additional disk space will be used.

I know that Ubuntu allows several kernels to coexist, so this kernel must use fresh disk space rather than replacing existing software, but it still seems large. I've not kept notes, but I thought a kernel update was usually a couple of hundred MBs. Have I just never noticed the size of kernels before or is there something unusual about today's update?


More From » package-management

 Answers
2

Why does today's kernel update need half a gigabyte of disk space?


There's more to it than meets the eye. Despite the fact that you see that 508MB of the disk will be used, does this mean this storage is permanent? After running a simple command, almost 450MB of storage will be freed up.


Generally, when a kernel upgrade occurs, new files and directories have to be placed. However, it won't automatically remove the older ones. Consequently, disk usage increases.


After upgrading your kernel, you can remove a sum of the older kernel modules by running:


sudo apt autoremove

In total, it will free up almost 450MB of disk space by removing the oldest kernel and modules.




Q&A



Why does today's kernel update need half a gigabyte of disk space?



It is because it has to place new files. It won't remove the older files, resulting in extended disk usage.



I've not kept notes, but I thought a kernel update was usually a couple of hundred MBs



Yes, they are, in fact, this upgrade is only 60-80MB.



is there something unusual about today's update?



Yes, this is a major kernel upgrade. You might not know that Ubuntu 20.04 will soon get upgraded to its 4th stage. So you'll get many upgrades like this. Get ready for Ubuntu 20.04.04!!




Why are kernels so big?


Linux kernel manages and controls the hardware resources like I/O (networking, storage, graphics and various user interface devices, etc.), memory and CPU for your device or computer. Each time a new upgrade comes, you get newer drivers and resources for better hardware resources.


If you are using a wireless card with custom-built drivers, then you have to recompile the drivers after the newer kernel kicks in. However, what about the other modules? The modules you do not need are still in your system. Why have iwlwifi when I use rtw99? The Linux kernel comes with thousands of different drivers for all kinds of devices. By default, apt will install ALL of them. This is one of the main reasons, why you should compile the Linux kernel yourself. To compile Linux kernel yourself without unnecessary things refer to this thread, comment #2.




Difference between Download Size and Installed Size.


Why does it show:



Need to get 95.0 MB of archives.



Even though it is saying "508 MB of additional disk space will be used"?


It is because of Compression.


The .deb also known as the "archive" format uses lossless compression algorithms to fit a huge number of files in a single .deb without increasing its size. You can run the following command to see the difference between installed size and download size.


apt show linux-generic-hwe-20.04 linux-headers-generic-hwe-20.04 linux-image-generic-hwe-20.04 linux-headers-5.13.0-28-generic linux-hwe-5.13-headers-5.13.0-28 linux-image-5.13.0-28-generic linux-modules-5.13.0-28-generic linux-modules-extra-5.13.0-28-generic | egrep "Size|Package" | grep -v APT

Here is a table showing the difference:





















































Package Installed-Size Download-Size
Package: linux-generic-hwe-20.04 Installed-Size: 19.5 kB Download-Size: 1,928 B
Package: linux-headers-generic-hwe-20.04 Installed-Size: 19.5 kB Download-Size: 2,516 B
Package: linux-image-generic-hwe-20.04 Installed-Size: 19.5 kB Download-Size: 2,628 B
Package: linux-headers-5.13.0-28-generic Installed-Size: 24.5 MB Download-Size: 2,569 kB
Package: linux-hwe-5.13-headers-5.13.0-28 Installed-Size: 75.9 MB Download-Size: 11.8 MB
Package: linux-image-5.13.0-28-generic Installed-Size: 10.2 MB Download-Size: 10.0 MB
Package: linux-modules-5.13.0-28-generic Installed-Size: 99.3 MB Download-Size: 18.3 MB
Package: linux-modules-extra-5.13.0-28-generic Installed-Size: 298 MB Download-Size: 51.1 MB

Should I remove older kernels?


Yes, you can remove old kernels, but it depends on how you operate your system.



  • If you have a habit of breaking your system once every week/month then its a good idea to keep multiple kernels.



  • If you use your system sincerely without doing experiments then its a good idea to remove older kernels.




How do I remove older kernels completely?


To completely purge ALL old kernels:


apt list --installed | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

To only purge the EoSS kernels:


sudo apt autopurge

Alternatively, as raj commented, you can wait for Software Updater to popup and ask for the removal of older kernels.


[#821] Sunday, June 27, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
montwim

Total Points: 103
Total Questions: 112
Total Answers: 120

Location: Vietnam
Member since Mon, Mar 14, 2022
2 Years ago
montwim questions
;