Navid Malekghaini's Personal Blog

My personal weblog for sharing and storing some of my activities related to computer science over the internet

Navid Malekghaini's Personal Blog

My personal weblog for sharing and storing some of my activities related to computer science over the internet

Navid Malekghaini's Personal Blog

Navid Malekghaini

Senior Software Engineer @ Intelligent Cloud Infrastructure Laboratory
Prev. Research Engineer @ University of Waterloo x Orange Telecom

University of Waterloo
Department of computer science
200 University Ave W, Waterloo, ON N2L 3G1, Canada
cs.uwaterloo.ca

contact me
navidmalekedu (AT) gmail (DOT) com [ Primary Email ]
nmalekgh (AT) uwaterloo (DOT) ca

۱ مطلب در می ۲۰۲۴ ثبت شده است

As a seasoned Linux user with a decade of experience, I’ve encountered my fair share of disk space issues on the root filesystem (“/”). In this blog post, I’ll share practical tips to tackle this problem and keep your system running smoothly. Feel free to bookmark this for future reference!

1. Avoid Rebooting

If you notice that your root filesystem is running out of space, avoid shutting down or restarting the system. Restarting can complicate matters further. Instead, follow these steps:

2. Apt Cleanup

  • Run automated cleanup commands:
    sudo apt autoremove  # Removes old packages (especially older kernel images/modules)
    sudo apt clean       # Clears the cache of apt
    
  • Identify and remove large packages using the following command and remove them if not needed:
    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}'
    

3. Clear Snap Packages

  • Clear the snap package cache:
    sudo sh -c 'rm -rf /var/lib/snapd/cache/*'
    
  • Remove disabled snap packages:
    set -eu
    snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
      snap remove "$snapname" --revision="$revision"
    done
    

4. Clean Logs

  • Remove old logs to free up space:
    journalctl --vacuum-time=10d
    

5. Docker Cleanup (if applicable)

  • List big Docker images and containers:
    docker ps -a
    docker images
    
  • Release unused space:
    docker system prune -a --volumes
    
  • Consider moving Docker to a different location (e.g., /home) instead of the root (“/”).

6. Inspect Directories

  • Manually check the size of different directories in the root (“/”) and dig into the root cause:
    du -hs /* | sort -h
    

7. Repartition if Necessary

  • If all else fails, consider repartitioning the root directory (“/”) to reclaim space from other partitions (e.g., “/home”). You can do this at runtime.

Remember, regular maintenance and monitoring disk space can prevent headaches down the road!

موافقین ۰ مخالفین ۰ 11 May 24 ، 01:40