I keep getting asked about this in various places, so I thought it was high time I described how I do it. I will avoid using any 3rd party proprietary tools; everything you need is built-in.
Notes for dual-booters:
This is a bit harder with Windows 10 than it was with any previous versions. There are some extra steps you need to do. Miss these and you will encounter problems, such as Linux refusing to boot, or hanging on boot, or refusing to mount your Windows drive.
It is worth keeping Windows around
. It's useful for things like updating your motherboard firmware, which is a necessary maintenance task -- it's not a one-off. Disk space is cheap these days.
Also, most modern PCs have a new type of firmware called UEFI. It can be tricky to get Linux to boot off an empty disk with UEFI, and sometimes, it's much easier to dual-boot with Windows. Some of the necessary files are supplied by Windows and that saves you hard work. I have personally seen this with a Dell Precision 5810, for instance.
Finally, it's very useful for hardware troubleshooting. Not sure if that new device works? Maybe it's a Linux problem. Try it in Windows then you'll know. Maybe it needs initialising by Windows before it will work. Maybe you need Windows to wipe out config information. I have personally seen this with a Dell Precision laptop and a USB-C docking station, for example: you could only configure triple-head in Windows, but once done, it worked fine in Linux too. But if you don't configure it in Windows, Linux can't do it alone.
Why would you want to do this? Well, there are various reasons.
- You regularly, often or only run Windows and want to keep it performing well.
- You run Windows in a VM under another OS and want to minimize the disk space and RAM it uses.
- You dual-boot Windows with another OS, and want to keep it happy in less disk space than it might normally enjoy to itself.
- You're preparing your machine for installing Linux or another OS and want to shrink the Windows partition right down to make as much free space as possible.
- You've got a slightly troublesome Windows installation and want to clean things up as a troubleshooting step.
Note, this stuff also applies
to a brand-new copy of Window
, not just an old, well-used installation.
I'll divide the process into 2 stages. One assuming you're not preparing to dual-boot, and a second stage if you are.So: how to clean up a Windows drive.
The basic steps are: update; clean up; check for errors.
If you're never planning to use Windows again, you can skip the updating part -- but you shouldn't. Why not? Well, as I advised above, you should keep your Windows installation around unless you are absolutely desperate for disk space and so poor that you can't afford to buy more. It's useful in emergencies. And in emergencies, you don't want to spend hours installing updates. So do it first.
Additionally, some Windows updates require earlier ones to be installed. A really old copy might be tricky to update.
- Updating. This is easy but not quite as easy as it looks at first glance. Connect your machine to the Internet, open Windows Update, click "Check for updates". But wait! There's more! Because Microsoft has a vested interest in making things look smooth and easy and untroubled, Windows lies to you. Sometimes, when you click "check for updates", it says there are none. Click again and magically some more will appear. There's also a concealed option to update other Microsoft products and it is, unhelpfully, off by default. You should turn that on.
- Once Windows Update has installed everything, reboot. Sometimes updates make you do this, but even if they don't, do it manually anyway.
- Then run Windows Update and check again. Sometimes, more will appear. If they do, install them and go back to step 1. Repeat this process until no new updates appear when you check.
- Next, we're going to clean up the disk. This is a 2-stage process.
- First, run Disk Cleanup. It's deeply buried in the menus so just open the Start menu and type CLEAN. It should appear. Run it.
- Tick all the boxes -- don't worry, it won't delete stuff you manually downloaded -- and run the cleanup. Normally, this is fast. A few minutes is enough.
- Once it's finished, run disk cleanup again. Yes, a second time. This is important.
- Second time, click the "clean up system files" button.
- Again, tick all the boxes, then click the button to run the cleanup.
- This time, it will take a long time. This is the real clean up and it's the step I suspect many people miss. Be prepared for your PC to be working away for hours, and don't try to do anything else while it works, or it will bypass files that are in use.
- When it's finished, reboot.
- After your PC reboots, right-click on the Start button and open an administrative command prompt. Click yes to give it permission to run. When it appears, type: CHKDSK C: /F
- Type "y" and hit "Enter" to give it permission.
- Reboot your PC to make it happen.
- This can take a while, too. This can fix all sorts of Windows errors. Give it time, let it do what needs to be done.
- Afterwards, the PC will reboot itself. Log in, and if you want an extra-thorough job, run Disk Cleanup a third time and clean up the system files. This will get rid of any created by the CHKDSK process.
- Now you should have got rid of most of the cruft on your C drive. The next step requires 2 things: firstly, that you have a Linux boot medium, so if you don't have it ready, go download and make one now. Secondly, you need to have some technical skill or experience, and familiarity with the Windows folder tree and navigating it. If you don't have that, don't even try. One slip and you will destroy Windows.
- If you do have that experiece, then what you do is reboot your PC from the Linux medium -- don't shutdown and then turn it back on, pick "restart" so that Windows does a full shutdown and reboot -- and manually delete any remaining clutter. The places to look are in C:\WINDOWS\TEMP and C:\USERS\$username\AppData\Local\Temp. "$username" is a placeholder here -- look in the home directory of your Windows login account, whatever that's called, and any others you see here, such as "Default", "Default User", "Public" and so on. Only delete files in folders called TEMP and nowhere else. If you can't find a TEMP folder, don't delete anything else. Do not delete the TEMP folders themselves, they are necessary. Anything inside them is fair game. You can also delete the files PAGEFILE.SYS, SWAPFILE.SYS and HIBERFIL.SYS in the root directory -- Windows will just re-create them next boot anyway.
That's about it. After you've done this, you've eliminated all the junk and cruft that you reasonably can from your Windows system. The further stages are optional and some depend on your system configuration.Optional stagesDefragmenting the drive
Do you have Windows installed on a spinning magnetic hard disk, or on an SSD?
If it's a hard disk, then you may wish to run a defrag. NEVER defrag an SSD -- it's pointless and it wears out the disk.
But if you have an old-fashioned HDD, then by all means, after your cleanup, defrag it. Here's how
.I have not tested this on Win10
, but on older versions, I found that defrag does a more thorough job, faster, if you run it in Safe Mode. Here's how to get into Safe Mode in Windows 10
.Turning off Fast Boot
Fast Boot is a featue that only shuts down part of Windows and then hibernates. Why? Because when you turn your PC on, it's quicker to wake Windows and then load a new session than it is to boot it from scratch, with all the initialisation that involves. Shutdown and startup both become a bit quicker.
If you only run Windows and have no intention of dual-booting, then ignore this if you wish. Leave it on.
But if you do dual-boot, it's definitely worth doing. Why? Because when Fast Boot is on, Windows doesn't totally stop when you shut down, only when you restart. This means that the C drive is marked as being still mounted, that is, still in use. And if it's in use, then Linux won't mount it and you can't access your Windows drive from Linux.
Worse still, if like me you mount the Windows drive automatically during bootup, then Linux won't finish booting. It waits for the C drive to become available, and since Windows isn't running, it never becomes available so the PC never boots. This is a new problem introduced by the Linux systemd
tool -- older init systems just skipped the C drive and moved on, but systemd tries to be clever and as a result it hangs.
So, if you dual boot, always disable Fast Boot. It gives you more flexibility. I will list a few how-tos since Microsoft doesn't seem to officially document this.Turning off HibernationIF you have a desktop PC,
once you have disabled Fast Boot, also disable Hibernation.
If you have a notebook, you might want to leave it on. It's useful if you find yourself in the middle of something but running out of power, or about to get off a train or plane. But for a desktop, there's less reason, IMHO.
There are a few reasons to disable it:
- It eliminates the risk of some Windows update turning Fast Boot back on. If Hibernation is disabled, it can't.
- It means when you boot Linux your Windows drive will always be available. Starting another OS when Windows is alive but hibernating risks drive corruption.
- It frees up a big chunk of disk space -- equal to your physical RAM -- that you can take off your Windows partition and give to Linux.
Here's how to disable it:
In brief: open an Admin Mode command prompt, and type powercfg /h off.
That's it. Done.
Once it's done, if it's still there, in Linux you can delete C:\HIBERFIL.SYS.Final steps -- preparing for installing a 2nd operating system
If you've got this far and you're not about to set up your PC for dual-boot, then stop, you're done.
But if you do
want to dual-boot, then the final step is shrinking your Windows drive.
There are 2 ways to do this. You might want one or the other, or both.
The safe way is to follow a dual-booter's handy rule:Always use an OS-native tool to manipulate that OS.
What this means is this: if you're doing stuff to, or for, Windows, then use a Windows tool if you can. If you're doing it to or for Linux, use a Linux tool. If you're doing it to or for macOS, use a macOS tool.
- Fixing a Windows disk? Use a Windows boot disk and CHKDSK. Formatting a drive for Windows? Use a Windows install medium. Writing a Windows USB key? Use a Windows tool, such as Rufus.
- Writing a Linux USB? Use Linux. Formatting a drive for Linux? Use Linux.
- Adjusting the size of a Mac partition? Use macOS. Writing a bootable macOS USB? Use macOS.
So, to shrink a Windows drive to make space for Linux, then use Windows to do it.
Here's the official Microsoft way
Check how much space Windows is using, and how much is free. (Find the drive in Explorer, right-click it and pick Properties.)
The free space is how much you can give to Linux.
Note, once Windows is shut down, you can delete the pagefile and swapfile to get a bit more space.
However, if you want to be able to boot Windows, then it needs some free working space. Don't shrink it down until it's full and there's no free space. Try to leave it about 50% empty, and at least 25% empty -- below that and Windows will hit problems when it boots, and if you're in an emergency situation, the last thing you need are further problems.
As a rule of thumb, a clean install of Win10 with no additional apps will just about run in a 16 GB partition. A 32 GB partition gives it room to breathe but not much -- you might not be able to install a new release of Windows, for example. A 64 GB partition is enough space to use for light duties and install new releases. A 128 GB partition is enough for actual work in Windows if your apps aren't very big.
Run Disk Manager, select the partition, right-click and pick "shrink". Pick the smallest possible size -- Windows shouldn't shrink the disk so much you have no free space, but note my guidelines above.
Let it work. When it's done, look at how much unpartitioned space you have. Is there enough room for what you want? Yes? Great, you're done. Reboot off your Linux medium and get going.
No? Then you might need to shrink it further.
Sometimes Disk Manager will not offer to shrink the Windows drive as much as you might reasonably expect. For example, even if you only have 10-20 GB in use, it might refuse to shrink the drive below several hundred GB.
If so, here is how to proceed.
- Shrink the drive as far as Windows' Disk Manager will allow.
- Reboot Windows
- Run "CHKDSK /F" and reboot again.
- Check you've disabled Fast Boot and Hibernation as described above.
- Try to shrink it again.
No joy? Then you might have to try some extra persuasion.
Boot off a Linux medium, and as described above, delete C:\PAGEFILE.SYS, C:\SWAPFILE.SYS and C:\HIBERFIL.SYS.
Reboot into Windows and try again. The files will be automatically re-created, but in new positions. This may allow you to shrink the drive further.
If that still doesn't work, all is not lost. A couple more things to try:
- If you have 8 GB or more of RAM, you can tell Windows not to use virtual memory. This frees up more space. Here's how.
- Disable System Protection. This can free up quite a bit of space on a well-used Windows install. Here's a how-to.
Try that, reboot, and try shrinking again.
If none of this works, then you can shrink the partition using Linux tools. So long as you have a clean disk, fully shut down (Fast Boot off, not hibernated, etc.) then this should be fine.
All you need to do is boot off your Linux medium, remove the pagefile, swapfile and any remaining hibernation file, then run GPARTED.
Again, bear in mind that you should leave 25-50% of free space if you want Windows to be able to run afterwards.
Once you've shrunk the partition, try it. Reboot into Windows and check it still works. If not, you might need to make the C partition a little bigger again.
Once you have a small but working Windows drive, you're good to go ahead with Linux.