- 7 Simple Ways to Free Up Space on Ubuntu and Linux Mint
- Check free space on Ubuntu
- How to free up disk space in Ubuntu and Linux Mint
- 1. Get rid of packages that are no longer required [Recommended]
- 2. Uninstall unnecessary applications [Recommended]
- 3. Clean up APT cache in Ubuntu
- 4. Clear systemd journal logs [Intermediate knowledge]
- 5. Remove older versions of Snap applications [Intermediate knowledge]
- 6. Clean the thumbnail cache [Intermediate knowledge]
- 7. Find and remove duplicate files
- 4. Remove old Linux kernels that were manually installed [For Experts]
- 5. Remove orphaned packages [For Experts]
- Bonus Tip: Using GUI tools to free space in Ubuntu
- Wrapping up
- 2 easy methods to extend/shrink resize primary partition in Linux
- Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
- Method 1: Change size of partition using parted CLI utility
- List available partitions
- Disable swap partition
- Delete swap and expand partition
- Re-create swap partition
- Method 2: Change size of partition using fdisk utility
- List available partitions
- Delete swap partition
- Part 1 — Resize root partition
- Create swap partition
- Part 2 — Resize root partition
- Related Posts
7 Simple Ways to Free Up Space on Ubuntu and Linux Mint
Last updated January 26, 2021 By Abhishek Prakash 168 Comments
Brief: Running out of space on your Linux system? Here are several ways you can clean up your system to free up space on Ubuntu and other Ubuntu based Linux distributions.
Over time, any operating system can become cluttered as programs are added and removed. If you have like a TB of storage capacity, you might not bother to clean up Ubuntu to make some disk space. But if your hard disk has limited space, like I have a 128 GB SSD laptop, freeing up disk space becomes a necessity.
In this article, I’ll show you some of the easiest tricks to clean up your Ubuntu system and get more space. I’ll also share some advanced tricks so that you’ll have choice.
But before that, let’s see how to find the free space remaining on Ubuntu.
Check free space on Ubuntu
It’s always a good idea to check the free disk space in Linux first. This is rather easy on Ubuntu. Just use Disk Usage Analyzer tool. Search it in the menu and run the tool. You should see the disk space used and the free space remaining in here:
Once you know the state of free space on your disk, it’s time to clean up your system and make some more free space here.
How to free up disk space in Ubuntu and Linux Mint
There are several ways you clean up disk space in Ubuntu and other Ubuntu based system. I have discussed several command line tricks here followed by some GUI options.
While I have mentioned several ways here, if you are a beginner, avoid the ones marked as ‘expert’. Not that you cannot use them, but it’s better to avoid if you don’t know what you are doing.
I am using Ubuntu 16.04 while writing this tutorial but you can use the same steps for Ubuntu 18.04 and other Ubuntu versions, Linux Mint, elementary OS and other Ubuntu-based Linux distributions.
If you prefer videos, I have made a video to show you how to clean Ubuntu.
1. Get rid of packages that are no longer required [Recommended]
If you read the apt-get commands guide, you might have come across the apt-get command option ‘autoremove’.
This option removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If that package is removed, these automatically installed packages are useless in the system.
It also removes old Linux kernels that were installed from automatically in the system upgrade.
It’s a no-brainer command that you can run from time to time to make some free space on your Ubuntu system:
As you can see, this command is going to free up 300 Mb of free space in my system.
2. Uninstall unnecessary applications [Recommended]
We all have a few games and/or applications that we hardly use. Don’t trust me? Go and find all the installed software on your Ubuntu system.
Chances are that you have a number of apps installed that you seldom use. Maybe you installed them on the back of an awesome review, out of nosiness, or to handle a particular task.
If you need space more getting rid of the unused or lesser used applications is always a good idea.
You can remove a program in Ubuntu from the software centre or using the command below with particular app name:
3. Clean up APT cache in Ubuntu
Ubuntu uses APT (Advanced Package Tool) for installing, removing and managing software on the system, and in doing so it keeps a cache of previously downloaded and installed packages even after they’ve been uninstalled.
The APT package management system keeps a cache of DEB packages in /var/cache/apt/archives. Over time, this cache can grow quite large and hold a lot of packages you don’t need.
You can see the size of this cache with the du command below:
As you can see, I have over 500 Mb of cache storage. When you are almost out of space, this 500 Mb can make a lot of difference.
Either remove only the outdated packages, like those superseded by a recent update, making them completely unnecessary.
Or delete apt cache in its entirety (frees more disk space):
4. Clear systemd journal logs [Intermediate knowledge]
Every Linux distribution has a logging mechanism that help you investigate what’s going on your system. You’ll have kernel logging data, system log messages, standard output and errors for various services in Ubuntu.
The problem is that over the time, these logs take a considerable amount of disk space. You can check the log size with this command:
Now, there are ways to clean systemd journal logs. The easiest for you is to clear the logs that are older than a certain days.
Here’s an example:
5. Remove older versions of Snap applications [Intermediate knowledge]
You probably already know that Snap packages are bigger in size. On top of that, Snap stores at least two older versions of the application (in case, you want to go back to the older version). This eats up huge chunk of space. In my case, it was over 5 GB.
Alan Pope, part of Snapcraft team at Canonical, has created a small script that you can use and run to clean all the older versions of your snap apps.
What you have to do here is to create a new shell script and use the following lines in your script:
Give it execute permission, run the shell script with sudo and see the magic. The script removed the older Snap packages and freed over half of the 5 GB space used by Snap.
6. Clean the thumbnail cache [Intermediate knowledge]
Ubuntu automatically creates a thumbnail, for viewing in the file manager. It stores those thumbnails in a hidden directory in your user account at the location
Over time, the number of thumbnails would increase dramatically. Moreover, the thumbnail cache will eventually contain many superfluous thumbnails of pictures that don’t exist anymore.
You can check the size of thumbnail cache with the command below:
For my system, the thumbnail cache is over 300 Mb in size.
So it’s a good practice to clear the thumbnail cache every few months or so. The quickest way is to use the terminal (please copy paste the commands to avoid mistakes):
7. Find and remove duplicate files
Sometimes you may have duplicate files in different places in your system. Getting rid of the duplicates will certainly free up some space and clean your Ubuntu system.
You can use a GUI tool like FSlint or a command line tool like FDUPES for this task. I recommend reading this article to see how to use these tools to remove duplicate files.
4. Remove old Linux kernels that were manually installed [For Experts]
The command discussed in the point 1 removes old Linux kernel. But it won’t work if you manually installed the kernel in Ubuntu. But removing old, unused Linux kernels will still save you plenty of space.
So, if you manually installed a Linux kernel, perhaps you can manually uninstall it as well.
List all installed Linux kernels first:
Removing the old kernels is the same as removing any other package. I’m using shell expansion for the version numbers to save typing. It will prompt you with a list of packages that will be removed, so you can double check the list before continuing.
Note: Replace VERSION with the version of the kernel you want to remove.
My recommendation is to keep at least two or preferably three kernels including the latest. This way, you will have at least one/two other kernels to boot with, if for whatever reason the latest kernel you are unable to boot with.
5. Remove orphaned packages [For Experts]
This step is best avoided if you are a beginner. I am not a fan of this method and I advise you to avoid it.
First, let’s see what is an orphaned package in Ubuntu.
Suppose you installed a package ‘myprogram’. But this package has a dependency on the library ‘mylib’. This lib will be usually installed automatically with ‘myprogram’. When you delete ‘myprogram’, mylib might still remain in the system. Thus mylib, in this case, becomes an orphaned package.
Now, the command listed in point 1 removes such orphaned packages. But imagine the case where you had manually installed mylib before installing myprogram. The command ‘apt autoremove’ might not remove the orphaned package in this case. And hence you’ll have to manually delete it.
You’ll have to find all the orphaned packages first and then remove them. Thankfully, we have a GUI tool to do that: gtkorphan, a graphical frontend for deborphan.
Install gtkorphan via the terminal:
And to remove orphaned packages, search for Removed Orphaned Package tool and run it to find all the orphaned packages in your system:
Honestly, I won’t go for this option unless you really need every Mb of free space.
Bonus Tip: Using GUI tools to free space in Ubuntu
We saw a number of command line options to make space in Linux system but I understand if you don’t want to use the commands.
Remembering all the commands or using them all one by one may not be convenient for you. And this is why we have a number of GUI tools that will help you do that in a few clicks with an easy to use interface.
Stacer is one such tool that you could use. You can read this article to know how to use Stacer in Ubuntu.
You can check out more tools to clean up Ubuntu and make some free space easily.
Wrapping up
So, you saw a number of ways to clean up Ubuntu system. Personally, I use apt-get autoremove more often than any other commands here. Regularly using this command keeps the system free from unnecessary files.
I hope this article helped you to make free space in Ubuntu, Linux Mint and other such distributions. Do let me know if this worked for you or if you have some other tip to share.
Like what you read? Please share it with others.
Источник
2 easy methods to extend/shrink resize primary partition in Linux
Table of Contents
Related Searches: How to resize primary partition in Linux. How to extend non lvm root partition. How to change size of partition in Linux using parted and fdisk without destroying data. Steps to expand partition in RHEL/CentOS 7 and 8 Linux. Perform Disk Management in CentOS. How to use unallocated space to change size of partition in a disk in Linux. How to resize root partition not on LVM in Linux. Step by step guide to resize primary partition. How to expand partition with examples in Linux. centos disk management. rhel 7 extend non lvm root partition. centos 7 resize root partition. Steps to resize primary partition to extend non lvm root partition in linux. how to add unallocated disk space to a partition in Linux. centos shrink or extend non lvm root partition. add space to partition. fdisk extend partition. resize boot partition. extend non lvm root partition in linux. change size of partition.how to expand partition. centos resize primary partition. rhel change size of partition.
Earlier I had shared steps to create a file system and check file system type in Linux . Now in this article I will share the steps to resize primary partition, here we will extend non lvm root partition. With LVM it is far more easier and less riskier to change size of partition in an volume group in Linux .
- This article covers steps to resize primary partition (non-lvm) which can be dangerous and can leave your Linux system in an unusable broken state. It is important that you backup your content before you attempt to change size of partition.
- You can change size of partition (non-lvm) only on the last partition on the storage device with unallocated space. If the respective partition is not the last partition then the only way to expand partition is to backup your data , rebuild the disk and partitions, then restore the data. No tool such as gparted, parted or fdisk can help you change size of partition in such case.
- You must have some unallocated space or free space available in the concerned device to be able to expand partition. In some of the virtual environment you have an option to change the storage device size but on physical node if there is no enough unallocated space then resize primary partition (extend non lvm root partition) is not possible
- This article assumes you’re using either a GPT partition table, or an msdos partition table using primary partition types to extend non lvm root partition.
Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
I have performed resize primary partition operation on Virtual Machine running on Oracle VirtualBox installed on Linux server . My VM is running with CentOS 8 but I have also verified these steps on RHEL/CentOS 7 and RHEL 8 Linux.
Here my VM is installed on /dev/sda device where /dev/sda1 is boot partition, /dev/sda2 is root while /dev/sda3 is for swap.. Additionally I have left some unallocated free space in /dev/sda for the demonstration of this article to extend non lvm root partition.
Method 1: Change size of partition using parted CLI utility
You can either use gparted (GUI utility) or parted (CLI utility) to change size of partition in Linux. Here we plan to resize primary partition which in our case is /dev/sda.
List available partitions
To list the available partitions in /dev/sda we will execute below command
As I mentioned in the disclaimer section, you can change size of partition only on the last partition of the device but here root partition ( /dev/sda2 ) is not the last one instead swap ( /dev/sda3 ) is my last partition. So to expand root partition I must delete swap device to be able to to use unallocated space and extend non lvm root partition. After deleting swap, root partition will become the last partition on /dev/sda after which we can resize primary partition.
Disable swap partition
Currently I have around 1GB reserved for swap partition
I will turn off my swap (disable swap partition) and use this space to extend non lvm root partition in Linux
Verify the swap partition space, as you see not it is 0
Update /etc/fstab to make sure swap partition is not mounted at boot up stage.
Delete swap and expand partition
Now to resize primary partition /dev/sda2 and expand partition to a new value we must first delete swap partition using parted utility. As we need root partition to be the last partition of /dev/sda before we expand partition.
But our root partition is showing the same size as earlier i.e.
To complete the steps to resize non lvm root partition, execute resizefs to expand partition and refresh the changes
Re-verify the new size of root partition to make sure our steps to extend non lvm root partition was successful.
Re-create swap partition
Now we must create Swap partition which we deleted earlier in this article. We will again use parted utility to create swap partition
Now with parted we only created a partition with file system type as swap. Use mkswap to turn this partition into swap.
Next we must update /etc/fstab with the UUID of our new swap partition. To get the new UUID of swap partition
Update this UUID in /etc/fstab as shown below
Finally turn on the new swap partition
Verify the new swap partition
Now you can reboot your Linux server to make sure everything is OK and resize primary partition was successful.
Method 2: Change size of partition using fdisk utility
Similar to parted command, you can also use fdisk utility to resize primary partition and extend non lvm root partition.
List available partitions
Before we resize primary partition, let us list the available partitions
Now as you see my existing root partition /dev/sda2 size is
10G . Here we will expand partition with +1GB using unallocated disk space from /dev/sda .
Delete swap partition
Currently my swap partition is enabled and is the last partition of /dev/sda . So we must first delete swap partition here before we change size of partition as we need root to be the last partition in /dev/sda
So we will turn off the swap partition before we disable it
Now it is time to use fdisk utility to resize partition
Part 1 — Resize root partition
We will continue with the steps to extend non lvm root partition in the same fdisk session. Note down the start sector of the root partition before you expand partition.
Create swap partition
After we resize primary partition, in the same fdisk session we will also create a new swap partition which we had deleted initially with new start and end sector
Update the kernel regarding the recent changes we did to change size of partition
But our swap partition is still shown as 0
Now let us complete our steps to create swap partition using mkswap
Next update /etc/fstab with the UUID for your new swap partition. You can use blkid to get the UUID
Update the same in /etc/fstab as shown below
Now you can turn on the swap partition
Verify the same using free command
Part 2 — Resize root partition
If not done already in above steps, once you exit fdisk utility, update the kernel regarding the recent changes we did to change size of partition
We are not done with resize primary partition, as df command still shows old partition size for root partition
Execute resize2fs to expand partition on /dev/sda2 with the new changes
Now you can verify the new size of root partition
Lastly I hope the steps from the article to resize primary partition and extend non lvm root partition on RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
Источник