Can I delete /var/tmp/mkinitramfs-* files?

I notice that my /var/tmp folder has occupied by 9.3GB space on my Ubuntu 16.04.2. Particularly, there are a bunch of mkinitramfs_* folders taken most of the space in the tmp folder. I looked into them, and they seem to be the temporary files for linux kernels compiled recently and in the past. Can I delete them safely, or they are linked to other important files?

I have tried using tmpreaper app to automate the temporary file cleaning process on reboots. But I find I can only put both /tmp/ and /var/tmp/ folders together into the auto-clean settings and only set up one max file age to remove old files. This may make it hard to set up the max file age parameter TMPREAPER_TIME properly. If I set it too short (by default, 7 days), I might delete those recent kernel compiling files in mkinitramfs_* folders which might be useful. If I set it too long, I may end up with a lot of files in /tmp. I hope you can point out to me some references on the role of those mkinitramfs_* folders and how to use tmpreaper app or other tools to automatically delete old temporary files.

Thanks!


Generally, you can delete any file in /tmp and /var/tmp without breaking the system. The worst case scenario is that it's a file needed by an open app, but that doesn't seem to be the case.

Regarding those files related to mkinitramfs, I would say that it's safe to prune them. See also this Debian bug: #818345 - tmp file is left under /var/tmp if mkinitramfs fails. Basically those files should be purged after the process that created them is over, but for some reason they are not.

I am not sure if you are affected by that bug specifically, but the point is that those files are needed by mkinitramfs while the process is ongoing. After the process is over, you don't need them anymore. Also, as usual with temporary files, they will be recreated in subsequent runs of the same process if necessary.

I hope you can point out to me some references on the role of those mkinitramfs_* folders and how to use tmpreaper app or other tools to automatically delete old temporary files.

I don't have experience with tmpreaper, but you could use a cron job to delete those files periodically. See:

Auto delete files older than 7 days