MCSE技术论坛

首页 » 微软安全解决方案 » Systems Management Server&System Center » ZTI基于SQL判断计算机重新分区解决方案
magicking - 2007-12-19 14:43:00

ZTI基于SQL判断计算机重新分区解决方案


注:该方案中是以BDD 2.5为蓝本进行该解决方案的介绍的
适用场景:
ZTI解决方案中我们如果想让计算机在安装操作系统时进行重新分区,BDD中自带的“ZTIUserExit.vbs”脚本可以达到这个目的,但是该脚本是基于Windows PE运行磁盘来判断是否对计算机进行重新分区,该方法只适用于裸机的安装,但对已有系统计算机这种方法判断就不够灵活,所以这篇文章就为了解决该问题。

阅读对象:
1、
熟悉并能熟练实用System Manage Server 2003产品,和OSD的功能包。
2、
熟悉ZTI的工作流程。
3、
能够对“Customsettings.ini”脚本进行编辑和自定义。
4、
SQL数据库有所了解。
5、
能够对ZTI安装进行简单的基于日志的排错。

环境要求:
已部署了Active DirectorySystem Manager Server,并使用了BDD中的ZTI解决方案。

操作步骤:
1、
在数据库中添加用于判断分区的字段。
在“BDDAdminDB”数据库中的“BDDAdminCore”表中添加“Repartition”列,类型为“nvarchar(50)”。

2、
修改“Customsettings.ini”脚本定义,定义“CustomKeysUserData”值。
将“Repartition”的值定义到“CustomKeysUserData”,表示方法为“CustomKeysUserData=Repartition”,每个值间用“,”区分开。该操作是为了让计算机再ZTI安装过程中能够顺利的在SQL数据库中“Repartition”列取得数据。

3、
修改“ZTIUserExit.vbs”脚本,增加分区判断条件。

增加行“iRepartition = dicUserData("Repartition")”,该行是定义“iRepartition”变量的值,从“Repartition”中取值。

增加行“If iRepartition = "Y" then”,该行是定义条件当数据库“Repartito”列的值为“Y”的如何操作。

增加行“end if”,该行是因为在②中定义了一个进行“if”的条件,所以这里相应的要进行结束条件。
注:这些行具体添加位置可以参看下面的附录



附录A:“ZTIUserExit.vbs”脚本范例
'//---------------------------------------------------------------------------
'//
'//
'//
File:
ZTIUserExit.vbs

'//
'//
Function:
UserExit()

'//
'//
Input:
sType - user exit type (PHASE, SECTION)

'//
sWhen - when being called (BEFORE, AFTER)

'//
sDetail - detail for the exist (phase name, section name)

'//
bSkip - flag to indicate whether to skip normal processing (only possible with BEFORE)

'//
'//
Return:
Success - 0

'//
Failure - 1

'//
'//
Purpose:
This is a sample user exit, showing some of the capabilities of a user exit.

'//

'//---------------------------------------------------------------------------

Function UserExit(sType, sWhen, sDetail, bSkip)


Dim iRetVal



LogInfo sLogFile, "User exit started: " & sType & " " & sWhen & " " & sDetail, LogTypeInfo




iRepartition = dicUserData("Repartition")



If sType = "PHASE" and sDetail = "PREINSTALL" and sWhen = "BEFORE" then



' Check to see if Windows PE is running from a different drive than the first disk partition


' (as identified by OSD).
If this is the case, then this is a new machine and we can


' repartition and format the drive.



If iRepartition = "Y" then



If Left(objOSD("OSDTARGETDRIVE"), 2) <> Left(wshEnv("SystemDrive"), 2) then



' First run DISKPART



LogInfo sLogFile, "USEREXIT: About to run Diskpart.", LogTypeInfo


iRetVal = wshShell.Run("DISKPART.EXE /s """ & sThisScriptDir & "\ZTIDiskPart.txt""", 0, true)


If iRetVal <> Success then


LogInfo sLogFile, "USEREXIT: ERROR - Diskpart returned a non-zero return code, rc = " & iRetVal, LogTypeError


UserExit = iRetVal


EXIT FUNCTION


End if



' Wait a few seconds



WScript.Sleep 5000




' Now run a quick format



LogInfo sLogFile, "USEREXIT: About to run quick format.", LogTypeInfo


iRetVal = wshShell.Run("FORMAT C: /FS:NTFS /V:OSDisk /Q /Y", 0, true)


iRetVal = wshShell.Run("FORMAT d: /FS:NTFS /V:OSDisk /Q /Y", 0, true)


iRetVal = wshShell.Run("FORMAT e: /FS:NTFS /V:OSDisk /Q /Y", 0, true)


If iRetVal <> Success then


LogInfo sLogFile, "USEREXIT: ERROR - Quick format returned a non-zero return code, rc = " & iRetVal, LogTypeError


UserExit = iRetVal


EXIT FUNCTION


End if


Else


LogInfo sLogFile, "USEREXIT: Windows PE is running from the system drive, must be a refresh.", LogTypeInfo


End if




Else


LogInfo sLogFile, "USEREXIT: No user exit processing is required.", LogTypeInfo


End if



end if



UserExit = Success


End Function

附录B:“CustomSettings.ini”脚本范例
[Settings]
Priority= DefaultGateway, SQL, RoleQuery, ComputerQuery, MACADDRESS, Default
CustomKeysUserData=UDShare,UDDir,UDProfiles,SLShare,OSInstall,Packages(*),Administrators(*),DriverPaths(*),PowerUsers(*),Role,Repartition
CustomKeysSysprep=ComputerName,TimeZone,JoinDomain,MachineObjectOU
OSDVariableKeys=OSDINSTALLSILENT,OSDINSTALLPACKAGE,OSDINSTALLPROGRAM,OSDNEWMACHINENAME
ScanStateArgs=/i:updateuser.inf /i:userdata.inf /v:7 /c
LoadStateArgs=/v:7 /c
UserExit=ZTIUserExit.vbs

[Default]
ComputerName=%OSDNEWMACHINENAME%
UDDir=%OSDCOMPUTERNAME%
CaptureGroups=No

[DefaultGateway]
192.168.11.1=NYC

[NYC]
SQLDefault=DB_BDD

[DB_BDD]
SQLServer=smsroot
Database=BDDAdminDB
Table=BDDAdminCore
Parameters=MacAddress

[RoleQuery]
SQLDefault=DB_RoleQuery

[ComputerQuery]
SQLDefault= DB_ComputerQuery

[DB_RoleQuery]
SQLServer=smsroot
Database=BDDAdminDB
Table=RolePackages
Parameters=Role
SQLShare=Logs

[DB_ComputerQuery]
SQLServer=smsroot
Database=BDDAdminDB
Table=ComputerPackages
Parameters=MacAddress
SQLShare=Logs

[SMS]
SQLServer=smsroot
Database=SMS_one
Table=v_Program
Parameters=PackageID,ProgramName

[SysprepInfMapping]
ComputerName=UserData
TimeZone=GuiUnattended
JoinDomain=Identification
MachineObjectOU=Identification
yangzhip - 2007-12-20 9:37:00


引用:

' Now run a quick format

LogInfo sLogFile, "USEREXIT: About to run quick format.", LogTypeInfo


iRetVal = wshShell.Run("FORMAT C: /FS:NTFS /V:OSDisk /Q /Y", 0, true)


iRetVal = wshShell.Run("FORMAT d: /FS:NTFS /V:OSDisk /Q /Y", 0, true)


iRetVal = wshShell.Run("FORMAT e: /FS:NTFS /V:OSDisk /Q /Y", 0, true)


魔王,既然所有的硬盘都需要格式化,何必不直接重新分区?我个人建议此处只格式化C盘,其他盘保持原样!

另:能否在对新硬盘分区的时候,根据新硬盘的大小来决定如何分区,现在硬盘容量大小相异很多,一个diskpart脚本是否难以满足我们的需要?
magicking - 2007-12-21 17:43:00
看我的标题,我这个解决方案是为了处理ZTI过程中分区不灵活的.
因为ZTI中默认脚本,如果使用光盘或者RIS的引导安装会自动对硬盘进行分区操作不够灵活,我是多加了个判断,到ZTI数据库中判断是否分区,加大了它的灵活机制
yangzhip - 2007-12-21 18:47:00
我希望的是在此基础是能再有所扩展,让灵活机制更加灵活!
magicking - 2007-12-21 21:21:00
谢谢意见我再改进下 :-)
pcmac - 2008-1-3 19:11:00
谁给写个关于ZTI的东西,刚开始搞就被他的自动分区把硬盘全格了,哭啊...
magicking - 2008-2-14 10:15:00
说来听听你是 什么地方出问题了
yangzhip - 2008-2-14 16:38:00
灵活运用,不要死搬硬套!
happyokok - 2008-3-21 11:36:00
看来最好先在虚拟机环境中学习。
Ninja - 2008-4-8 11:53:00
ZTI的分区脚本在ZTIDiskpart.txt可以找到.
这是我的基于实际环境修改的,只格式化C盘,其余分区保留不动

select disk 0
select partiton 1
format fs=ntfs quick
assign letter=c:
active
exit

PS:注意!因为有一些品牌的笔记本有隐藏分区,请千万看清楚,否则Partition这一步会报错.
magicking - 2008-4-12 16:37:00
我这个解决方案是用来在BDD 2.5的环境下进行多分区控制的,用来优化分区的配置,不过现在已经用不着了,mdt和bdd 2007已经多分区做了个一个单独的任务序列功能非常完整
digua - 2008-6-5 17:11:00
:default2:
我在做的过程中分区的时候在perinstall过程中出错,帮忙看看原因
我的硬盘是快新硬盘,什么都没有,按照你的方法就这里的时候就出错
whlgzw - 2008-7-18 21:52:00
好东西 ,,,,,
1
查看完整版本: ZTI基于SQL判断计算机重新分区解决方案