Remove Unused Kernels

🔍 Step 1: Check What’s Using Space

Run this in your terminal:

sudo du -h --max-depth=1 / | sort -hr | head -n 10

This shows the largest directories in root. Investigate the biggest ones (like /var, /usr, /home, etc.).


🧹 Step 2: Clean Package Cache

sudo apt clean

This removes cached .deb files in /var/cache/apt/archives, which can take up a lot of space.


🧹 Step 3: Remove Unused Kernels

Check your current kernel:

uname -r

List installed kernels:

dpkg --list | grep linux-image

Remove old kernels (except the current one):

sudo apt remove --purge linux-image-X.X.X-XX-generic
# sudo apt remove --purge linux-image-6.1.0-33-amd64
# sudo apt purge linux-image-6.1.0-32-amd64

Be very careful not to remove the current or only working kernel.


🧹 Step 4: Remove Orphaned Packages

sudo apt autoremove

This removes packages installed as dependencies but no longer needed.


🧹 Step 5: Clean Journal Logs (if using systemd)

sudo journalctl --vacuum-time=3d

This deletes logs older than 3 days (adjust as needed).


🧼 Step 6: Identify & Delete Large Files

Find files larger than 100MB:

sudo find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k 5 -rh | head -n 20

Check if any are safe to delete (e.g., large ISO files, crash dumps, logs, etc.).


🧭 Optional: Move Files Off Root

If /home or an external drive has space:

sudo mv /path/to/large/file /home/youruser/

Or compress rarely used files:

gzip /path/to/large/file

🚨 Reboot After Cleaning

Once you’ve freed a few GB, reboot to ensure system services restart normally:

sudo reboot

After you’ve removed the old kernels and run sudo apt autoremove, you can check how much space is now free on your root partition with:

df -h /

This will output something like:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        20G   18G  1.5G  93% /

Look at the “Avail” column — it shows how much space is now free on your / partition.