Why are some files not movable on Windows 10?

22

3

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.

kelalaka

Posted 2019-09-12T18:45:33.397

Reputation: 331

They are movable but not while booted into windows, you need a third party partitioning tool that you boot from, then any of them can be moved. – Moab – 2019-09-12T20:23:33.447

4

Possible duplicate of How can I shrink a Windows 10 partition?

– Moab – 2019-09-12T20:26:34.257

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 – 2019-09-12T20:28:29.547

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 – 2019-09-12T20:29:41.943

While running hibernation is used? It should be used only when going to hibernate. – kelalaka – 2019-09-12T20:31:57.173

Its still locked by Windows. – Moab – 2019-09-12T20:33:04.283

Voted to close as a duplicate, since we don't need yet another question, that explains how to disable the pagefile, hibernation file, in order to then recreate it at a different part of the disk. – Ramhound – 2019-09-12T22:39:49.393

2@kelalaka: Windows 10 makes hibernation faster by preparing in the background, when it's got nothing else to do. – MSalters – 2019-09-13T09:13:46.663

1You might as well ask why you can't rip out the RAM/memory and replace it while windows is running. pagefile is on-disk memory. – freedomn-m – 2019-09-13T09:58:04.000

@freedomn-m That still doesn't explain why it is not movable. – glglgl – 2019-09-13T11:40:55.797

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 – 2019-09-13T18:06:04.497

@jmbpiano I see no problem with your approach. If you're still hesitant or looking for more support, take it to meta and I'm sure you'll find it. – Mast – 2019-09-15T06:16:58.413

1You can't move files on Windows which have an open file handle. I believe this is different on Linux as even if you were to delete file when there is an active handle, the handle is still valid in that it still points to the original data which isn't actually deleted until the last handle is closed (despite the file no longer having any reference in the file tree). – Zhro – 2019-09-15T08:58:40.860

Answers

39

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.

harrymc

Posted 2019-09-12T18:45:33.397

Reputation: 306 093

2If 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 – 2019-09-13T14:44:53.323

1@Džuris: You miss the point. – harrymc – 2019-09-13T14:54:48.883

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 – 2019-09-13T15:29:35.110

I get the overall point, but in this exact example the architecture seems such that it would keep working through any renames. However, I believe there is no mechanism in Windows that would allow local renames but prevent moving to another disk. – Džuris – 2019-09-13T17:28:21.100

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 – 2019-09-13T17:40:25.710

2To 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 – 2019-09-13T18:46:22.263

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. – HiddenWindshield – 2019-09-13T19:07:46.430

1@HiddenWindshield: Moving to another directory is just a rename operation, but only after the copy is finished. As in my above comment, a file that is constantly being updated cannot be copied to start with. – harrymc – 2019-09-14T10:28:35.557

1@harrymc there is no copy to be finished. Moving a file to another directory in the same partition does not copy anything. But again, that's not what the question is about. – OrangeDog – 2019-09-15T11:42:05.157

1@OrangeDog: There is always a copy to be done, even if to only copy the file's metadata from one folder to another. But even more for the page-file which is only located at the disk root, so any change is a full copy. – harrymc – 2019-09-15T18:36:30.933

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.

HoD

Posted 2019-09-12T18:45:33.397

Reputation: 2 282

11This 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. – Dmitry Grigoryev – 2019-09-13T07:50:15.697

7His 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 – 2019-09-13T07:55:26.587

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 – 2019-09-13T08:38:54.087

4@HoD Yes, but that's not because JKdefrag is trying to move hiberfil out of the root directory. – Dmitry Grigoryev – 2019-09-13T08:45:23.367

7It'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 – 2019-09-13T08:47:46.850

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.

wallyk

Posted 2019-09-12T18:45:33.397

Reputation: 1 306

The defragmenter doesn't prevent it, Windows prevents it. – OrangeDog – 2019-09-15T11:42:55.777

@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 – 2019-09-15T21:15:39.377

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. – Justin Time - Reinstate Monica – 2019-09-17T06:12:20.133

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.

user1901982

Posted 2019-09-12T18:45:33.397

Reputation: 739