Software & AppsOperating SystemLinux

How To Free Up Disk Space in Ubuntu’s Root Drive

Ubuntu 13

Running out of disk space on your root drive can be a common issue for Ubuntu users. This article will guide you through several methods to free up disk space on your Ubuntu’s root drive.

Quick Answer

To free up disk space in Ubuntu’s root drive, you can clean up the apt-get cache, move the /home mount point to a separate drive, remove old kernel versions, clean up large files, check for large packages, and clean up Docker images and volumes.

Clean up the apt-get cache

The Advanced Package Tool (APT) maintains a cache of deb files, which are essentially downloaded package files. Over time, this cache can grow and consume a significant amount of disk space. You can clean up this cache by running the following command in your terminal:

sudo apt-get clean

This command will remove all downloaded deb files from the apt-get cache directory, freeing up space on your root drive.

Move the /home mount point

The /home directory is where user files are typically stored. If this directory is on your root drive, it could be taking up a lot of space. Consider moving it to a separate drive. This guide on how to move the home folder to a separate drive can help you with the process.

Increase the size of the root partition

If you have additional disk space available on your system, you can resize the root partition to increase its size. This can be done using disk management tools like GParted. However, this solution may not be feasible if you are running low on disk space overall.

Remove old kernel versions

Old kernel versions can take up a significant amount of space on the root drive. You can remove them to free up space. Be cautious not to remove the currently installed kernel. You can find the installed kernels by running:

dpkg --list | grep linux-image

This command will list all the installed kernels. To remove an old kernel, use the command:

sudo apt-get purge linux-image-x.x.x.x-generic

Replace x.x.x.x with the version number of the kernel you want to remove.

Clean up large files

You can use the find command to locate large files on your system. For example, running:

sudo find / -type f -size +50M -exec du -h {} \; | sort -n

This command will find files larger than 50MB and sort them by size. You can then decide which files to delete or move to another location.

Check for large packages

You can use the dpkg-query command to find the largest packages installed on your system. Running:

dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}'

This command will list the packages and their sizes. You can then decide which packages to remove using sudo apt-get purge package_name.

Clean up Docker images and volumes

If you use Docker, removing unused images and volumes can free up a significant amount of space. You can use commands like docker system prune to remove dangling images or docker system prune -af --volumes to perform a deep clean.

In conclusion, regularly monitoring disk usage and cleaning up unnecessary files can prevent future space issues. Be cautious when deleting files or removing packages to avoid any unintended consequences.

How do I check the available disk space on my Ubuntu system?

You can check the available disk space on your Ubuntu system by using the df command in the terminal. Simply run df -h to see the disk space in a human-readable format.

Can I delete all files in the apt-get cache directory?

Yes, you can safely delete all files in the apt-get cache directory by running the command sudo apt-get clean. This will remove all downloaded deb files, but it won’t affect the functionality of your system. The next time you install or update packages, the cache will be rebuilt.

How can I move the `/home` directory to a separate drive?

Moving the /home directory to a separate drive requires some advanced steps. You can refer to the guide on how to move the home folder to a separate drive for detailed instructions.

Is it safe to remove old kernel versions?

Yes, it is generally safe to remove old kernel versions as long as you do not remove the currently installed kernel. It is recommended to keep at least one previous kernel version as a backup. You can use the command dpkg --list | grep linux-image to list all installed kernels and sudo apt-get purge linux-image-x.x.x.x-generic to remove an old kernel.

How can I find large files on my Ubuntu system?

You can use the find command to locate large files on your Ubuntu system. For example, running sudo find / -type f -size +50M -exec du -h {} \; | sort -n will find files larger than 50MB and sort them by size. You can then decide which files to delete or move to another location.

How do I check the size of installed packages on my Ubuntu system?

You can use the dpkg-query command to find the size of installed packages on your Ubuntu system. Running dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}' will list the packages and their sizes.

How can I clean up Docker images and volumes?

To clean up Docker images, you can use the command docker system prune, which will remove dangling images. To perform a deep clean and remove unused images and volumes, you can use docker system prune -af --volumes. Be cautious when using these commands as they will permanently delete the specified Docker resources.

Leave a Comment

Your email address will not be published. Required fields are marked *