win2003系统网络安装——基于linux+pxe+dhcp+tftp+samba+ris
原文發表于:2010-09-16
轉載至cu于:2012-07-21
一.原理簡介
PXE(preboot execute environment)工作于Client/Server的網絡模式,支持工作站通過網絡從遠端服務器下載鏡像,并由此支持來自網絡的操作系統的啟動。啟動過程中,終端由DHCP服務器分配IP地址,再用TFTP(trivial file transfer protocol)等協議下載存在于服務器(NFS,FTP,HTTP, SAMBA等)的操作系統內核和文件系統等到本機內存中并執行,由此完成終端基本軟件設置,從而引導預先安裝在服務器中的終端操作系統。
RIS(遠程安裝服務,Remote Installation Services) 是windows server的可選服務,利用RIS可以讓管理員很方便地為客戶端部署操作系統。
二.環境說明
server os:
CentOS 5.4 i386
server soft:
dhcp, tftp, samba, ris-linux
可以使用yum安裝:
yum –y install dhcp* yum –y install tftp* yum –y install samba*server ip:
eth1: 192.168.0.1
client:
HP 360G5
windows 2003 sp2 cn enterprise
三.安裝配置過程簡介
1. 配置DHCP
more /etc/dhcpd.confddns-update-style interim; ignore client-updates; allow booting; allow bootp;subnet 192.168.0.0 netmask 255.255.255.0 {option routers 192.168.0.1;option subnet-mask 255.255.255.0;option domain-name-servers 192.168.0.1;option time-offset -18000; # Eastern Standard Timerange dynamic-bootp 192.168.0.10 192.168.1.254;default-lease-time 21600;max-lease-time 43200;# Group the PXE bootable hosts # PXE-server configuration directionnext-server 192.168.0.1; #指向nfs服務器filename "/pxelinux.0"; #/tftp根目錄下的啟動引導文件 }重啟dhcp服務:
/etc/init.d/dhcpd restart?2. 配置TFTP
more /etc/xinetd.d/tftp# default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems.service tftp {socket_type = dgramprotocol = udpwait = yesuser = rootserver = /usr/sbin/in.tftpd#-s指定tftp根目錄, -m指定一個規則文件, -vv輸出tftp的log到/var/log/message server_args = -u nobody -s /tftpboot -m /tftpboot/rules -vv#默認yes,關閉disable = no per_source = 11cps = 100 2flags = IPv4 }重啟tftp服務:
/etc/init.d/xinetd.restart查看tftp服務是否啟動:
chkconfig –list | grep tftp?3. 建立TFTP的rules文件
Linux下區分大小寫,但windows不區分,為免混亂,將所有查找文件內容統一改成小寫。
more /tftpboot/rulesri ^[a-z]: # Remove "drive letters" rg \\ / # Convert backslashes to slashes rg \# @ # Convert hash marks to @ signs rg /../ /..no../ # Convert /../ to /..no../ rg A a rg B b rg C c rg D d rg E e rg F f rg G g rg H h rg I i rg J j rg K k rg L l rg M m rg N n rg O o rg P p rg Q q rg R r rg S s rg T t rg U u rg V v rg W w rg X x rg Y y rg Z z r ^/(.*) \1?4. 配置SAMBA
windows的ris安裝是通過windows共享文件的方式進行文件傳輸,在linux下可以通過samba實現與windows進行文件共享,進而實現ris安裝windows。
編輯samba配置文件:/etc/samba/smb.conf
#全局配置 [global]null passwords = trueworkgroup = WORKGROUPserver string = Samba Server Version %vsecurity = sharedns proxy = noload printers = nodisable spoolss = yesdebug level = 2log file = /var/log/samba/%m.logmax log size = 0#共享配置 [wininstall] comment = Windows 2003 Installpath = /tftpbootbrowsable = trueread only = nowriteable = yesguest ok = yes重啟samba服務:
/etc/init.d/smb restart?5. 配置啟動需要的文件
上傳windows2003的鏡像或者文件到服務器。這里使用上傳鏡像然后掛載。
mount /root/win2003cn.iso /mnt –o loop mkdir /tftpboot/win2k3 cd /mnt cp –a * /tftpboot/win2k3?
下面需要解壓一些iso中的文件,可以使用cabextract。
下載頁:http://www.cabextract.org.uk/
可以根據版本下載。
wget http://www.cabextract.org.uk/cabextract-1.3-1.i386.rpm rpm –ivh cabextract-1.3-1.i386.rpm?
配置windows ris 啟動文件:
cd /tftpboot cabextract win2k3/i386/startrom.n1_ #解壓 sed -i -e 's/NTLDR/W2K3L/gi' startrom.n12 #直接替換startrom.n12文件中” NTLDR”為” W2K3L” #W2K3L: windows 2003 Setup Loader mv startrom.n12 /tftpboot/w2k3.0 #w2k3.0: windows 2003 pxe loader cabextract win2k3/i386/setupldr.ex_ sed -i -e 's/winnt\.sif/wi2k3\.sif/gi' setupldr.exe sed -i -e 's/ntdetect\.com/ntdetect\.2k3/gi' setupldr.exe mv setupldr.exe /tftpboot/w2k3l cp win2k3/i386/ntdetect.com /tftpboot/ntdetect.2k3 #ntdetect.2k3: windows 2003 ntdetect.com?
配置pxe啟動鏡像:
cp /usr/lib/syslinux/pxelinux.0 /tftpboot # pxelinux.0依賴于syslinux,沒有安裝使用yum:yum –y install syslinux* # pxelinux.0是PXE啟動引導文件?
配置pxe啟動加載文件:
pxelinux.0啟動中,讀取同目錄先pxelinux.cfg文件夾下的配置文件以確定它應該怎么加載啟動文件。
mkdir /tftpboot/pxelinux.cfgvim /tftpboot/pxelinux.cfg/defaultdefault win2k3label win2k3kernel w2k3.0 #與ris啟動文件匹配?
建立安裝應答文件:
這個文件很強大,提供的參數不是對系統很了解的人并不一定全知道,我們只需要知道對我們有用的參數。當然,沒事的時候也可以慢慢研究。J
vim /tftpboot/wi2k3.sif[data] AutoPartition = "0" #關閉自動分區,2003還不能完全自動分區,這點需要手工操作。如果一定要跳過這一步,需要和后面的參數配合,并且2003提供的只有將全盤劃成根盤(c:\) floppyless = "1" msdosinitiated = "1" UnattendedInstall = "Yes" OriSrc = \\192.168.0.1\wininstall\win2k3\i386 #注意samba和win安裝文件路徑 OriTyp = "4" LocalSourceOnCD = "1" DisableAdminAccountOnDomainJoin = "1"[SetupData] OsLoadOptions = "/fastdetect" SetupSourceDevice = "\Device\LanmanRedirector\192.168.0.1\wininstall\win2k3"[Unattended] UnattendMode = "FullUnattended" #使用unattended文件 FileSystem = "LeaveAlone" NtUpgrade = "No" OverwriteOemFilesOnUpgrade = "No" DriverSigningPolicy = "Ignore" UpdateInstalledDrivers = "Yes" ConfirmHardware = "No" ExtendOEMPartition = "0" TargetPath = "\WINDOWS" UnattendSwitch = "Yes" WaitForReboot = "No" CrashDumpSetting = "0" OemSkipEula = "Yes" OEMSkipWelcome = "1" InstallFilesPath = "\\192.168.0.1\wininstall\win2k3\i386" LegacyNIC = "1" OemPreInstall = "Yes" #加載OEM中的驅動[UserData] ProductKey = "M4VQK-HVTD9-42RQX-2DJP2-23KVM" FullName = "admin" OrgName = "SDO" ComputerName = C1ZJ[GuiUnattended] AdminPassword = WD#sd7258 EncryptedAdminPassword = "No" OEMSkipRegional = "1" TimeZone = "220" OemSkipWelcome = "1"[LicenseFilePrintData] AutoMode=PerServer AutoUsers=5[Identification] JoinWorkgroup = WORKGROUP#這里和分區有關 [RemoteInstall] Repartition = "NO" UseWholeDisk = "No"[Networking] InstallDefaultComponents = "Yes"?
#以下的默認文件中沒有,和服務器raid卡驅動有關:
[MassStorageDrivers] "Windows Driver for Smart Array SAS/SATA Controllers" = OEM[OEMBootFiles] cp011324.xml cpqsetup.exe generic.dll hpcisss2.cat hpcisss2.sys hpcissx2.inf install.xml txtsetup.oem#以下是系統安裝完畢后第一次啟動執行的批處理文件 [GuiRunOnce] %systemdrive%\preinstall\runonce.cmd6. 驅動加載相關
因為是服務器的安裝,所以需要提前加載一些驅動,自動安裝的麻煩就在此。
?
pxe安裝需要加載網卡驅動(引導和文件傳輸是兩個階段,傳輸文件階段開始時要先把網卡驅動加載起來的)。
查到服務器使用的Broadcom NetXtreme II網卡,而Broadcom提供在ris下的驅動:
wget http://www.broadcom.com/docs/driver_download/NXII/win_2k3_RIS-5.0.0.zip mkdir /tftpboot/nicdrive unzip win_2k3_RIS-5.0.0.zip -d /tftpboot/nicdrive?
驅動網卡,需要有一個binl server,binl讀取所有新的與網絡接口卡相關的.inf文件,并在映像中創建.pnf文件。
?binl server下載:http://oss.netfarm.it/guides/
wget http://oss.netfarm.it/guides/ris-linux-0.4.tar.gz tar –zxvf ris-linux-0.4.tar.gz cd ris-linux-0.4 ./infparser.py /tftpboot/nicdrive/Server/W2K3_W2K8/RIS/ ./binlsrv.py -d #-d 后臺運行,不能停止此程序 cp /tftpboot/nicdrive/Server/W2K3_W2K8/RIS/b06nd51x.sys /tftpboot/win2k3/i386
這里是Broadcom提供有專門的ris網卡驅動,如果沒有,可以將windows需要的網卡驅動(不限于網卡)的.inf文件放在/tftpboot/inf文件夾下,執行:
./infparser.py /tftpboot/inf ./binlsrv.py?
然后是加載raid卡驅動(其他驅動也適用,關鍵是能否找到相關文件)。
光盤安裝windows在開始時藍色屏幕上有一個按F6的提示,提示是通過軟盤加載磁盤驅動,這類驅動是windows系統中的驅動,可以下載好windows驅動,解壓好驅動放在一個指定的目錄,再通過應答文件,一般可以加載上這類驅動。這類驅動加載完畢后不必在系統中再安裝。加載這類驅動有注意點:文件要有正確的oem數字簽名(一般提供驅動的廠商都帶數字簽名),亂改動這類文件,同時不在配置文件中寫明去掉數字簽名認證,是不能加載的。
?
下載HP的raid卡驅動(已經查明型號:Smart Array E200i, 一般一個驅動支持多種類型的raid卡):
?
在自動應答文件wi2k3.sif末尾添加:
[MassStorageDrivers] "Windows Driver for Smart Array SAS/SATA Controllers" = OEM #”Windows Driver for Smart Array SAS/SATA Controllers”可以查看textmode文件夾下的txtsetup.oem文件,名字保持一致[OEMBootFiles] cp011324.xml cpqsetup.exe generic.dll hpcisss2.cat hpcisss2.sys hpcissx2.inf install.xml txtsetup.oem #textmode下的所有文件名字,一般自動安裝的驅動文件.inf, .cat, .sys#新增參數,修改[Unattended]字段 OemPreInstall = "Yes"7. 補丁,前期包,其他驅動的加載
完成以上操作就已經可以安裝系統了,但是系統安裝完成后需要做一些前期操作,像打補丁,打安全包,或者一些驅動(芯片組,網卡,顯卡等在上面沒有加載到系統中的一些驅動)。
這些優化的問題可以利用批處理文件解決。這些批處理文件最好是在windows下編輯好再上傳到服務器,否則會出現格式問題導致文件不能執行。
?
首先需要在$oem$目錄下建立cmdlines.txt文件,這個文件會在系統安裝過程的注冊組件時間段(即還剩13分鐘左右時)調用:
vim /tftpboot/win2k3/$oem$/cmdlines.txt#文件的內容以" [COMMANDS]"為起頭;使用引號“”來標記下面需要執行的每條命令。 注意路徑問題,install.cmd的路徑為cmdlines.txt的同級目錄; #這里還可以添加注冊表。 [COMMANDS] "install.cmd"以下是此時使用的install.cmd:
@ echo off title Windows Install Prepackage, Hotfix and Drives @ color 0a@echo 安裝WINDOWS_2003_SP2補丁, 大約需要20分鐘... 2>>%HOMEDRIVE%/errlog.txt @ cd hotfix 2>>%HOMEDRIVE%/errlog.txt WindowsServer2003-KB914961-SP2-x86-CHS.exe /quiet /norestart WindowsUpdateAgent30-x86.exe /quiet /norestart WindowsServer2003-KB925902-x86-CHS.exe /quiet /norestart WindowsServer2003-KB930178-x86-CHS.exe /quiet /norestart WindowsServer2003-KB931784-x86-CHS.exe /quiet /norestart WindowsServer2003-KB932168-x86-CHS.exe /quiet /norestart WindowsServer2003-KB935839-x86-CHS.exe /quiet /norestart WindowsServer2003-KB935840-x86-CHS.exe /quiet /norestart WindowsServer2003-KB933729-x86-CHS.exe /quiet /norestart WindowsServer2003-KB943460-x86-CHS.exe /quiet /norestart WindowsServer2003-KB921503-x86-CHS.exe /quiet /norestart WindowsServer2003-KB938829-x86-CHS.exe /quiet /norestart WindowsServer2003-KB941644-x86-CHS.exe /quiet /norestart WindowsServer2003-KB943485-x86-CHS.exe /quiet /norestart WindowsServer2003-KB942830-x86-CHS.exe /quiet /norestart WindowsServer2003-KB942831-x86-CHS.exe /quiet /norestart WindowsServer2003-KB943055-x86-CHS.exe /quiet /norestart WindowsServer2003-KB946026-x86-CHS.exe /quiet /norestart WindowsServer2003-KB941693-x86-CHS.exe /quiet /norestart WindowsServer2003-KB944338-x86-CHS.exe /quiet /norestart WindowsServer2003-KB945553-x86-CHS.exe /quiet /norestart WindowsServer2003-KB948590-x86-CHS.exe /quiet /norestart WindowsServer2003-KB951748-x86-CHS.exe /quiet /norestart WindowsServer2003-KB950974-x86-CHS.exe /quiet /norestart WindowsServer2003-KB952954-x86-CHS.exe /quiet /norestart WindowsServer2003-KB938464-x86-CHS.exe /quiet /norestart windowsserver2003-kb953155-x86-chs.exe /quiet /norestart windowsserver2003-kb954211-x86-chs.exe /quiet /norestart windowsserver2003-kb956803-x86-chs.exe /quiet /norestart windowsserver2003-kb956841-x86-chs.exe /quiet /norestart windowsserver2003-kb957095-x86-chs.exe /quiet /norestart WindowsServer2003-KB958644-x86-CHS.exe /quiet /norestart WindowsServer2003-KB957097-x86-CHS.exe /quiet /norestart WindowsServer2003-KB956802-x86-CHS.exe /quiet /norestart WindowsServer2003-KB958687-x86-CHS.exe /quiet /norestart WindowsServer2003-KB958690-x86-CHS.exe /quiet /norestart WindowsServer2003-KB960225-x86-CHS.exe /quiet /norestart WindowsServer2003-KB952004-x86-CHS.exe /quiet /norestart WindowsServer2003-KB956572-x86-CHS.exe /quiet /norestart WindowsServer2003-KB960803-x86-CHS.exe /quiet /norestart WindowsServer2003-KB961501-x86-CHS.exe /quiet /norestart WindowsServer2003-KB968537-x86-CHS.exe /quiet /norestart WindowsServer2003-KB970238-x86-CHS.exe /quiet /norestart WindowsServer2003-KB958469-x86-CHS.exe /quiet /norestart WindowsServer2003-KB971032-x86-CHS.exe /quiet /norestart WindowsServer2003-KB971657-x86-CHS.exe /quiet /norestart WindowsServer2003-KB967723-x86-CHS.exe /quiet /norestart WindowsServer2003-KB953298-x86-CHS.exe /quiet /norestart WindowsServer2003-KB958869-x86-CHS.exe /quiet /norestart WindowsServer2003-KB971486-x86-CHS.exe /quiet /norestart WindowsServer2003-KB975467-x86-CHS.exe /quiet /norestart WindowsServer2003-KB969947-x86-CHS.exe /quiet /norestart WindowsServer2003-KB974392-x86-CHS.exe /quiet /norestart WindowsServer2003-KB972270-x86-CHS.exe /quiet /norestart WindowsServer2003-KB971468-x86-CHS.exe /quiet /norestart WindowsServer2003-KB975713-x86-CHS.exe /quiet /norestart WindowsServer2003-KB977165-x86-CHS.exe /quiet /norestart WindowsServer2003-KB978251-x86-CHS.exe /quiet /norestart WindowsServer2003-KB979683-x86-CHS.exe /quiet /norestart WindowsServer2003-KB980232-x86-CHS.exe /quiet /norestart WindowsServer2003-KB979559-x86-CHS.exe /quiet /norestart WindowsServer2003-KB980218-x86-CHS.exe /quiet /norestartif %errorlevel% EQU 0 ( @ echo 補丁安裝成功, 繼續安裝prepackge... 2>>%HOMEDRIVE%/errlog.txt @ cd .. @ goto prepackge 2>>%HOMEDRIVE%/errlog.txt ) else ( @ echo 補丁安裝失敗, 繼續安裝prepackge... 2>>%HOMEDRIVE%/errlog.txt @ cd .. @ goto prepackge 2>>%HOMEDRIVE%/errlog.txt ):prepackge@ echo 安裝Prepackage中... 2>>%HOMEDRIVE%/errlog.txt @ cd windows_2010628 2>>%HOMEDRIVE%/errlog.txt install.bat /qn 2>>%HOMEDRIVE%/errlog.txt if %errorlevel% EQU 0 ( @ echo Prepackage安裝成功 2>>%HOMEDRIVE%/errlog.txt @ cd .. @ goto end 2>>%HOMEDRIVE%/errlog.txt ) else ( @ echo Prepackage安裝失敗 2>>%HOMEDRIVE%/errlog.txt @ cd .. @ goto end 2>>%HOMEDRIVE%/errlog.txt ):end批處理文件中的hotfix(出重要的補丁時可以下載放到這,但別忘記了修改批處理文件),windows_20100628(安全部門制作的安全包解壓所得)文件夾和install.cmd位于同級目錄,這里就是在/tftpboot/win2k3/$oem$/下。
其中在組件注冊時不能執行的的命令或者程序(包括有交互而不適合執行的程序),可以通過在自動應答文件wi2k3.sif中添加[GuiRunOnce]字段,在第一次登錄系統時執行腳本來完成一些短時間能夠完成的操作。
在/tftpboot/win2k3/$oem$/下建立文件夾$1,這個文件夾下的所有文件(夾)會在安裝過程中復制到兄根目錄,即C盤。
mkdir /tftpboot/win2k3/$oem$/$1 cd mkdir /tftpboot/win2k3/$oem$/$1 mkdir preinstall在windows平臺編輯一個批處理文件runonce.cmd,上傳到preinstall文件夾下:
@ echo off title Windows GuiRunOnce Install Drives @ color 0aecho starting drive echo. @ cd\ @ cd preinstall @ cd hp call bp000588.cmdecho. echo starting pcanywhere @ cd\ @ cd preinstall @ cd pcanywhere_10.5.1cn start /wait SymantecpcAnywhere.msi echo. shutdown -r -t 0 exit這里我將HP的所有驅動放到hp文件夾下(因為我也分不清楚哪些需要,哪些不需要,就只有全部上傳了,L),pcanywhere安裝文件放到pcanywhere_10.5.1cn文件夾下。所有這些文件夾統一放到preinstall文件夾下(有需要還可以增加,修改runonce.cmd即可)
最后在自動應答文件wi2k3.sif中添加:
#注意路徑 [GuiRunOnce] %systemdrive%\preinstall\runonce.cmd?8. 進階
上面只是提到32為系統,對于64位系統,我們可以在/tftpboot下建立win2k3_64文件夾,將iso下的文件拷到此文件夾下。
cabextract win2k3_64/i386/startrom.n1_ #解壓 sed -i -e 's/NTLDR/W2K3L_64/gi' startrom.n12 #直接替換startrom.n12文件中" NTLDR"為" W2K3L_64" #W2K3L_64: windows 2003 64bit Setup Loader mv startrom.n12 /tftpboot/w2k3_64.0 # w2k3_64.0: windows 2003 bit pxe loader cabextract win2k3_64/i386/setupldr.ex_ sed -i -e 's/winnt\.sif/wi2k3_64\.sif/gi' setupldr.exe sed -i -e 's/ntdetect\.com/ntdetect\.2k3_64/gi' setupldr.exe mv setupldr.exe /tftpboot/w2k3l_64 cp win2k3_64/i386/ntdetect.com /tftpboot/ntdetect.2k3_64 # ntdetect.2k3_64: windows 2003 bit ntdetect.comsamba服務器需要建立針對64位系統的共享目錄,如[win64install];同時建立自動應答文件/tftpboot/wi2k3_64.sif 。這兩者當中的路徑問題請一定要注意一一對應。
pxe加載/tftpboot/pxelinux.cfg/default文件,需要有系統選擇時,可以修改文件:
vim /tftpboot/pxelinux.cfg/defaultdefault win2k3 timeout 30 label win2k3 kernel w2k3.0 label win2k3_64 kernel w2k3_64.0其實不管是32位還是64位系統,啟動文件都是一樣的,這些都可以不用修改,只是客戶端從服務器下載文件的路徑一定要區分32位和64位。
啟動順序:pxelinux.0—> default—> pxe loader(w2k3.0, startrom.n12)—>setup loader(w2k3l, setupldr.exe) —> ntdetect.com(ntdetect.2k3) and winnt.sif(wi2k3.sif)
9. 小結
關于驅動加載的問題,如果我們參照一臺已經裝好windows2003系統的服務器的硬件驅動(重要的是芯片組,網卡,顯卡等)可以看出這些驅動主要由.sys, .dll, .inf(驅動信息文件), .cat(驅動簽名文件)等文件組成。如果能收集到這些文件放到系統安裝文件里,就不用事后打驅動那么麻煩。但這個過程目前我還沒有摸透,這點還是有很大的改進空間的。
使用這套系統安裝windows2003系統,加上打補丁(大概超過20分鐘)的時間,前后在40分鐘左右。我看過安全部門制作的安全包,系統正式上線后應該是可以自動打補丁的。如果有可能的話,可以把打補丁這個環節去掉。這樣利用這套系統安裝一臺windows2003系統大概是20分鐘,批量安裝更能體現效果。
轉載于:https://www.cnblogs.com/netonline/p/7066867.html
總結
以上是生活随笔為你收集整理的win2003系统网络安装——基于linux+pxe+dhcp+tftp+samba+ris的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Pycharm 创建 Django ad
- 下一篇: 用C#操作word替换字符,用spire