Managing disk space on a Manjaro Linux system with a separate root partition can be challenging, especially when root space fills up unexpectedly. Here are practical housekeeping tips to help you manage your system efficiently, minimize disk space usage, and ensure optimal performance.
1. Analyze Disk Usage
The first step to effective housekeeping is understanding what consumes space on your root partition. Use the following command to analyze disk usage:
sudo du -xhd1 / | sort -h
This will display the sizes of top-level directories, helping you identify the biggest space hogs. Focus on directories like /var
, /usr
, and /opt
.
2. Manage the Pacman Cache
Manjaro's package manager, pacman
, caches downloaded packages in /var/cache/pacman/pkg
. Over time, this directory can grow significantly.
Check Cache Size:
du -sh /var/cache/pacman/pkg
Clear the Cache:
To remove all cached packages:
sudo pacman -Scc
Alternatively, to remove only unused cached packages:
sudo pacman -Sc
Move the Cache to a Separate Partition:
If /var/cache
frequently consumes space, you can move it to your /home
partition:
Create a new directory in
/home
:mkdir -p /home/var-cache
Move existing files:
sudo rsync -a /var/cache/ /home/var-cache/
Bind the new directory:
sudo mount --bind /home/var-cache /var/cache
Make it permanent by adding this line to
/etc/fstab
:/home/var-cache /var/cache none bind 0 0
3. Control Log File Growth
System logs in /var/log
can accumulate over time. Use these commands to manage them:
Check Log Size:
sudo du -sh /var/log
Clear Old Logs:
Manually clear logs if needed:
sudo journalctl --vacuum-size=500M
Or, clear logs older than two weeks:
sudo journalctl --vacuum-time=2weeks
Relocate Logs to /home
:
If logs are a recurring issue, consider moving /var/log
to /home
:
Create a directory in
/home
:mkdir -p /home/var-log
Move existing files:
sudo rsync -a /var/log/ /home/var-log/
Bind the new directory:
sudo mount --bind /home/var-log /var/log
Add this to
/etc/fstab
:/home/var-log /var/log none bind 0 0
4. Optimize Docker Storage
If you use Docker for development, its default data directory (/var/lib/docker
) can consume significant space with images, containers, and volumes.
Check Docker Usage:
docker system df
Prune Unused Data:
Clear unused images, containers, and volumes:
docker system prune -af
Move Docker Data to /home
:
Stop Docker:
sudo systemctl stop docker
Move Docker's data directory:
sudo mv /var/lib/docker /home/docker-data
Create a symbolic link:
sudo ln -s /home/docker-data /var/lib/docker
Restart Docker:
sudo systemctl start docker
5. Manage Orphaned Packages
Orphaned packages are unused dependencies left behind after uninstalling software. Remove them to free up space:
sudo pacman -Rns $(pacman -Qdtq)
6. Timeshift Snapshots
Timeshift snapshots can consume significant space on the root partition. Regularly prune old snapshots to avoid space issues:
List Snapshots:
sudo timeshift --list
Delete Old Snapshots:
sudo timeshift --delete
Relocate Timeshift Snapshots:
By default, Timeshift stores snapshots on the root partition. If possible, configure Timeshift to store snapshots on a different partition during setup.
7. Regular Maintenance Checklist
Run updates regularly and clear the pacman cache afterward:
sudo pacman -Syu && sudo pacman -Scc
Prune Docker data:
docker system prune -af
Clear old journal logs:
sudo journalctl --vacuum-size=500M
Check disk usage periodically:
sudo du -xhd1 / | sort -h
Conclusion
By following these housekeeping tips, you can manage your Manjaro Linux system efficiently, ensuring that your root partition stays optimized and avoids unexpected space issues. While moving specific directories to your /home
partition can provide immediate relief, regular maintenance and monitoring are key to long-term stability.