24

I'm trying to shrink my partition. In order to achieve the amount that I need, I'm using JKdefrag. I've seen that some files are marked red - not movable, like hibernation.sys and pagefile.sys.

In the end, they are just files, and I'm an administrator. The only thing I can do remove them by disabling.

Why are they not movable?

Note: I'm not asking how to disable the hibernation.sys, pagefile.sys, etc. file. I'm looking for the reason why they are not movable. The answers in probable duped question don't contain the reason.

13
  • 4
    Possible duplicate of How can I shrink a Windows 10 partition?
    – Moab
    Commented Sep 12, 2019 at 20:26
  • 5
    @Moab I'm not asking how to shrink or remove them. There are tons of sites that mentions this. I'm just asking Why!
    – kelalaka
    Commented Sep 12, 2019 at 20:28
  • 3
    "I'm trying to shrink my partition" Because they are in use by Windows and some are protected, just cant move them while booted into windows.
    – Moab
    Commented Sep 12, 2019 at 20:29
  • 2
    @kelalaka: Windows 10 makes hibernation faster by preparing in the background, when it's got nothing else to do.
    – MSalters
    Commented Sep 13, 2019 at 9:13
  • 8
    This is actually a duplicate of Why are some files unmovable when shrinking a partition in Windows? Sadly, the only "answer" at the older question fails to answer it at all. This is not a new issue, nor is it specific to Windows 10. Given the superior quality of the answers here, I'd almost be tempted to suggest removing the "windows-10" tag from this question and making it the canonical version (marking the older question as a dupe to this one).
    – jmbpiano
    Commented Sep 13, 2019 at 18:06

4 Answers 4

40

Some system files cannot be moved after the system boots, such as the page-file and registry database files. They are exclusively locked by Windows itself, so cannot be moved or directly updated while Windows is running.

For example, while Windows is running the page-file is referred-to by its direct cluster number on the disk. Since swap is a critical operation affecting system performance, Windows does not have the time to search the disk and folder metadata when it wants to do or undo a swap.

Another reason for making these files unmovable is that they are critical to the operation of Windows, so Windows protects them to the limit and does not allow any access that does not go through its dedicated utilities or API.

Any product that is capable of moving these files will require a reboot in order to get access to the disk before Windows is launched.

10
  • 2
    If Windows refers to it by cluster number, what's the problem with moving? A move within the same disk is just a rename. Why would Windows care if he's not using the name?
    – Džuris
    Commented Sep 13, 2019 at 14:44
  • 3
    @Džuris I don't think he does though; he's right, moving pagefile.sys within a filesystem wouldn't change the physical location of its contents. Sure, I can see why Windows would just lock the file and disallow any actions, but you imply the direct access necessitates denying renames, and I don't see how that's true. Interestingly, Linux (which normally has a voluntary attitude to locking) behaves the same.
    – marcelm
    Commented Sep 13, 2019 at 15:29
  • 10
    @Džuris, in this scenario moving the file refers to moving it's contents to another area of the disk. The goal is to end up with all the free space at the end of the partition so it can then be trimmed. Renaming is irrelevant.
    – kicken
    Commented Sep 13, 2019 at 17:40
  • 2
    To lay things straight: No operating system can allow the swap file to be unavailable while it is being copied. It is a big question whether the OS can even do the copy while swap is paralyzed. New processes cannot start without swap space allocation, the kernel may come to a halt if it cannot swap out memory, cache data cannot be swapped out for making space for the data to be copied etc etc. In short, a file while moved is unusable, that's why critical system files are unmovable. And a move is certainly not a rename.
    – harrymc
    Commented Sep 13, 2019 at 18:46
  • 9
    @Džuris Moving a file to another directory is just a rename operation, as a file name is just a pointer to the physical sectors that hold the actual data. But kelalaka is asking about moving the actual data in the context of shrinking a partition. So, no, that's not a simple rename. Commented Sep 13, 2019 at 19:07
5

A cool story by Raymond Chen:

Windows Confidential -The File System Paradox

In short:

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.

5
  • 11
    This cool story has nothing to do with the question: the OP isn't trying to move these files out of the root directory, they try to move them in another physical location on the disk. Commented Sep 13, 2019 at 7:50
  • 7
    His final note is, "It's only a matter of time before somebody asks for a way to put the hibernation file on a [network drive]."
    – cjs
    Commented Sep 13, 2019 at 7:55
  • 1
    @DmitryGrigoryev Perhaps I misunderstand but JKdefrag is a tool you run inside Windows, which shows it as unmovable because Windows prevents any modification of the hiberfil ?
    – HoD
    Commented Sep 13, 2019 at 8:38
  • 4
    @HoD Yes, but that's not because JKdefrag is trying to move hiberfil out of the root directory. Commented Sep 13, 2019 at 8:45
  • 7
    It's an interesting read, but it's about moving hibernation file to a different directory. OP's question is about moving file's physical location on the HDD, but without changing its location in the directory tree. That's what defragmentation does.
    – gronostaj
    Commented Sep 13, 2019 at 8:47
1

The hibernate and page files are low level system files. Both are used to temporarily store system memory (RAM) on non-volatile storage (disk or ssd).

Hibernation—also called suspend to disk—is powering down a computer while retaining its state (so, for example, word processor files being worked on don't have to be saved first). When the system is powered on again, the RAM image data is restored from the "hibernate image and the system proceeds as though it had not been powered down at all.

Paging is a central characteristic of virtual memory systems where each program is given the illusion that its process-specific memory space is all of the address space on the computer. That illusion is provided by moving not-recently-used small blocks (commonly 4,096 bytes, but sometimes larger—32 KiB, 1 MiB, 16 MiB, 1 TiB) of memory to disk until needed. When a program accesses memory which has been paged out, a low level CPU operation called a "page fault" is attended to by the o/s kernel to bring the page back into memory and then resumes the program seamlessly at the faulting instruction so it can execute as though the page had been in memory all along.

Both paging and hibernation are implemented at the lowest levels of the operating system. As a result, it is inconvenient and messy for a disk defragmenter to cleanly move the disk blocks of those files around while they are potentially in use. To greatly simplify programs which might do that, it is easier to recognize these files and prohibit such operations.

3
  • The defragmenter doesn't prevent it, Windows prevents it.
    – OrangeDog
    Commented Sep 15, 2019 at 11:42
  • @OrangeDog: It is the defragger which marks the clusters as "unmoveable". There is no attribute in FAT nor NTFS which says this extent or file is unmovable. More recent versions of Windows (since XP) have an API for defragmenters; before that, they would perform direct i/o on the disk volume.
    – wallyk
    Commented Sep 15, 2019 at 21:15
  • 1
    These files are, in fact, locked by Windows to prevent them from being manipulated by anything other than the kernel itself, as can be observed by attempting to open them with Notepad. So, while the defragger may or may not be responsible for marking them as unmoveable, it does so because Windows itself prevents it from so much as looking at them, let alone actually touching 'em. Commented Sep 17, 2019 at 6:12
0

Also, I think it's worth adding here that there is a solution to your original issue (allowing you to shrink your partitions).

Using System settings, you can set your Pagefile to a different drive and disable hibernation, so pop in a pen drive to put your pagefile on and you'll be a restart away from those unmoveable files not existing at all.

You must log in to answer this question.

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