Skip to content

Instantly share code, notes, and snippets.

@Francesco149
Last active December 12, 2019 03:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Francesco149/2457ee733c39a8c6f153a89e7bfe2432 to your computer and use it in GitHub Desktop.
Save Francesco149/2457ee733c39a8c6f153a89e7bfe2432 to your computer and use it in GitHub Desktop.

#How to free up Windows 7 disk space

Here are some ways to reduce the disk space usage of Windows 7 for those with a really small SSD who need space on C: to install updates or software such as visual studio which requires space on your primary drive to even install, no matter what.

This guide is mainly a reminder memo for myself, so forgive me if it's not too detailed.

All code blocks imply that you run the commands in an elevated command prompt (Start -> type "cmd" -> right click "cmd" -> Run As Administrator).

Backstory: I've recently tried installing visual studio express in a virtual machine that had very little disk space on the main drive (28gb partition of my SSD). I had about 2 gigs of space free and even with Program Files and Program Files (x86) symlinked to a slower, larger drive that I use for anything except the OS, the installer would just crash either instantly or during installation. This happened for VS2008 Express, VS2013 Community, VS2015 Community. Also, installing large updates was impossible as they would automatically get downloaded and unpacked in C:.

Move the tmp folder

  • Control Panel -> System and Security -> System -> Advanced System Settings
  • Click "Environment Variables..."
  • If the upper table contains TEMP and TMP, edit them to your desired directory by highlighting each of them and clicking "Edit...". If they do not exist, create them by clicking "New...".
  • Reboot and delete C:\Temp or whatever folder it was previously set to.

Disable the paging file

Be aware that this might not always be the best idea, as your system will crash if you run out of ram. I am perfectly fine with this though, as I have plenty of ram.

This will free as much disk space as the amount of ram you have (I have 8 gigs of ram, so it freed up 8 gigs of disk space).

  • Control Panel -> System and Security -> System -> Advanced System Settings
  • Go to the "Advanced" tab
  • Click "Settings..." under "Performance"
  • Go to the "Advanced" tab
  • Click "Change..." under "Virtual Memory"
  • Untick "Automatically manage paging file size for all drives"
  • Make sure C: is selected
  • Tick "No paging file" and click "Set"
  • Click OK
  • Reboot

Symlink Program Files

This will force programs to install to a different drive. Even those that don't offer that option or don't fully honor it, such as Visual Studio.

Prepare a USB stick with GParted Live. Rufus should get the job done for preparing the stick.

Copy C:\Program Files and C:\Program Files (x86) to your desired drive (E: in my case).

(before you run these commands, remember to replace E:\Program Files and E:\Program Files (x86) with your desired locations)

mkdir "C:\links"
mklink /D "E:\Program Files" "C:\links\Program Files"
mklink /D "E:\Program Files (x86)" "C:\links\Program Files (x86)"

Make sure that both links in C:\links go to your copies of "Program Files" and "Program Files (x86)".

Boot into gparted live and use the gui that pops up to find out what partition your OS is in (named /dev/ followed by letters and a number). You want the OS partition, not the 100mb system reserved partition. For this example, we'll assume it's /dev/sda1.

Open the terminal and type (remember to replace /dev/sda1 with your partition):

sudo mkdir /mnt/win
sudo mount /dev/sda1 /mnt/win
cd /mnt/win
sudo rm -rf "Program Files"
sudo mv "./links/Program Files" .
  • Boot back into Windows and download and extract NTFS Permissions Tool.
  • Run NPT64.
  • Navigate to C: and highlight "Program Files (x86)".
  • Right click "Program Files (x86)" and click "Copy Security settings" and "Inheritance Permissions".
  • Highlight "Program Files".
  • Right click "Program Files" and click "Paste Security settings" and "Replace all child object permissions".

Boot into GParted live and once again remember or find out your partition as explained earlier.

Open the terminal and type (remember to replace /dev/sda1 with your partition):

sudo mkdir /mnt/win
sudo mount /dev/sda1 /mnt/win
cd /mnt/win
sudo rm -rf "Program Files (x86)"
sudo mv "./links/Program Files (x86)" .
  • Boot back into Windows and run once again NPT64.
  • Navigate to C: and highlight "Program Files".
  • Right click "Program Files" and click "Copy Security settings" and "Inheritance Permissions".
  • Highlight "Program Files (x86)".
  • Right click "Program Files (x86)" and click "Paste Security settings" and "Replace all child object permissions".

There's also more you can symlink using this method, such as AppData and other large folders. The permissions stuff is usually not necessary if you copy the original folder. Symlinks must be first created on windows and then moved from linux (GParted) just like we did with Program Files if the folder cannot be deleted or moved while windows is running.

Symlink the Windows Update download folder

This is mainly to be able to install large updates that require gigabytes of space to even unpack or download.

net stop wuauserv

Move the C:\Windows\SoftwareDistribution folder to a different drive (E: in this example).

(before you run these commands, remember to replace E:\SoftwareDistribution with your desired location)

mklink /D "C:\Windows\SoftwareDistribution" "E:\SoftwareDistribution"
net start wuauserv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment