Is it possible to prevent Windows from deleting hibernate file (hiberfil.sys) when shut down?

7

1

I'm trying to move the hibernate file from system partition (SSD) to some other partition (HDD).

I know a lot of people say this is impossible, but I'm not completely convinced yet.

What I'm trying to do is:

  1. Boot up from Windows 7 DVD;
  2. Copy hiberfil.sys from SSD to HDD;
  3. Delete hiberfil.sys from SSD;
  4. Create a symbolic link for hiberfil.sys on SSD;

Unfortunately, when I boot up from Windows 7 DVD, I sadly found the hiberfil.sys file was not there. I remember I have read somewhere that Windows automatically deletes the hiberfil.sys file when shut down.

Is it possible to prevent Windows from deleting hiberfil.sys file when shut down?

Thanks


Update:

It seems Windows actually doesn't delete hiberfil.sys file when shut down. It was the VMware Tools automatically disabled hibernate when shut down / start up.

user68795

Posted 2011-04-06T18:12:57.550

Reputation:

Why do you need hibernation on a SSD? It would be more cost efficient to just use sleep or shutdown instead. – Tamara Wijsman – 2011-04-06T19:23:30.537

1@Tom Wijsman: I'm using APC PowerChute. It requires hibernate be enabled, so that it can automatically puts my PC into hibernation after power cut. – None – 2011-04-06T19:38:13.750

Ah, makes sense then. Well, a power cut is most likely once a year so there is no worry... :) – Tamara Wijsman – 2011-04-06T19:43:07.220

4@TomWijsman the frequency of power outages can vary greatly depending on where you are, especially in developing countries – Xantec – 2011-04-06T21:49:47.580

Answers

5

No, you can't move it.

During boot time Windows (and your BIOS) uses a minimal file I/O system to locate the boot drive and files needed to finish the boot (including the file-system drivers). Since the hibernation file contains system state before shutdown, it's needed actually boot to the 'full' file system.

If you've been around since the DOS days, you may remember having to use "SYS" to make a disk bootable; you couldn't just copy the boot files (msdos.sys, io.sys, etc.) to the disk and have it work, becuase they need(ed) to be at a specific address on the disk so the system knew where to find them to boot the actual OS. Same deal here...

Here's a good blurb about it:

Hibernation follows a similar pattern. Hibernating the operating system means dumping the entire contents of memory into the hibernation file; restoring from hibernation entails sucking that file back into memory and pretending nothing happened. Again, it's another chicken-and-egg problem: to load the hibernation file, you need the file system driver, but the file system driver is in the hibernation file. If you keep the hibernation file in the root directory of the boot drive, the miniature file system driver can be used instead.

You can read the rest of the article here.

Ƭᴇcʜιᴇ007

Posted 2011-04-06T18:12:57.550

Reputation: 103 763

1@techie007, thanks for your detailed answer and the link. Now I'm completely convinced :) – None – 2011-04-06T18:46:20.190

1@caveman: That article is from 2007. That was in the early XP Vista times and that article is most likely referring to Windows XP which is unsupported by now. Windows 7 has been released in late 2009 so you shouldn't really trust such an old link, give it a try because the current structure might allow for symbolic links or changing the path in the registry. – Tamara Wijsman – 2011-04-06T18:57:24.027

3

@Tom Wijsman - It still holds true. Here's references from a MS MVP in 2009, in regards to Windows 7 specifically: http://social.technet.microsoft.com/Forums/bg-BG/w7itproui/thread/b5baa5bf-bdb2-4c9e-8795-1441f59700a0 - he links back to that same article. I think the problem you're going to find with hard-links is that they don't exist until the file-system is running, which would be after the hibernaiton file has been used to boot.

– Ƭᴇcʜιᴇ007 – 2011-04-06T19:03:17.390

1@techie007: A MVP is not an official representative. Junctions do cross filesystems... – Tamara Wijsman – 2011-04-06T19:12:33.397

1

Furthermore, hibernation can be traced these days, so you should think about your statements.

– Tamara Wijsman – 2011-04-06T19:14:18.713

@Tom: Not necessarily. It could be just storing the perf data in otherwise-unused memory and dumping to disk after the system has resumed. – user1686 – 2011-04-06T19:16:12.910

@grawity: It could be? That would not result in a full trace. – Tamara Wijsman – 2011-04-06T19:20:28.430

2@Tom Wijsman - I'm aware an MVP isn't an actual MS rep. But they're usually more in-the-know when it comes to their favorite MS technologies than the average dude on the Internet. The xbootmgr tracing is for checking system performance while going in to and coming out of ACPI sleep states (and how long they were in those states). The trace doesn't start/continue until after the hibernation file has been mounted and the OS is running again. – Ƭᴇcʜιᴇ007 – 2011-04-06T19:31:23.067

2@techie007: Sorry for playing devil's advocate. A MS rep explanation from the Windows Internals book can be found in my answer and tracing it as you did are two up-to-date ways to verify that it's impossible in that way, the only thing that is left to try is to change that registry location as it most likely is there for a reason... – Tamara Wijsman – 2011-04-06T19:50:04.080

2

Disallowing deletes (if there is a SID)

First make sure that hiberfil.sys isn't inheriting permissions, be sure to add permissions.

Then, make sure for each user that has access except for being able to delete the file:

enter image description here

This way, the file can not be deleted, if there is at least a security identifier attached.

Looking at what Microsoft has to say about the hibernation file.

When a user subsequently turns on the computer, a normal boot process occurs, except that Bootmgr checks for and detects a valid memory image stored in the hibernation file. If the hibernation file contains saved system state, Bootmgr launches Winresume, which reads the contents of the file into memory, and then resumes execution at the point in memory that is recorded in the hibernation file.

If Windows enabled the BCD setting to inform Bootmgr of a hibernation resume, this shortcuts the boot process by launching Winresume.exe, which will read the contents of the file into memory and transfer control to code in the kernel that resumes a hibernated system. That code is responsible for restarting drivers that were active when the system was shut down. Hiberfil.sys will be valid only if the last time the computer was shut down it was hibernated.

After Bootmgr enables protected mode, it is fully operational. However, it still relies on functions supplied by BIOS to access IDE-based system and boot disks as well as the display. Bootmgr’s BIOS-interfacing functions briefly switch the processor back to a mode in which services provided by the BIOS can be executed, called real mode. Bootmgr next reads the BCD file from the \Boot directory using built-in file system code.

Bootmgr contains read-only NTFS code (Bootmgr also supports other file systems, such as FAT, El Torito CDFS, UDFS, and WIM files); unlike the boot sector’s code, however, Bootmgr’s file system code can read subdirectories.

— Windows Internals

So, no, as it uses built-in file system code, doing this in a simple way is most likely impossible.

The best you could try is to change the BCD:

HKEY_LOCAL_MACHINE\BCD00000000\Objects\{db7f3566-bd6f-11df-b716-db3964014abb}\Elements\22000002\Element

Perhaps you could try modifying it to X:\Some\Path\To\Whatever\File.Ext or a fully qualified path.

A solution that will sure work which makes your question possible.

  1. Install your Windows to your HDD.

  2. Move everything to your SSD except for the hiberfil.sys file.

  3. Create junction points to everything on your SSD.

You are also able to scale down the size of the hibernation file.

You can do this towards 50% using powercfg.exe

-HIBERNATE, -H
        Enables-Disables the hibernate feature.  Hibernate timeout is not
        supported on all systems.

        Usage: POWERCFG -H <ON|OFF>
               POWERCFG -H -Size <PercentSize>
        -Size  Specifies the desired hiberfile size in percentage of the
               total memory. The default size cannot be smaller than 50.
               This switch will also enable the hiberfile automatically.

Tamara Wijsman

Posted 2011-04-06T18:12:57.550

Reputation: 54 163

@user68795, Link down... – Pacerier – 2017-02-14T18:44:56.003

@TomWijsman, What does db7f3566-bd6f-11df-b716-db3964014abb refer to? Doesn't seem to find that in the list http://www.geoffchappell.com/notes/windows/boot/bcd/objects.htm?tx=5

– Pacerier – 2017-02-14T18:45:00.343

I was not able to set permissions on hiberfil.sys file. The Security tab of Properties of hiberfil.sys file says "The requested security information is either unavailable or can't be displayed". – None – 2011-04-06T19:05:28.037

@caveman: Take ownership of the file first. :) – Tamara Wijsman – 2011-04-06T19:12:03.223

@caveman: Updated the end of my question with a handy tip... – Tamara Wijsman – 2011-04-06T19:21:38.213

Here is a screenshot I took from virtual machine. Unfortunately I couldn't change the ownership or permissions of the hiberfil.sys file.

– None – 2011-04-06T19:28:58.360

@caveman: Try doing this from the a Windows 7 DVD which should allow you to access it's permissions. If not, then it is probably made at a lower level and thus doesn't have a security identifier attached, if the BootMgr removes it without checking permissions then there is nothing we could do about it... – Tamara Wijsman – 2011-04-06T19:36:02.790

2What happens when you reduce the percentage? – Ivo Flipse – 2011-04-20T07:48:40.430

1@IvoFlipse: If you have 4 GB memory, and you are using less than 2 GB (excluding ReadyBoost) it would only store 2 GB if you change this towards 50% instead of 4 GB filled with zeroes or random data. – Tamara Wijsman – 2011-04-20T09:45:42.273