11

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!

  • I have heard it's better to keep a longer age for files in /var/tmp than in /tmp. lsof doesn't show any process is using those files. But there are a bunch of warnings in the tmpreaper app's manual when I tried to set it up to automatically delete those files, that is where I got scared away. So, you think deleting those files 7days after the last access is safe? – Xiaodong Qi Apr 19 '17 at 5:37
  • I have noticed that bug on my searching. Firstly, those files were generated not because of any kernel installation failure. Secondly, the bug was said being fixed. Is there any way to verify if they are not linked to any other files? – Xiaodong Qi Apr 19 '17 at 7:28
  • I've converted my previous comments to a proper answer. I'm going to clean them up now. – Andrea Lazzarotto Apr 26 '17 at 23:23
16

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

  • Thank you for writing this answer. After understanding the tmp files, I used tmpreaper (see my notes for details) to automatically clean up those files older than 30 days and saved me 7GB of space. That is very helpful! – Xiaodong Qi Apr 26 '17 at 23:59
  • Update my notes' link. – Xiaodong Qi Jun 20 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.