User Tools

Site Tools


userspace:diskpart_-_dynamic_system_partition_resize

This is an old revision of the document!


Resize system partition dynamically, based on size needed

  • tested under windows 7
  • tested under winst 4.11.5.13

In case you want your system partition to only use the amount of diskspace required by the system and the applications you install, you can use the following code to extend your system partition dynamically before installing your software.

!!! Warning !!!

Using this can lead to problems if your applications or users are storing data on the system partition.

If you want use this, you should consider adopting further measures to prevent possible hickups - f.e. move profiles to another partition, configure your applications to store their data on another partition, prevent write access for users on the system partition. Take care ;)

Integrate the following code into your installation script, and change the value of $MinimumFreeSpace$ to the amount of MB required by the software to install; 1 GB equals 1024, like given as example below.

[actions]
defVar $MinimumFreeSpace$ 
set $MinimumFreeSpace$ = "1024"
 
if not ( hasMinimumSpace( "%SystemDrive%", $MinimumFreeSpace$ + " MB" ) )
	comment "Not enough free space left, trying to extend volume %SystemDrive% by " + $MinimumFreeSpace$ + " MB."
	execwith_resize_volume diskpart /s
	if not ( hasMinimumSpace( "%SystemDrive%", $MinimumFreeSpace$ + " MB" ) )
		logError "Failed to resize volume, cancel installation"
		isFatalError
	endif
else
	comment "Still enough free space left, continue with installation"
endif
[execwith_resize_volume]
select volume %SystemDrive%
extend size=$MinimumFreeSpace$

This script assumes you install software on your system partition. Otherwise, you need to replace any occurance of %SystemDrive% within my code with the drive letter of your desired partition. f.e. extract it like this:

defVar $InstallDrive$
set $InstallDrive$ = takeString(0,splitString($InstallDir$,"\"))
userspace/diskpart_-_dynamic_system_partition_resize.1442511835.txt.gz · Last modified: 2021/08/23 08:37 (external edit)