Tech Monger

Programming, Web Development and Computer Science.

Skip to main content| Skip to information by topic

How to safely free up /boot directory in Ubuntu Linux

If you are getting message prompt in your ubuntu operating system The Volume "boot" has only * MB disk space remaining then it's time to free up some space inside /boot partition in your operating system. But it should be carefully handled because /boot directory contains files responsible for starting your machine which includes kernel, initial ramdisk (initrd), grub(bootloader) and System Map among others.

Disk Space Notification Prompt

On startup you would get following prompt on Ubuntu 16.04 which asks you to remove files from /boot before it gets completely full.

The Volume
Ubuntu Low Disk Space Prompt : /boot

If you do click on examine then you would get following prompt, which is not very useful though.

Disk Usage Percentage for /boot and /grub
Ubuntu Disk Usage Analyzer : /boot

Solution - Boot Cleanup

    Analyze Free Space and Large Files

  1. Check how much free space does /boot holds and which files are occupying majority of disk space.

    Note that you may need to use sudo as not all files in /boot/are accessible by non root users.

    $ df -h /boot
    
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1       472M  431M   18M  97% /boot
    
    $ sudo du -sh /boot/*
    
    1.5M	/boot/abi-4.13.0-32-generic
    1.5M	/boot/abi-4.13.0-36-generic
    1.5M	/boot/abi-4.13.0-37-generic
    210K	/boot/config-4.13.0-32-generic
    210K	/boot/config-4.13.0-36-generic
    210K	/boot/config-4.13.0-37-generic
    6.9M	/boot/grub
    50M	/boot/initrd.img-4.13.0-32-generic
    50M	/boot/initrd.img-4.13.0-36-generic
    50M	/boot/initrd.img-4.13.0-37-generic
    12K	/boot/lost+found
    180K	/boot/memtest86+.bin
    182K	/boot/memtest86+.elf
    182K	/boot/memtest86+_multiboot.bin
    3.8M	/boot/System.map-4.13.0-32-generic
    3.8M	/boot/System.map-4.13.0-36-generic
    3.8M	/boot/System.map-4.13.0-37-generic
    7.4M	/boot/vmlinuz-4.13.0-32-generic
    7.4M	/boot/vmlinuz-4.13.0-36-generic
    7.4M	/boot/vmlinuz-4.13.0-37-generic
    
  2. Check Running Kernel Version

  3. For the majority of you files having relatively large size would be of initrd and vmlinuz kernel images.
    These includes old kernel and startup images which can be safely removed.
    Hence first check current kernel version which is in use.
    $ uname -r
    
    4.13.0-37-generic
    
  4. Autoremove Unused Kernel Files

  5. We can use autoremove feature to purge old and unwanted files including kernel images.
    $ sudo apt autoremove --purge
    
    After this operation, 1,574 MB disk space will be freed.
    Do you want to continue? [Y/n] Y
    

For most of you above will solve the issue. However if purge fails for some reason then you may need to manually remove files. It could fail if you have 0 byte space inside /boot.

Manual Cleanup

If you are getting following message then you can perform manual removal.

The Volume boot has only 0 byte disk space remaining.

  • You can manually remove all files which are not related to current kernel version 4.13.0-37.
  • However it's good idea to keep at least one older version of kernel inside boot along with current version because if current kernel gets corrupted then you can always start your system using older version of kernel.
  • Hence we recommend you to only remove files related to oldest one which in our case is 4.13.0-32.
  • We will remove 4.13.0-32 files from /boot and store into /tmp directory so we can restore it later if require.
    $ mkdir /tmp/4.13.0-32/
    $ sudo mv /boot/*4.13.0-32* /tmp/4.13.0-32/
    
  • Now run autoremove purge again.
    $ sudo apt autoremove --purge
    

Conclusion - If boot mount is getting full then ubuntu will notify you and you should remove old and unused files either purging by autoremove or by moving manually from boot partition to some other location without affecting current kernel files.

Tagged Under : Linux Ubuntu