Thursday, June 21, 2007
如何使用PXE (in FreeBSD) 安裝 Windows XP
真是太苦了,花了兩天的時間終於成功地用PXE把Windows XP安裝到Toshiba R100上。這故事告訴我們,以後買NB還是要買有光碟機的好,否則過了保固想要/必須重灌就真的是欲哭無淚。
我參考了三份大文件,分別是
使用PXE安裝作業系統簡單的說,是當電腦開機後,由支援PXE的網路卡去發出DHCP要求,DHCP伺服器回應給它一個IP addr.並且告訴它之後去跟誰要開機用的image,接著就使用tftp取得開機用image後,再把安裝所需的檔案從伺服器抓回來,此時抓取可以使用網路芳鄰(samba in FreeBSD)。之後的步驟就不再詳細解釋其意義,有興趣請參考 [1], [2], 和 [3]。
※安裝DHCP、tftp和samba servers
※建立PXEboot環境
※準備安裝Windows的開機image和相關檔案
接下來確定dhcpd、samba和tftpd都有在跑後
正常的狀況下,binlsrv.py會顯示的訊息如下
Good Luck & Enjoy :)
Updated June 21, 2007
小時後OS要好好學喔!否則... “小時後OS沒學好,長大不會用PXE”!
我參考了三份大文件,分別是
[1] PXEBoot裝肥多拉(Fedora), by yhsung另外還有一些雜七雜八的,主要是過程中發生一些問題不知該如何解,直接問Google大神。那些資料太多我也忘了該如何找起,就... XD 最後有一個很好用的
[2] 3 分鐘設好 PXE Boot on FreeBSD, by jnlin
[3] Remote Install WinXP from a FreeBSD box, by jnlin
[4] 檔名大寫換小寫,含子目錄, FreeBSD Chinese HOWTO這是因為Windows系統都不管大小寫的,但是UN*X系列會把大小寫看成不同的檔案,因此在之後的過程中,我們會把所有檔名變成小寫,順便把安裝過程中要求傳送的檔案通通改成小寫 [3]。
使用PXE安裝作業系統簡單的說,是當電腦開機後,由支援PXE的網路卡去發出DHCP要求,DHCP伺服器回應給它一個IP addr.並且告訴它之後去跟誰要開機用的image,接著就使用tftp取得開機用image後,再把安裝所需的檔案從伺服器抓回來,此時抓取可以使用網路芳鄰(samba in FreeBSD)。之後的步驟就不再詳細解釋其意義,有興趣請參考 [1], [2], 和 [3]。
※安裝DHCP、tftp和samba servers
$ cd /usr/ports/net/isc-dhcp3-server
$ make all install clean
$ cat /usr/local/etc/dhcpd.conf /* actually, you should edit it */
ddns-update-style none;
allow booting;
allow bootp;
option domain-name "example.org";
option domain-name-servers 140.113.235.107;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.20;
option routers 192.168.0.1;
next-server 192.168.0.2;
filename "pxelinux.0";
}
$ cd /usr/ports/ftp/tftp-hpa/
$ make all install clean
$ cat /etc/inetd.conf /* actually, you should edit it */
ssh stream tcp nowait root /usr/sbin/sshd sshd -i -4
tftp dgram udp wait root /usr/local/libexec/in.tftpd in.tftpd -v -m /tftpboot/rules -s /tftpboot
$ cd /usr/ports/net/samba3/
$ make all install clean
$ cat /usr/local/etc/smb.conf /* actually, you should edit it */
[global]
workgroup = mshome
server string = Samba Server
security = share
hosts allow = 192.168.0.
load printers = no
guest account = guest
log file = /var/log/samba/log.%m
max log size = 50
dns proxy = no
[reminst]
path = /tftpboot
browsable = true
read only = no
writable = yes
guest ok = yes
$ cat /etc/rc.conf /* actually, you should edit it */
defaultrouter="192.168.0.1"
hostname="freebsd.yalin.tw"
ifconfig_de0="inet 192.168.0.2 netmask 255.255.255.0"
keymap="us.iso"
inetd_enable="YES"
dhcpd_enable="YES"
samba_enable="YES"
※建立PXEboot環境
$ mkdir /tftpboot
$ cd /tftpboot
$ fetch http://freshmeat.net/redir/syslinux/10177/url_tgz/syslinux-2.11.tar.gz
$ tar zxvf syslinux-2.11.tar.gz
$ cd syslinux-3.51 /* the version number varies, depends on what you've downloaded */
$ cp pxelinux.0 ../
$ cp com32/modules/menu.c32 ../
$ cp memdisk/memdisk ../
$ mkdir /tftproot/pxelinux.cfg
$ cat /tftproot/pxelinux.cfg/default /* actually, you should edit it */
DEFAULT menu.c32
PROMPT 0
ALLOWOPTIONS 0
TIMEOUT 50
MENU TITLE PXELinux Menu
LABEL winxp
MENU LABEL winxp
kernel winxp.0
$ cat /tftpboot/rules /* actually, you should edit it */
ri ^[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
※準備安裝Windows的開機image和相關檔案
1. 把Windows光碟放進光碟機中(我是使用Windows XP + SP2)
$ mount_cd9660 /dev/acd0 /mnt /* it depends on your own device */
$ mkdir -p /tftpboot/winxp/i386
$ cp -R /mnt/i386/* /tftpboot/winxp/i386
$ umount /mnt
$ cd /tftpboot/winxp
$ cabextract i386/startrom.n1_
$ sed -i -e 's/NTLDR/XPLDR/g' startrom.n12
$ sed -i -e 's/ntldr/xpldr/g' startrom.n12
$ mv startrom.n12 ../winxp.0
$ cabextract /i386/setupldr.ex_
$ sed -i -e 's/winnt\.sif/winxp\.sif/g' setupldr.exe
$ sed -i -e 's/ntdetect\.com/ntdetect\.wxp/g' setupldr.exe
$ mv setupldr.exe ../xpldr
$ cp i386/ntdetect.com ../ntdetect.wxp
$ cat /tftpboot/winxp.sif /* actually, you should edit it */
[data]
floppyless = "1"
msdosinitiated = "1"
; Needed for second stage
OriSrc = "\\192.168.0.2\reminst\winxp\i386"
OriTyp = "4"
LocalSourceOnCD = 1
DisableAdminAccountOnDomainJoin = 1
[SetupData]
OsLoadOptions = "/fastdetect"
; Needed for first stage
SetupSourceDevice = "\Device\LanmanRedirector\192.168.0.2\reminst\winxp"
[UserData]
ComputerName = *
; if needed
;ProductID=
2. 置入drivers的inf檔
事實上這邊我不知道到底要放哪些drivers,所以我就耍狠,去找一台Windows SP2的PC,把C:\WINDOWS\inf整個燒出來。當然,還有欲重灌那台NB的網卡driver也要喔!(為此找好久QQ 台灣Toshiba sucks! XD)
假設drivers放在光碟中...
$ mount_cd9660 /dev/acd0 /mnt /* it depends on your own device */
$ cp -R /mnt/* /tftpboot/winxp/i386/
$ umount /mnt
$ cd /tftpboot/winxp
$ find ./ -depth | perl -ne 'chomp;m[^/]*$>;$d=$`;$_=$f=$&; s/([\x80-\xFF].)|(\w)/$1\l$2/g;system "mv",$d.$f,$d.$_ if $f ne $_'
$ cd /tftpboot
$ fetch http://oss.netfarm.it/guides/ris-linux-0.2.tar.gz
$ tar zxvf ris-linux-0.2.tar.gz
$ cd ris-linux-0.2
$ ./infparser.py ../winxp/i386
$ ./binlsrv.py
接下來確定dhcpd、samba和tftpd都有在跑後
$ /usr/local/etc/rc.d/isc-dhcpd restart就可以把NB打開囉!(廢話!要接網路線/跳線啊!)
$ /usr/local/etc/rc.d/samba restart
$ /etc/rc.d/inetd restart
正常的狀況下,binlsrv.py會顯示的訊息如下
freebsd# ./binlsrv.py
Succesfully loaded 1067 devices
Binlserver started... pid 18819
Recv NCQ len = 48
NCQ Driver request
[R] Mac address 00:08:0d:35:70:d1
[R] Vid: 0x8086
[R] Pid: 0x103d
[R] rev_u1 = 0x2
[R] rev_u2 = 0x0
[R] rev_u3 = 0x0
[R] rev = 0x83
[R] rev2 = 0x240
[R] subsys = 0x11179
[R] Source path: \\192.168.0.2\reminst\winxp
Checking PCI\VEN_8086&DEV_103D&SUBSYS_00011179
Found PCI\VEN_8086&DEV_103D&SUBSYS_00011179 in e100b325.inf
[S] Packet len = 0xc6 (198)
[S] Result code: 0x0
[S] type: 0x2
[S] base offset = 0x24 (36)
[S] drv_off = 0x70 (112)
[S] srv_off: 0x8a (138) -> 130 from start
[S] plen: 0x38 (56)
[S] p_off: 0x96 (150) -> 142 from start
[S] hid: PCI\VEN_8086&DEV_103D&SUBSYS_00011179 - Len 0x25 (37)
[S] drv: e100bnt5.sys - Len 0xc (12)
[S] srv: E100B - Len 0x5 (5)
[S] Description (REG_EXPAND_SZ [2]) = NoDesc
[S] Characteristics (REG_SZ [1]) = 132
[S] BusType (REG_SZ [1]) = 5
[S] Total Params: 3
Good Luck & Enjoy :)
Updated June 21, 2007
小時後OS要好好學喔!否則... “小時後OS沒學好,長大不會用PXE”!
Labels: 小技巧
Posted by smallredbean at 6:41 AM | 1 comments |






