7

I run high sierra, and the large private/var/vm/sleepimage file has been bothering me. My computer has 16 GB of ram, which means sleepimage takes up 16 GB on my drive. I have read tutorials on how to remove it, but it does not work for me. I tried typing sudo rm -R private/var/vm/sleepimage in the terminal, but the terminal responds rm: private/var/vm/sleepimage: No such file or directory. What do I do?

1
  • 1
    private/var/vm/sleepimage is the same directory as ./private/var/vm/sleepimage, which points to a subdirectory under your current directory, but you are trying to delete a file/folder under /. If you don’t cd /, this command won’t work. Or you can just add a / before the path: /private/var/vm/sleepimage – user255044 Jun 1 '18 at 5:21
8

That file can be deleted - no need for -R but be sure to have the full path:

 sudo rm /private/var/vm/sleepimage

One you "delete it", the space will not be freed until the kernel and other processes close the file, so restart your Mac. The image file will be recreated next time you need to sleep - so if you had a HDD with that file contiguously allocated, you will make things worse when it's allocated non-contiguous blocks. SSD won't care either way.

I would focus on cleaning / relocating other files long term than this one.

1
  • 2
    $sudo rm /private/var/vm/sleepimage override rw------T root/wheel for /private/var/vm/sleepimage? y rm: /private/var/vm/sleepimage: Operation not permitted in Mojave – iggy Sep 27 '19 at 3:56
4

Info in this answer has been extracted from this page.

The sleepimage file is protected by SIP, which needs to be disabled before deletion. Additionally, you need to turn off the mechanism which creates the sleepimage file to keep it from creating the file in the future.

Turn off hibernate mode (which may be reset during future system upgrades/updates:)

sudo pmset -a hibernatemode 0

Restart your machine and hold down Cmd-R to boot into recovery mode. When that loads, go to Utilities > Terminal, and enter the following to disable SIP:

csrutil disable
reboot

When your machine starts back up, go into terminal and remove the sleepimage. This time, it’ll work. You’ll also need to create a blank sleepimage file and make it unwritable, otherwise the full file will come back fairly quickly.

sudo rm -f /private/var/vm/sleepimage
sudo touch /private/var/vm/sleepimage
sudo chflags uchg /private/var/vm/sleepimage

Now boot back into recovery mode and re-enable SIP:

<s>csrutil enable</s>
reboot

When you’re back into MacOS, go into terminal one final time, and verify that the sleepimage has a size of 0 bytes:

ls -la /private/var/vm
2
  • On 10.13.4 and lower, this is not required - the sleep image file is not protected by SIP. $ ls -lO /private/var/vm/sleepimage -rw------T 1 root wheel - 1073741824 May 26 19:29 /private/var/vm/sleepimage There's a lot of amazing good info here and the potential to try and change permissions on this file, but I can delete it anytime as normal admin / sudo with SIP fully enabled across many installs of High Sierra – bmike Jun 1 '18 at 22:37
  • What happens once you’ve got the user immutable flag set on 10.13 for the sleep image file and another script overrides the power management settings? +1 for keeping this updated! – bmike Aug 7 '18 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .