Menghapus Kernel yang Tidak Digunakan pada Ubuntu

Posted by

Harddisk SSD yang saya gunakan pada Laptop Lenovo memiliki kapasitas 120 GB. Setengah dari kapasitasnya saya install Linux openSUSE dan setengahnya lagi Ubuntu. Dulunya Linux ElementaryOS. Namun setelah di upgrade, berubah menjadi Ubuntu 😀 . Memang sih base system yang digunakan oleh ElementaryOS ini adalah Ubuntu.

Ketika saya pakai dan ada kebutuhan untuk diinstall Docker dan Container Oracle Xpress, free space yang ada hanya beberapa GB saja. Kemudian coba sortir folder mana saja yang pemakaiannya cukup besar dan bisa dihapus. Salah satu folder yang pemakaiannya cukup besar adalah /usr. Dimana pada folder tersebut terdapat folder Linux Kernel Header yang sudah tidak digunakan.

Mau coba hapus langsung folder tersebut dengan perintah rm -rvf khawatir salah hapus. Yang ada malah ngga bisa booting ke Ubuntu nya 😀 . Setelah mencari cara bagaimana cara menghapus Kernel yang sudah tidak digunakan, ditemukanlah simple script yang dapat mengecek dan menghapusnya. Script tersebut dapat didownload dari Github pada link berikut : kernel-purge.sh. Atau bisa juga download via curl

curl -k https://raw.githubusercontent.com/kivisade/kernel-purge/master/kernel-purge.sh > /tmp/kernel-purge.sh

Cara pemakaiannya, cukup berikan hak akses eksekusi dan jalankan script. Script akan otomatis mengecek dan menghapus kernel-kernel yang sudah tidak digunakan. Prosesnya kurang lebih seperti berikut :

chmod +x /tmp/kernel-purge.sh
/tmp/kernel-purge.sh

root@lenovo:/srv/kernel-purge# /tmp/kernel-purge.sh
Running kernel version is: 4.15.0-54
The following (unused) KERNEL packages will be removed:
linux-headers-3.13.0-133
linux-headers-3.13.0-133-generic
linux-headers-3.13.0-46
linux-headers-3.13.0-46-generic
linux-headers-3.13.0-48
linux-headers-3.13.0-48-generic
linux-headers-3.13.0-49
linux-headers-3.13.0-49-generic
linux-headers-3.13.0-51
linux-headers-3.13.0-51-generic
linux-headers-3.13.0-52
linux-headers-3.13.0-52-generic
linux-headers-3.13.0-83
linux-headers-3.13.0-83-generic
linux-headers-3.13.0-91
linux-headers-3.13.0-91-generic
linux-headers-3.13.0-96
linux-headers-3.13.0-96-generic
linux-headers-4.15.0-29
linux-headers-4.15.0-29-generic
linux-headers-4.15.0-66
linux-headers-4.15.0-66-generic
linux-image-4.15.0-29-generic
linux-image-4.15.0-66-generic
linux-lts-vivid-tools-3.19.0-56
linux-lts-vivid-tools-3.19.0-80
linux-modules-4.15.0-29-generic
linux-modules-4.15.0-66-generic
linux-modules-extra-4.15.0-29-generic
linux-modules-extra-4.15.0-66-generic
Do you want to continue [yN]? y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  linux-tools-common
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  linux-generic* linux-headers-3.13.0-133* linux-headers-3.13.0-133-generic* linux-headers-3.13.0-46* linux-headers-3.13.0-46-generic*
  linux-headers-3.13.0-48* linux-headers-3.13.0-48-generic* linux-headers-3.13.0-49* linux-headers-3.13.0-49-generic* linux-headers-3.13.0-51*
  linux-headers-3.13.0-51-generic* linux-headers-3.13.0-52* linux-headers-3.13.0-52-generic* linux-headers-3.13.0-83*
  linux-headers-3.13.0-83-generic* linux-headers-3.13.0-91* linux-headers-3.13.0-91-generic* linux-headers-3.13.0-96*
  linux-headers-3.13.0-96-generic* linux-headers-4.15.0-29* linux-headers-4.15.0-29-generic* linux-headers-4.15.0-66*
  linux-headers-4.15.0-66-generic* linux-headers-generic* linux-headers-generic-lts-trusty* linux-image-4.15.0-29-generic*
  linux-image-4.15.0-66-generic* linux-image-generic* linux-image-generic-lts-trusty* linux-lts-vivid-tools-3.19.0-56*
  linux-lts-vivid-tools-3.19.0-80* linux-modules-4.15.0-29-generic* linux-modules-4.15.0-66-generic* linux-modules-extra-4.15.0-29-generic*
  linux-modules-extra-4.15.0-66-generic*
0 upgraded, 0 newly installed, 35 to remove and 0 not upgraded.
After this operation, 1.362 MB disk space will be freed.
(Reading database ... 507770 files and directories currently installed.)
Removing linux-generic (4.15.0.66.68) ...
Removing linux-headers-3.13.0-133-generic (3.13.0-133.182) ...
Removing linux-headers-3.13.0-133 (3.13.0-133.182) ...
... skip ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-29-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-66-generic
Found initrd image: /boot/initrd.img-4.15.0-66-generic
Found linux image: /boot/vmlinuz-4.15.0-54-generic
Found initrd image: /boot/initrd.img-4.15.0-54-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found openSUSE Leap 15.1 on /dev/sda1
done
Removing linux-image-generic-lts-trusty (3.13.0.165.175) ...
Removing linux-image-generic (4.15.0.66.68) ...
Removing linux-modules-extra-4.15.0-66-generic (4.15.0-66.75) ...
Removing linux-image-4.15.0-66-generic (4.15.0-66.75) ...
I: /vmlinuz is now a symlink to boot/vmlinuz-4.15.0-54-generic
I: /initrd.img is now a symlink to boot/initrd.img-4.15.0-54-generic
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-66-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-54-generic
Found initrd image: /boot/initrd.img-4.15.0-54-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found openSUSE Leap 15.1 on /dev/sda1
done
Removing linux-lts-vivid-tools-3.19.0-56 (3.19.0-56.62~14.04.1) ...
Removing linux-lts-vivid-tools-3.19.0-80 (3.19.0-80.88~14.04.1) ...
Removing linux-modules-4.15.0-29-generic (4.15.0-29.31) ...
Removing linux-modules-4.15.0-66-generic (4.15.0-66.75) ...
(Reading database ... 213236 files and directories currently installed.)
Purging configuration files for linux-modules-4.15.0-66-generic (4.15.0-66.75) ...
dpkg: warning: while removing linux-modules-4.15.0-66-generic, directory '/lib/modules/4.15.0-66-generic' not empty so not removed
Purging configuration files for linux-modules-extra-4.15.0-66-generic (4.15.0-66.75) ...
Purging configuration files for linux-modules-4.15.0-29-generic (4.15.0-29.31) ...
dpkg: warning: while removing linux-modules-4.15.0-29-generic, directory '/lib/modules/4.15.0-29-generic' not empty so not removed
Purging configuration files for linux-image-4.15.0-66-generic (4.15.0-66.75) ...
Purging configuration files for linux-image-4.15.0-29-generic (4.15.0-29.31) ...
Purging configuration files for linux-modules-extra-4.15.0-29-generic (4.15.0-29.31) ...

Ternyata Kernel yang sudah tidak digunakan cukup banyak dan masih ada pada Ubuntu. Dengan dihapusnya old Kernel tersebut, free space yang didapatkan cukup lumayan dan bisa diinstall Docker dan Container Oracle Xpress yang besarnya lebih kurang 2.5 GB.

Silakan dicoba dan semoga bermanfaat 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.