Why was my Linux VM's disk always full?
Some of my VMs had been getting less and less space disk, and I thought it was because of the log files. Even after deleting them, I'd end up recovering less and less space.
So I tried finding the largest files. A quick search on Google returns this:
# du -a [thefolder] | sort -n -r | head -n 20
# du -a / | sort -n -r | head -n 20
So I used it on the root. It returned /usr. So I ran it again in there, and got this:
# du -a /usr | sort -n -r | head -n 20
8094088 /usr
6795852 /usr/src
848520 /usr/lib
306856 /usr/lib/node_modules
281640 /usr/share
240984 /usr/lib/node_modules/polymer-cli
239780 /usr/lib/node_modules/polymer-cli/node_modules
133376 /usr/bin
122936 /usr/lib/x86_64-linux-gnu
114552 /usr/lib/go-1.8
108480 /usr/src/linux-headers-4.4.0-190
108476 /usr/src/linux-headers-4.4.0-189
108476 /usr/src/linux-headers-4.4.0-187
108476 /usr/src/linux-headers-4.4.0-186
108468 /usr/src/linux-headers-4.4.0-185
108468 /usr/src/linux-headers-4.4.0-176
108464 /usr/src/linux-headers-4.4.0-179
108464 /usr/src/linux-headers-4.4.0-177
108464 /usr/src/linux-headers-4.4.0-174
108460 /usr/src/linux-headers-4.4.0-184
It looked like some old versions of some package. Can I remove them safely? How? On https://www.pontikis.net/blog/remove-old-kernels-debian-ubuntu, they say I shoud use apt autoremove
. And it worked!
# apt auto-remove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-headers-4.4.0-101 linux-headers-4.4.0-101-generic linux-headers-4.4.0-103
linux-headers-4.4.0-103-generic linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic
linux-headers-4.4.0-109 linux-headers-4.4.0-109-generic linux-headers-4.4.0-112
linux-headers-4.4.0-112-generic linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic
linux-headers-4.4.0-119 linux-headers-4.4.0-119-generic linux-headers-4.4.0-121
linux-headers-4.4.0-121-generic linux-headers-4.4.0-124 linux-headers-4.4.0-124-generic
linux-headers-4.4.0-127 linux-headers-4.4.0-127-generic linux-headers-4.4.0-128
linux-headers-4.4.0-128-generic linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic
linux-headers-4.4.0-133 linux-headers-4.4.0-133-generic linux-headers-4.4.0-134
linux-headers-4.4.0-134-generic linux-headers-4.4.0-137 linux-headers-4.4.0-137-generic
linux-headers-4.4.0-138 linux-headers-4.4.0-138-generic linux-headers-4.4.0-139
linux-headers-4.4.0-139-generic linux-headers-4.4.0-141 linux-headers-4.4.0-141-generic
linux-headers-4.4.0-142 linux-headers-4.4.0-142-generic linux-headers-4.4.0-143
linux-headers-4.4.0-143-generic linux-headers-4.4.0-145 linux-headers-4.4.0-145-generic
linux-headers-4.4.0-148 linux-headers-4.4.0-148-generic linux-headers-4.4.0-150
linux-headers-4.4.0-150-generic linux-headers-4.4.0-151 linux-headers-4.4.0-151-generic
linux-headers-4.4.0-154 linux-headers-4.4.0-154-generic linux-headers-4.4.0-157
linux-headers-4.4.0-157-generic linux-headers-4.4.0-159 linux-headers-4.4.0-159-generic
linux-headers-4.4.0-161 linux-headers-4.4.0-161-generic linux-headers-4.4.0-164
linux-headers-4.4.0-164-generic linux-headers-4.4.0-165 linux-headers-4.4.0-165-generic
linux-headers-4.4.0-166 linux-headers-4.4.0-166-generic linux-headers-4.4.0-169
linux-headers-4.4.0-169-generic linux-headers-4.4.0-170 linux-headers-4.4.0-170-generic
linux-headers-4.4.0-171 linux-headers-4.4.0-171-generic linux-headers-4.4.0-173
linux-headers-4.4.0-173-generic linux-headers-4.4.0-174 linux-headers-4.4.0-174-generic
linux-headers-4.4.0-176 linux-headers-4.4.0-176-generic linux-headers-4.4.0-177
linux-headers-4.4.0-177-generic linux-headers-4.4.0-178 linux-headers-4.4.0-178-generic
linux-headers-4.4.0-179 linux-headers-4.4.0-179-generic linux-headers-4.4.0-184
linux-headers-4.4.0-184-generic linux-headers-4.4.0-185 linux-headers-4.4.0-185-generic
linux-headers-4.4.0-186 linux-headers-4.4.0-186-generic linux-headers-4.4.0-187
linux-headers-4.4.0-187-generic linux-headers-4.4.0-83 linux-headers-4.4.0-83-generic linux-headers-4.4.0-87
linux-headers-4.4.0-87-generic linux-headers-4.4.0-89 linux-headers-4.4.0-89-generic linux-headers-4.4.0-91
linux-headers-4.4.0-91-generic linux-headers-4.4.0-92 linux-headers-4.4.0-92-generic linux-headers-4.4.0-93
linux-headers-4.4.0-93-generic linux-headers-4.4.0-96 linux-headers-4.4.0-96-generic linux-headers-4.4.0-97
linux-headers-4.4.0-97-generic linux-headers-4.4.0-98 linux-headers-4.4.0-98-generic
linux-image-4.4.0-101-generic linux-image-4.4.0-103-generic linux-image-4.4.0-104-generic
linux-image-4.4.0-109-generic linux-image-4.4.0-112-generic linux-image-4.4.0-116-generic
linux-image-4.4.0-119-generic linux-image-4.4.0-121-generic linux-image-4.4.0-124-generic
linux-image-4.4.0-127-generic linux-image-4.4.0-128-generic linux-image-4.4.0-130-generic
linux-image-4.4.0-133-generic linux-image-4.4.0-134-generic linux-image-4.4.0-137-generic
linux-image-4.4.0-138-generic linux-image-4.4.0-139-generic linux-image-4.4.0-141-generic
linux-image-4.4.0-142-generic linux-image-4.4.0-143-generic linux-image-4.4.0-145-generic
linux-image-4.4.0-148-generic linux-image-4.4.0-150-generic linux-image-4.4.0-151-generic
linux-image-4.4.0-154-generic linux-image-4.4.0-157-generic linux-image-4.4.0-159-generic
linux-image-4.4.0-161-generic linux-image-4.4.0-164-generic linux-image-4.4.0-165-generic
linux-image-4.4.0-166-generic linux-image-4.4.0-169-generic linux-image-4.4.0-170-generic
linux-image-4.4.0-171-generic linux-image-4.4.0-173-generic linux-image-4.4.0-174-generic
linux-image-4.4.0-176-generic linux-image-4.4.0-177-generic linux-image-4.4.0-178-generic
linux-image-4.4.0-179-generic linux-image-4.4.0-184-generic linux-image-4.4.0-185-generic
linux-image-4.4.0-186-generic linux-image-4.4.0-187-generic linux-image-4.4.0-83-generic
linux-image-4.4.0-87-generic linux-image-4.4.0-89-generic linux-image-4.4.0-91-generic
linux-image-4.4.0-92-generic linux-image-4.4.0-93-generic linux-image-4.4.0-96-generic
linux-image-4.4.0-97-generic linux-image-4.4.0-98-generic linux-modules-4.4.0-143-generic
linux-modules-4.4.0-145-generic linux-modules-4.4.0-148-generic linux-modules-4.4.0-150-generic
linux-modules-4.4.0-151-generic linux-modules-4.4.0-154-generic linux-modules-4.4.0-157-generic
linux-modules-4.4.0-159-generic linux-modules-4.4.0-161-generic linux-modules-4.4.0-164-generic
linux-modules-4.4.0-165-generic linux-modules-4.4.0-166-generic linux-modules-4.4.0-169-generic
linux-modules-4.4.0-170-generic linux-modules-4.4.0-171-generic linux-modules-4.4.0-173-generic
linux-modules-4.4.0-174-generic linux-modules-4.4.0-176-generic linux-modules-4.4.0-177-generic
linux-modules-4.4.0-178-generic linux-modules-4.4.0-179-generic linux-modules-4.4.0-184-generic
linux-modules-4.4.0-185-generic linux-modules-4.4.0-186-generic linux-modules-4.4.0-187-generic python-acme
python-certbot python-certbot-nginx python-cffi-backend python-chardet python-configargparse python-configobj
python-cryptography python-dialog python-dnspython python-enum34 python-funcsigs python-idna python-ipaddress
python-mock python-ndg-httpsclient python-openssl python-parsedatetime python-pbr python-pkg-resources
python-psutil python-pyasn1 python-pyicu python-pyparsing python-requests python-rfc3339 python-setuptools
python-six python-tz python-urllib3 python-zope.component python-zope.event python-zope.hookable
python-zope.interface
0 upgraded, 0 newly installed, 218 to remove and 104 not upgraded.
1 not fully installed or removed.
After this operation, 7,737 MB disk space will be freed.
Do you want to continue? [Y/n]
It took much longer than I thought to remove those, and it would often freeze for minutes while showing this:
Replacing config file /run/grub/menu.lst with new version
After 30 minutes, the command completed, and I recovered those 7 GB. Yay!