How to cleanup your /boot in Ubuntu

First check your kernel version, so you won’t delete the in-use kernel image, running:

uname -a

Now run this command for a list of installed kernels:

sudo dpkg --list 'linux-image*'

and delete the kernels you don’t want/need anymore by running this:

sudo apt-get remove linux-image-VERSION linux-image-VERSION

Replace VERSION with the version of the kernel you want to remove.

When you’re done removing the older kernels, you can run this to remove ever packages you won’t need anymore:

sudo apt-get autoremove

And finally you can run this to update grub kernel list:

sudo update-grub

Ubuntu set local hostname via DHCP

Sometime for automation you need to be able to set the ubuntu hostname at  boot ( or at network restart ) via DHCP / DNS .

To be able to do that you only have to add in /etc/dhcp/dhclient-exit-hooks.d a file named hostname with the following content:

 

if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
&& [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
then
return
fi

host=$(host $new_ip_address | cut -d ' ' -f 5)
host=${hostname:0:-1}
echo $host > /etc/hostname
hostname $host

What it does ? Simple it hooks dhcpclient and after the client receives the new ip from dhcp it will make a simple reverse lookup for the ip received
and will set the hostname accordingly.