How to cleanup the /boot partition on Ubuntu Linux
by Riley MacDonald, June 27, 2017

My headless Ubuntu Server ran into issues when attempting to install (kernel) updates:

# When trying to upgrade
$ sudo apt-get upgrade
 
# The following was observed
Setting up linux-image-extra-4.4.0-81-generic (4.4.0-81.104) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-81-generic /boot/vmlinuz-4.4.0-81-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-81-generic /boot/vmlinuz-4.4.0-81-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-81-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
 
gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-81-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-81-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-extra-4.4.0-81-generic; however:
  Package linux-image-extra-4.4.0-81-generic is not configured yet.
 
dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 4.4.0.81.87); however:
  Package linux-image-generic is not configured yet.
 
dpkg: error processing package linux-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report written because the error message indicates its a followup error from a previous failure.
 Errors were encountered while processing:
 linux-image-extra-4.4.0-81-generic
 linux-image-generic
 linux-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

gzip: stdout: No space left on device Uh oh, something’s full!

Let’s take a look at the disk space using the disk space usage tool df.

# -a, --all; include dummy file systems
$ df -a
 
Filesystem                   1K-blocks      Used Available Use% Mounted on
sysfs                                0         0         0    - /sys
proc                                 0         0         0    - /proc
udev                            938928         0    938928   0% /dev
devpts                               0         0         0    - /dev/pts
tmpfs                           191816     20348    171468  11% /run
/dev/mapper/bridget--vg-root 305103120 266315512  23266228  92% /
securityfs                           0         0         0    - /sys/kernel/security
tmpfs                           959072         0    959072   0% /dev/shm
tmpfs                             5120         0      5120   0% /run/lock
tmpfs                           959072         0    959072   0% /sys/fs/cgroup
cgroup                               0         0         0    - /sys/fs/cgroup/systemd
pstore                               0         0         0    - /sys/fs/pstore
cgroup                               0         0         0    - /sys/fs/cgroup/blkio
cgroup                               0         0         0    - /sys/fs/cgroup/hugetlb
cgroup                               0         0         0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                               0         0         0    - /sys/fs/cgroup/memory
cgroup                               0         0         0    - /sys/fs/cgroup/devices
cgroup                               0         0         0    - /sys/fs/cgroup/freezer
cgroup                               0         0         0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                               0         0         0    - /sys/fs/cgroup/perf_event
cgroup                               0         0         0    - /sys/fs/cgroup/cpuset
cgroup                               0         0         0    - /sys/fs/cgroup/pids
systemd-1                            0         0         0    - /proc/sys/fs/binfmt_misc
debugfs                              0         0         0    - /sys/kernel/debug
hugetlbfs                            0         0         0    - /dev/hugepages
mqueue                               0         0         0    - /dev/mqueue
fusectl                              0         0         0    - /sys/fs/fuse/connections
/dev/sdb                      76766184     70168  72773384   1% /mnt/backup_drive
/dev/sda1                       482922    452559      5429  99% /boot
cgmfs                              100         0       100   0% /run/cgmanager/fs
lxcfs                                0         0         0    - /var/lib/lxcfs
/home/user/.Private     305103120 266315512  23266228  92% /home/user
tmpfs                           191816         0    191816   0% /run/user/119

/boot is 99% full! My machine doesn’t have a very large drive (yet). It’s just performing some minuscule tasks for me. Let’s check to see how many kernels are on disk since I installed the system a few months ago.

# List the kernels but only show the installed ones
$ sudo dpkg --list 'linux-image*' | grep ^ii
 
ii  linux-image-4.4.0-64-generic       4.4.0-64.85  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-66-generic       4.4.0-66.87  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-70-generic       4.4.0-70.91  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-71-generic       4.4.0-71.92  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-72-generic       4.4.0-72.93  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-75-generic       4.4.0-75.96  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-78-generic       4.4.0-78.99  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-79-generic       4.4.0-79.100 amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-81-generic       4.4.0-81.104 amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-64-generic 4.4.0-64.85  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-66-generic 4.4.0-66.87  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-70-generic 4.4.0-70.91  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-71-generic 4.4.0-71.92  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-72-generic 4.4.0-72.93  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-75-generic 4.4.0-75.96  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-78-generic 4.4.0-78.99  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-79-generic 4.4.0-79.100 amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP

Let’s double check the current kernel.

$ uname -a
Linux server_name 4.4.0-79-generic #100-Ubuntu SMP Wed May 17 19:58:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

No need to keep all of these kernels around, the system has been stable for quite some time now. Some users and Ubuntu itself output will suggest running autoremove to cleanup unused kernels but I don’t feel safe running that command. I like to keep at least 3 of the most recent kernels in case I need to revert back to a previous version.

I’ll just remove a few to free up some disk space for now:

$ sudo apt-get remove linux-image-4.4.0-64-generic linux-image-extra-4.4.0-64-generic linux-image-4.4.0-66-generic linux-image-extra-4.4.0-66-generic
 
# ...
After this operation, 438 MB disk space will be freed.
Do you want to continue? [Y/n] Y
 
# My previously failed upgrade kicked right in and finished after the remove operation.
Setting up linux-image-generic (4.4.0.81.87) ...
Setting up linux-generic (4.4.0.81.87) ...
 
# Check the boot partition now
$ df /boot/
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sda1         482922 354074    103914  78% /boot

Great, this should hold me over until a larger disk is installed.

Open the comment form

Leave a comment:

Comments will be reviewed before they are posted.

User Comments:

Be the first to leave a comment on this post!