0

I am using hyper-v to create a VM running Ubuntu guest. I git cloned the kernel source, and compiled it. Then second time, I wanted to modify the kernel source. Just the default settings other than adding a custom name to the version.

make menuconfig
make
make modules_install
make install

When I ran modules_install, I saw an error message that my VM ran out of free space. I managed to allocate more space to the virtual hard drive and solved the issue then.

While booting up, the grub displays 3 different kernels available. My question is, what is taking up all the disk space? If i keep compiling kernels, will that take GBs of my disk? If so, how can I free up space? Can I delete the unused kernels to reclaim some space?

Please suggest.

hago

Update 1 The output of ls -l /boot is

total 1319637
-rw-r--r-- 1 root root    224422 Aug  1  2019 config-5.0.0-25-generic
-rw-r--r-- 1 root root    224535 Jul  6 22:35 config-5.1.0-eudyptula-h.1.1-dirty
-rw-r--r-- 1 root root    224525 Jul  2 18:15 config-5.1.0-h.1.1
-rw-r--r-- 1 root root    224538 Jul  1 20:06 config-5.1.1hago_1_1
-rw-r--r-- 1 root root    224538 Jul  1 19:25 config-5.1.1hago_1_1.old
drwxr-xr-x 4 root root       512 Jan  1  1970 efi
drwxr-xr-x 6 root root      4096 Jul  6 22:43 grub
-rw-r--r-- 1 root root  40808013 Jul  1 19:18 initrd.img-5.0.0-25-generic
-rw-r--r-- 1 root root 410846721 Jul  6 22:41 initrd.img-5.1.0-eudyptula-h.1.1-dirty
-rw-r--r-- 1 root root 410821916 Jul  2 18:19 initrd.img-5.1.0-h.1.1
-rw-r--r-- 1 root root  10622869 Jul  1 21:07 initrd.img-5.1.1
-rw-r--r-- 1 root root 410847209 Jul  1 21:09 initrd.img-5.1.1hago_1_1
-rw-r--r-- 1 root root    182704 Jan 28  2016 memtest86+.bin
-rw-r--r-- 1 root root    184380 Jan 28  2016 memtest86+.elf
-rw-r--r-- 1 root root    184840 Jan 28  2016 memtest86+_multiboot.bin
-rw------- 1 root root   4290047 Aug  1  2019 System.map-5.0.0-25-generic
-rw-r--r-- 1 root root   4346940 Jul  6 22:35 System.map-5.1.0-eudyptula-h.1.1-dirty
-rw-r--r-- 1 root root   4346456 Jul  2 18:15 System.map-5.1.0-h.1.1
-rw-r--r-- 1 root root   4346456 Jul  1 20:06 System.map-5.1.1hago_1_1
-rw-r--r-- 1 root root   4346456 Jul  1 19:25 System.map-5.1.1hago_1_1.old
-rw------- 1 root root   8711928 Aug  1  2019 vmlinuz-5.0.0-25-generic
-rw-r--r-- 1 root root   8808832 Jul  6 22:35 vmlinuz-5.1.0-eudyptula-h.1.1-dirty
-rw-r--r-- 1 root root   8808832 Jul  2 18:15 vmlinuz-5.1.0-h.1.1
-rw-r--r-- 1 root root   8808832 Jul  1 20:06 vmlinuz-5.1.1hago_1_1
-rw-r--r-- 1 root root   8808832 Jul  1 19:25 vmlinuz-5.1.1hago_1_1.old

Update 2 Now when I boot the VM, I see another new kernel version 5.3.0 appearing in the GRUB menu.

1
  • Please edit your question and include the output of ls -l /boot (mount it first, if necessary) Jul 6 '20 at 23:00
0

Since these are custom-built, all you have to do is rm all the old kernels you don't want anymore, and then sudo grub-mkconfig. Note that /boot isn't the only location, there are kernel files in /lib/modules/ and /var/lib/initramfs-tools/ as well, although not nearly as large. apt won't keep anything you build yourself cleaned up, unfortunately.

3
  • thanks. By rm all the old kernels, you meant to remove them from the /boot, /lib/modules/ and /var/lib/initramfs-tools/ dir? and then run sudo update-grub2?
    – hago
    Jul 7 '20 at 17:54
  • The update just looks for a vmlinuz and then does some checks to ensure its related files are also present. Removing them and removing the grub entries is painless. I also just found out that grub-mkconfig is the command now, and the older ones are just symlinked to it; all these years and I never noticed. Jul 7 '20 at 18:21
  • 1
    Thanks. I found that /lib/modules had few directories taking up GBs of space. I deleted 1 dir related to an unused kernel and reclaimed 5GB of storage.
    – hago
    Jul 8 '20 at 9:20
0

A typical size for the initrd is in the tens-of-megs range. Your custom builds are 410MB. Check your kernel build settings and exclude things from the initrd that can be loaded post-boot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.