What you said also makes sense, but the primary partition established this way is not at the end of the hard drive, but behind the first primary partition. Of course, the primary partition established in this way does not affect the installation of one-key recovery, and it should be feasible. According to your requirement, you need to first check whether the space of the last partition is sufficient. If not, then check the first partition. If it is still not sufficient, operate according to my V3 script, right?
The following is the script modified according to your needs:
// Allow the user to manually restart the computer after the operation, otherwise it will automatically restart the computer
Allow Manual Reboot
// By default, do not detect bad sectors to improve operation speed
Set Default Bad Sector Test State OFF
// Select the first hard drive
Select Disk 1
// Select the first partition
Select Partition First
Dim PriSize
// Detect the used space of the first partition, set PriSize to 1/2 of its used space plus 200M, otherwise it may not be enough
PriSize = GetUsedAmount / 2 + 200
// Detect the number of primary partitions on the current hard drive
Dim PriNum
Dim i
i = 1
PriNum = 0
Select Partition FIRST
DO WHILE i < GetTotalPartitions
IF IsPrimary Then
PriNum = PriNum + 1
End If
Select Partition Next
i = i + 1
Loop
IF IsPrimary Then
PriNum = PriNum + 1
End If
// Detect whether there is an extended partition on the hard drive, if there is, it is also counted as a primary partition
dim ExtNum
ExtNum = GetPartitionNumber Extended
If ExtNum 0 Then
PriNum = PriNum + 1
End If
// Only continue if the number of primary partitions is less than 4
IF PriNum = PriSize Then
Resize Space After PriSize
// Select the last unallocated space (the one just freed)
Select Unallocated After Selected Partition
// Create a partition of the specified size at the end of the hard drive, the volume label is SYS_GHOST, of course, you can modify the label according to the actual situation.
Create /FS=FAT32 /LABEL="SYS_GHOST"
// Convert this partition to a primary partition
Convert To Primary
bDone = 1
End If
// If the space of the last partition is not enough, then check whether the space of the first partition is enough. If it is enough, repeat the above operation.
If bDone = 0 Then
Select Partition First
Check
Resize Larger Max
If GetUnusedAmount >= PriSize + 2048 Then
Resize Space After PriSize
// Select the last unallocated space (the one just freed)
Select Unallocated After Selected Partition
// Create a partition of the specified size, the volume label is SYS_GHOST, of course, you can modify the label according to the actual situation.
Create /FS=FAT32 /LABEL="SYS_GHOST"
// Convert this partition to a primary partition
Convert To Primary
bDone = 1
End If
End If
// If the above two operations are not successful, perform the third operation, which is also the most complex operation, mainly manifested in the longest time consumption
If bDone = 0 Then
// If there is an extended partition, select the extended partition and let it occupy all the unallocated space before and after
If ExtNum 0 Then
Select Disk 1
Select Partition Extended
Resize Max
End if
// dOperPnum is used to save how many partitions have been operated
Dim dOperPnum
dOperPnum = 0
// bMove is used to judge whether space freeing operation has been performed. If yes, it is the basis for subsequent space movement judgment
Dim bMove
bMove = 0
// dLastOpPar saves the partition number of the last operation
Dim dLastOpPar
// If the current number of unallocated spaces meets the need, there is no need to perform space reallocation operation
If GetTotalUnallocatedSpaces < PriSize Then
// Select the last partition and judge whether it is a primary partition
Select Partition Last
Check
// FreeSpace is used to save the freed space
Dim FreeSpace
FreeSpace = 0
// NeedSpace is used to save how much space still needs to be freed
Dim NeedSpace
NeedSpace = PriSize
Dim dTmp
dTmp = 0
// Loop from the last partition to free the required space
i = 0
Do While FreeSpace = NeedSpace Then
// Change the size of this partition, free the space of the required size (that is, the value saved in the NeedSpace variable) behind it
Resize Space After NeedSpace
FreeSpace = FreeSpace + NeedSpace
bMove = 1
Else
// If the remaining space of this partition is greater than 100M, reduce the size of this partition by the size of unused space minus 100M
If GetUnusedAmount > 100 Then
dTmp = GetUnusedAmount - 100
Resize Space After dTmp
FreeSpace = FreeSpace + dTmp
NeedSpace = PriSize - FreeSpace
bMove = 1
End If
End If
i = i + 1
dOperPnum = dOperPnum + 1
// If the loop reaches the first partition but the space is still insufficient, directly exit the loop
If i < GetTotalPartitions Then
Select Partition Previous
Check
dLastOpPar = GetPartitionNumber Next
Else If FreeSpace < PriSize Then
dLastOpPar = GetPartitionNumber First
Exit Loop
End If
Loop
End If //If GetTotalUnallocatedSpaces < PriSize
// If there is no partition segmentation operation, there are two reasons: 1. Insufficient disk space; 2. Unallocated space is enough
If bMove = 0 Then
dLastOpPar = GetPartitionNumber First
dOperPnum = GetTotalPartitions
Select Partition First
Move Left Max
Else
// Start to move the space freed in the previous loop backwards
Dim LastMoveParType
Dim CurParNum
i = 1
If bMove = 1 Then
Select Disk 1
Select Partition dLastOpPar
CurParNum = GetPartitionNumber Next
If IsPrimary Then
LastMoveParType = 1
Else
LastMoveParType = 0
End If
Do While i < dOperPnum
Select Partition Next
If IsPrimary Then
If LastMoveParType = 0 Then
Select Disk 1
Select Partition Extended
Resize Min
End If
Else
If LastMoveParType = 1 Then
Select Disk 1
Select Partition Extended
Resize Left Boundary Max
End If
End If
Select Partition CurParNum
Move Left Max
If IsPrimary Then
LastMoveParType = 1
Else
LastMoveParType = 0
End If
CurParNum = GetPartitionNumber Next
i = i + 1
Loop
// Select the last unallocated space (the one just freed)
Select Unallocated After Selected Partition
// Create a partition of the specified size at the end of the hard drive, the volume label is SYS_GHOST, of course, you can modify the label according to the actual situation.
Create /FS=FAT32 /LABEL="SYS_GHOST"
// Convert this partition to a primary partition
Convert To Primary
End If // If bMove = 1
End If // If bMove = 0
End If // If bDone = 0
End If // If PriNum < 4
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“
这个帖子”和“
这个帖子”并努力遵守,如果可能,请告诉更多的人!