Linux Low Disk Space On Root? One way to clean up space if you use Flatpak.
By: Roger Creasy
The dreaded 'Low Disk space on /'. You may think to yourself, "But, I have plenty of space on my hard drive. How can space on root be low?" An online search will give numerous things to try - cleaning your package manager cache, removing all but recent kernel images, etc. All of these things help, and may solve the issue. But, Flatpak stores its data in /var/lib/Flatpak, which is part of root. If you use Flatpak, there is a simple fix that can save gigs of space. Keep reading to learn how to implement this fix.
The typical linux install creates separate partitions for the /home directory and the / (root) directory. Usually the root directory partition is created with a relatively small amount of space. From the command line run:
You should see something like:
Explaining all of the above is beyond the scope of this article. Briefly. the
lsblk command lists block storage devices. The results above are from my laptop. 'sdb' is one of my drives. Below 'sdb' are the partitions for that drive. Look at the far right column, specifically '/', and '/home'. To the left of each of those you see 'lvm', meaning 'logical volume'. Two columns further left, you see the size of those volumes. In the example above '/' is 50G (rather large), and '/home' is 174G. '[SWAP]' is also using some of the available space. '[SWAP]' is a topic for another article.
If your setup is similar to the above, the 'Low Disk Space on /' warning means there is low disk space on that one logical volume.
An inspection of your space used will likely show that the space hog is /var/lib/flatpak. In my case that directory was nearly 30G! To check space, cd to root, then run
sudo du -cks * |sort -rn |head -11 On a large drive, this command could take several minutes to run. This command looks at space used, sorts descending, then shows the top 10. To find the space hogs, you'll have to drill down. i.e. run the command on '/', then cd to the top space user, likely /var. Then cd to the top space user there and run the command again. By going through this process I found that /var/lib/flatpak was the culprit.
tldr; The Solution
What I did was move /var/lib/flatpak to a different drive, where there is space. But, if you don't have an additional drive, you can move it to your /home directory. After moving the flatpak directory, I created a symlink at its original location. THe steps and commands are below.
- Create a folder to house system files in your /home directory
- Move the flatpak directory into the directory created above
sudo mv -r /var/lib/flatpak ~/system/
- Create the symbolic link at the original flatpak location
sudo ln -s /home/[your username]/system/flatpak /var/lib/flatpak
- Test that a couple of Flatpak apps are still opening Okay.
If you are fearful of losing files, like I am, you may want to make a copy of the flatpak directory before moving it. If so, add a step 1.5 to the above -
cp -R /var/lib/flatpak/temp /var/lib/temp And, add a step 5 - If Flatpak apps are opening OK,
sudo rm -rf /var/lib/temp
That's it! I hope you find this information helpful. If you do, please share!