It seems like every single week I have to update my Ubuntu 12.04 Server edition. I configured it to do automatic updates now. Though, I still have to do it manually most of the time. At one point, my boot partition ran out of space and all updates kept failing. I didn’t know at the time why it was failing so I ignored for a few weeks. When I finally paid attention to the issue. I found out that my boot partition was almost full. Apparently, my Linux had warned me every time I logged in to the server since it was on the message of the day page but I normally do not pay to it so it was ignored.
How Did It Get So Big
Well, apparently, Ubuntu holds on to the old kernel when you do sudo apt-get dist-upgrade so whenever it gets updated, it decides to keep the old ones on the boot partition. I didn’t know it at the time so I was really surprised that the boot partition got to a point that I couldn’t update my Ubuntu box. Below is the /etc/motd output that I get whenever I SSH’d to the box. When I was getting an error message that I didn’t have space, I was really confused because if you look at the usage of section of the MOTD it said 43.2% of 6.62GB. But, what I didn’t know at the time was that value was only for the root partition and not for the boot.
login as: networkjutsu networkjutsu@192.168.1.222's password: Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-52-generic x86_64) * Documentation: https://help.ubuntu.com/ System information as of Mon Aug 19 19:33:43 PDT 2013 System load: 0.68 Processes: 76 Usage of /: 43.2% of 6.62GB Users logged in: 1 Memory usage: 32% IP address for eth0: 192.168.1.222 Swap usage: 0% The warning will show up here if I am not mistaken talking about /boot partition. Graph this data and manage this system at https://landscape.canonical.com/ Last login: Mon Aug 19 19:33:15 2013
Checking Hard Disk Space?
To check hard disk space on Ubuntu Linux, type df -ah on the CLI. Below is the output of my Ubuntu box.
networkjutsu@ubuntu:~$ df -ah Filesystem Size Used Avail Use% Mounted on /dev/mapper/ubuntu-root 6.7G 2.9G 3.5G 46% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security udev 79M 4.0K 79M 1% /dev devpts 0 0 0 - /dev/pts tmpfs 36M 244K 35M 1% /run none 5.0M 0 5.0M 0% /run/lock none 88M 0 88M 0% /run/shm /dev/sda1 228M 140M 76M 65% /boot
As you can see above, this particular box has used up 65% of the boot partition. This needs to be cleaned up or I’ll eventually run into the same issue as mentioned earlier.
Boot Partition Contents
At the time, I was curious what are taking up my boot partition so I issued ls -l command and found a similar output as shown below.
networkjutsu@ubuntu:~$ ls -hl /boot total 136M -rw-r--r-- 1 root root 773K Apr 10 2012 abi-3.2.0-23-generic -rw-r--r-- 1 root root 775K Nov 15 2012 abi-3.2.0-34-generic -rw-r--r-- 1 root root 775K Jan 8 2013 abi-3.2.0-36-generic -rw-r--r-- 1 root root 775K Jan 24 2013 abi-3.2.0-37-generic -rw-r--r-- 1 root root 777K Jun 18 11:20 abi-3.2.0-49-generic -rw-r--r-- 1 root root 777K Jul 26 10:08 abi-3.2.0-52-generic -rw-r--r-- 1 root root 137K Apr 10 2012 config-3.2.0-23-generic -rw-r--r-- 1 root root 138K Nov 15 2012 config-3.2.0-34-generic -rw-r--r-- 1 root root 138K Jan 8 2013 config-3.2.0-36-generic -rw-r--r-- 1 root root 138K Jan 24 2013 config-3.2.0-37-generic -rw-r--r-- 1 root root 138K Jun 18 11:20 config-3.2.0-49-generic -rw-r--r-- 1 root root 138K Jul 26 10:08 config-3.2.0-52-generic drwxr-xr-x 3 root root 5.0K Aug 19 19:31 grub -rw-r--r-- 1 root root 15M Dec 15 2012 initrd.img-3.2.0-23-generic -rw-r--r-- 1 root root 15M Dec 15 2012 initrd.img-3.2.0-34-generic -rw-r--r-- 1 root root 15M Feb 7 2013 initrd.img-3.2.0-36-generic -rw-r--r-- 1 root root 15M Feb 7 2013 initrd.img-3.2.0-37-generic -rw-r--r-- 1 root root 15M Jul 19 20:33 initrd.img-3.2.0-49-generic -rw-r--r-- 1 root root 15M Aug 19 19:32 initrd.img-3.2.0-52-generic drwxr-xr-x 2 root root 12K Dec 15 2012 lost+found -rw-r--r-- 1 root root 173K Nov 27 2011 memtest86+.bin -rw-r--r-- 1 root root 175K Nov 27 2011 memtest86+_multiboot.bin -rw------- 1 root root 2.8M Apr 10 2012 System.map-3.2.0-23-generic -rw------- 1 root root 2.8M Nov 15 2012 System.map-3.2.0-34-generic -rw------- 1 root root 2.8M Jan 8 2013 System.map-3.2.0-36-generic -rw------- 1 root root 2.8M Jan 24 2013 System.map-3.2.0-37-generic -rw------- 1 root root 2.8M Jun 18 11:20 System.map-3.2.0-49-generic -rw------- 1 root root 2.8M Jul 26 10:08 System.map-3.2.0-52-generic -rw------- 1 root root 4.8M Apr 10 2012 vmlinuz-3.2.0-23-generic -rw------- 1 root root 4.8M Nov 15 2012 vmlinuz-3.2.0-34-generic -rw------- 1 root root 4.8M Jan 8 2013 vmlinuz-3.2.0-36-generic -rw------- 1 root root 4.8M Jan 24 2013 vmlinuz-3.2.0-37-generic -rw------- 1 root root 4.8M Jun 18 11:20 vmlinuz-3.2.0-49-generic -rw------- 1 root root 4.8M Jul 26 10:08 vmlinuz-3.2.0-52-generic
As shown, there are a lot of older kernel version (vmlinuz) still on the boot partition. In theory, rm command should work but it’s not as clean as running the dpkg command.
Cleaning It Up
As already mentioned, the quickest and probably the best way to clean this up is to issue the command shown below. There are a lot of ways to do this but I prefer this command since it’s only one line of command. When I first had to clean up the boot partition, I actually used several commands to clean it up. This one is just one line of command and you’re good to go. I’ve included the whole output just to show a similar screen that you’ll see.
networkjutsu@ubuntu:~$ dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
[sudo]
password for networkjutsu:
Reading package lists…
Done
Building dependency tree Reading state information…
Done
The following packages will be REMOVED:
linux-headers-3.2.0-23*
linux-headers-3.2.0-23-generic*
linux-headers-3.2.0-34*
linux-headers-3.2.0-34-generic*
linux-headers-3.2.0-36*
linux-headers-3.2.0-36-generic*
linux-headers-3.2.0-37*
linux-headers-3.2.0-37-generic*
linux-headers-3.2.0-49*
linux-headers-3.2.0-49-generic*
linux-image-3.2.0-23-generic*
linux-image-3.2.0-34-generic*
linux-image-3.2.0-36-generic*
linux-image-3.2.0-37-generic*
linux-image-3.2.0-49-generic*
0 upgraded, 0 newly installed, 15 to remove and 0 not upgraded. After this operation, 1,084 MB disk space will be freed. (Reading database … 180798 files and directories currently installed.)
Removing linux-headers-3.2.0-23-generic …
Removing linux-headers-3.2.0-23 …
Removing linux-headers-3.2.0-34-generic …
Removing linux-headers-3.2.0-34 …
Removing linux-headers-3.2.0-36-generic …
Removing linux-headers-3.2.0-36 …
Removing linux-headers-3.2.0-37-generic …
Removing linux-headers-3.2.0-37 …
Removing linux-headers-3.2.0-49-generic …
Removing linux-headers-3.2.0-49 …
Removing linux-image-3.2.0-23-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-23-generic /boot/vmlinuz-3.2.0-23-generic update-initramfs:
Deleting /boot/initrd.img-3.2.0-23-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-23-generic /boot/vmlinuz-3.2.0-23-generic Generating grub.cfg …
Found linux image: /boot/vmlinuz-3.2.0-52-generic
Found initrd image: /boot/initrd.img-3.2.0-52-generic
Found linux image: /boot/vmlinuz-3.2.0-49-generic
Found initrd image: /boot/initrd.img-3.2.0-49-generic
Found linux image: /boot/vmlinuz-3.2.0-37-generic
Found initrd image: /boot/initrd.img-3.2.0-37-generic
Found linux image: /boot/vmlinuz-3.2.0-36-generic
Found initrd image: /boot/initrd.img-3.2.0-36-generic
Found linux image: /boot/vmlinuz-3.2.0-34-generic
Found initrd image: /boot/initrd.img-3.2.0-34-generic
Found memtest86+ image: /memtest86+.bin done
Purging configuration files for linux-image-3.2.0-23-generic …
Examining /etc/kernel/postrm.d . run-parts:
executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-23-generic /boot/vmlinuz-3.2.0-23-generic run-parts:
executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-23-generic /boot/vmlinuz-3.2.0-23-generic
Removing linux-image-3.2.0-34-generic …
Examining /etc/kernel/postrm.d . run-parts:
executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-34-generic /boot/vmlinuz-3.2.0-34-generic update-initramfs:
Deleting /boot/initrd.img-3.2.0-34-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-34-generic /boot/vmlinuz-3.2.0-34-generic
Generating grub.cfg …
Found linux image: /boot/vmlinuz-3.2.0-52-generic
Found initrd image: /boot/initrd.img-3.2.0-52-generic
Found linux image: /boot/vmlinuz-3.2.0-49-generic
Found initrd image: /boot/initrd.img-3.2.0-49-generic
Found linux image: /boot/vmlinuz-3.2.0-37-generic
Found initrd image: /boot/initrd.img-3.2.0-37-generic
Found linux image: /boot/vmlinuz-3.2.0-36-generic
Found initrd image: /boot/initrd.img-3.2.0-36-generic
Found memtest86+ image: /memtest86+.bin done
Purging configuration files for linux-image-3.2.0-34-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-34-generic /boot/vmlinuz-3.2.0-34-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-34-generic /boot/vmlinuz-3.2.0-34-generic
Removing linux-image-3.2.0-36-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-36-generic /boot/vmlinuz-3.2.0-36-generic update-initramfs:
Deleting /boot/initrd.img-3.2.0-36-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-36-generic /boot/vmlinuz-3.2.0-36-generic
Generating grub.cfg …
Found linux image: /boot/vmlinuz-3.2.0-52-generic
Found initrd image: /boot/initrd.img-3.2.0-52-generic
Found linux image: /boot/vmlinuz-3.2.0-49-generic
Found initrd image: /boot/initrd.img-3.2.0-49-generic
Found linux image: /boot/vmlinuz-3.2.0-37-generic
Found initrd image: /boot/initrd.img-3.2.0-37-generic
Found memtest86+ image: /memtest86+.bin done
Purging configuration files for linux-image-3.2.0-36-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-36-generic /boot/vmlinuz-3.2.0-36-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-36-generic /boot/vmlinuz-3.2.0-36-generic
Removing linux-image-3.2.0-37-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-37-generic /boot/vmlinuz-3.2.0-37-generic update-initramfs:
Deleting /boot/initrd.img-3.2.0-37-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-37-generic /boot/vmlinuz-3.2.0-37-generic Generating grub.cfg …
Found linux image: /boot/vmlinuz-3.2.0-52-generic Found initrd image: /boot/initrd.img-3.2.0-52-generic
Found linux image: /boot/vmlinuz-3.2.0-49-generic Found initrd image: /boot/initrd.img-3.2.0-49-generic
Found memtest86+ image: /memtest86+.bin done Purging configuration files for linux-image-3.2.0-37-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-37-generic /boot/vmlinuz-3.2.0-37-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-37-generic /boot/vmlinuz-3.2.0-37-generic Removing linux-image-3.2.0-49-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-49-generic /boot/vmlinuz-3.2.0-49-generic update-initramfs:
Deleting /boot/initrd.img-3.2.0-49-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-49-generic /boot/vmlinuz-3.2.0-49-generic
Generating grub.cfg …
Found linux image: /boot/vmlinuz-3.2.0-52-generic
Found initrd image: /boot/initrd.img-3.2.0-52-generic
Found memtest86+ image: /memtest86+.bin done
The link /vmlinuz.old is a damaged link
Removing symbolic link vmlinuz.old you may need to re-run your boot loader[grub] The link /initrd.img.old is a damaged link
Removing symbolic link initrd.img.old you may need to re-run your boot loader[grub]
Purging configuration files for linux-image-3.2.0-49-generic …
Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.2.0-49-generic /boot/vmlinuz-3.2.0-49-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.2.0-49-generic /boot/vmlinuz-3.2.0-49-generic
Verification
To verify that the command worked, issue both commands. Though, the first command will be fine.
networkjutsu@ubuntu:~$ df -ah Filesystem Size Used Avail Use% Mounted on /dev/mapper/ubuntu-root 6.7G 1.7G 4.7G 27% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security udev 79M 12K 79M 1% /dev devpts 0 0 0 - /dev/pts tmpfs 36M 244K 35M 1% /run none 5.0M 0 5.0M 0% /run/lock none 88M 0 88M 0% /run/shm /dev/sda1 228M 27M 189M 13% /boot networkjutsu@ubuntu:~$ ls -al /boot total 23544 drwxr-xr-x 4 root root 2048 Aug 19 20:18 . drwxr-xr-x 23 root root 4096 Aug 19 20:18 .. -rw-r--r-- 1 root root 795365 Jul 26 10:08 abi-3.2.0-52-generic -rw-r--r-- 1 root root 140629 Jul 26 10:08 config-3.2.0-52-generic drwxr-xr-x 3 root root 5120 Aug 19 20:18 grub -rw-r--r-- 1 root root 14819736 Aug 19 19:32 initrd.img-3.2.0-52-generic drwxr-xr-x 2 root root 12288 Dec 15 2012 lost+found -rw-r--r-- 1 root root 176764 Nov 27 2011 memtest86+.bin -rw-r--r-- 1 root root 178944 Nov 27 2011 memtest86+_multiboot.bin -rw------- 1 root root 2893555 Jul 26 10:08 System.map-3.2.0-52-generic -rw------- 1 root root 4978224 Jul 26 10:08 vmlinuz-3.2.0-52-generic
Thoughts
I am actually surprised that Ubuntu chose to keep the older kernel when doing an update. I wish in the future release that they will include the uninstall of the older kernel so I won’t have to do this every time I am running out of boot partition space. Yes, I can redo the partition but it will eventually fill up anyway so it’s a wasted effort in my opinion.
Reference
Disclosure
NetworkJutsu.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com.