Every month (at least) I check my Ubuntu servers for updates and every month (at least) I forget how I clean old installs etc.
The following is a list of commands that I use regularly. This post is not meant to be a comprehensive description of these Linux/Ubuntu commands, more a checklist for updating my servers.
df or df /boot
When I log into my servers and see updates available the first thing I tend to do is run df and check the /boot usage/space available (obviously I could jump straight to the next command in my list, but I sort of like knowing what space I have available). I’ve tried carrying out an update in the past with next to no space available and sadly end up spending way too long trying to clear up partially installed components and/or clear disc space.
Alternatively, if you only want to view the /boot usage/space – which is really what we’re after here, just use df /boot.
sudo apt-get autoremove
apt-get is the Ubuntu based package manager (well, it’s actually originally from Debian), we’ll need to run it as the su. The options supplied will remove old packages and configurations files and all unused packages.
Why is the above useful? Well as we add updates to Ubuntu, it’s not unusual to find previous releases sat on our machine in the /boot area (I assume this is so we could roll back a release). Once you’re happy with your latest updates (or as I do, prior to the next update), run this command sudo apt-get autoremove to clear out these unused packages and free up disc space.
sudo apt-get update
The update option will retrieve a new list of packages available. This doesn’t install new versions of software but will ensure all package index files are upto date.
sudo apt-get upgrade
Now its time to upgrade we run sudo apt-get upgrade. This will look to clear out old packages if required, but doesn’t seem to do a more comprehensive removal, unlike purge and autoremove.
This command uses information from apt-get update to know about new versions of packages on the machine.
sudo apt-get dist-upgrade
If we want upgrade dependencies etc. this can be used instead of the straight upgrade.
sudo reboot now
Time to restart the server. This will obviously reboot the machine instantly (now).
uname -r
I don’t tend to use this during my “update” process, but if I want to know what version of the Linux kernel I’m running, using uname -r will tell me. This does become important if (as has happened to me) I cannot autoremove old kernels. Obviously when targeting specific kernels you need to know which one is current, or to put it another way, which one to not remove.
So for example, at the time of this post my current kernel is
4.4.0-72-generic
dpkg -l | grep linux-image
If you want to see what kernels exist on your machine, use dpkg -l | grep linux-image. This will (in conjunction with uname -r) allow us to target a purge of each kernel individually, using the following command.
sudo apt-get -y purge linux-image-?.?.?-??-generic
Obviously replace ?.?.?-?? with the version you wish to remove. This will then remove that specific package.