FreeBSD搭建PXE + ISCSI无盘站

FreeBSD搭建PXE + ISCSI无盘站

本示例通过PXE启动ISCSI TARGER磁盘上的WINDOWS XP SP3系统

注: tftp的目录为 /data/tftproot iscsi tagate目录为 /data/iscsi TFTP服务器IP为192.168.1.253 路由器为:192.168.1.254 ISCSI服务器为192.168.1.253

初始化以上目录

test# mkdir -p /data/tftproot
test# mkdir -p /data//data/iscsi

一、安装相关软件

1、配置TFTP

test# ee /etc/inetd.conf

增加

tftp    dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /data/tftproot
tftp    stream  tcp     wait    root    /usr/libexec/tftpd      tftpd -l -s /data/tftproot

修改 rc.conf

test# ee /etc/rc.conf

增加

inetd_enable="YES"

2、安装isc-dhcp服务

test#  cd /usr/ports/net/isc-dhcp41-server/
test#  make install clean

配置isc-dhcp

test#cd /usr/local/etc/ 
test#cp dhcpd.conf.sample dhcpd.conf
test#ee dhcpd.conf

增加

option space gpxe;
option gpxe-encap-opts code 175 = encapsulate gpxe;
option gpxe.bus-id code 177 = string;
subnet 192.168.1.0 netmask 255.255.255.0 {
  range dynamic-bootp 192.168.1.40 192.168.1.60;
  option broadcast-address 192.168.1.255;
  option routers 192.168.1.254;
  option root-path "192.168.1.253:/"; #TFTP的下载地址,这里主要为了下载一些初始化文件如 boot.kpxe和boot.gpxe文件
  next-server 192.168.1.253; #此为TFTP的服务器地址,如果不写,客户端就会出现tftp://0.0.0.0/xxx的下载地址
  if not exists gpxe.bus-id {
  filename "boot.kpxe"; #boot.kpxe是带带ISCSI驱动的启动文件,从http://www.rom-o-matic.net/gpxe/gpxe-1.0.1/contrib/rom-o-matic/下载
  }else{
  filename "boot.gpxe";#启动脚本
  }
  server-name "test";
  server-identifier 192.168.1.253;}

在/etc/rc.conf 增加

dhcpd_enable="YES"
dhcpd_ifaces="bge0" #bge0为你使用的网卡,我这里是bge0,使用ifconfig 来查找

3、安装iscsi服务 具本教程可以查看http://people.freebsd.org/~rse/iscsi/iscsi.txt

这里要注意的是生成的iscsi的文件不要超过4G,因为gpxe暂时只支持到4G以下的分区

修改 istgt.conf

ee /usr/local/etc/istgt/istgt.conf

[Global]
  Comment "Global section"
  NodeBase "192.168.1.253"
  PidFile /var/run/istgt.pid
  AuthFile /usr/local/etc/istgt/auth.conf
  #文件存放的目录我们这里为/data/iscsi
  MediaDirectory /data/iscsi
  LogFacility "local7"
  Timeout 30
  NopInInterval 20
  DiscoveryAuthMethod Auto
  MaxSessions 16
  MaxConnections 6
  MaxR2T 32
  MaxOutstandingR2T 16
  DefaultTime2Wait 2
  DefaultTime2Retain 60
  FirstBurstLength 262144
  MaxBurstLength 1048576
  MaxRecvDataSegmentLength 262144
  InitialR2T Yes
  ImmediateData Yes
  DataPDUInOrder Yes
  DataSequenceInOrder Yes
  ErrorRecoveryLevel 0
[UnitControl]
  Comment "Internal Logical Unit Controller"
  AuthMethod CHAP Mutual
  AuthGroup AuthGroup10000
  Portal UC1 127.0.0.1:3261
  Netmask 127.0.0.1
[PortalGroup1]
  Comment "ANY IP"
  Portal DA1 0.0.0.0:3260
[InitiatorGroup1]
  Comment "Initiator Group1"
  InitiatorName "ALL"
  Netmask 192.168.1.0/24
[LogicalUnit1]
  Comment "OS VM XP"
  #TargetName 的内容就是gPxe后面用到指令的 iscsi:192.168.1.253::::192.168.1.253:vmwinxp 一至
  TargetName vmwinxp
  TargetAlias "VM WIN XP"
  Mapping PortalGroup1 InitiatorGroup1
  AuthMethod None
  AuthGroup AuthGroup1
  UseDigest Auto
  UnitType Disk
  LUN0 Storage /data/iscsi/vmwinxp 3GB

二、配置相关文件

1、在/data/tftpboot目录下创建boot.gpxe文件,内容如下

#!gpxe
sanboot iscsi:192.168.1.253::::192.168.1.253:vmwinxp

第一个192.168.1.253表示ISCSI服务所在的服务器
第二个192.168.1.253其实我这里取巧了,为了实验成功,避免使用了Initiator node name

2、从http://www.rom-o-matic.net/gpxe/gpxe-1.0.1/contrib/rom-o-matic/下载kpxe

此网页里有多个选择,我们选择kpxe,并选择undi,然后[get image]

把下载的文件改名成boot.gpxe上传到/data/tftproot目录

3、生成/data/iscsi/vmwinxp文件(3G)

test# dd if=/dev/zero of=/data/iscsi/vmwinxp bs=512 count=6291456

每块512个字节,共6291456块,合计3G

三、使用vm搭建一个XP

使用VM创建一个3G大小空间的虚拟机,并正常安装XP

安装完后,需要在XP上再加装 Initiator-2.08-boot-build3825-x86chk.exe (从微软官网上下载,记得是chk不是fre)

再加装sanbootconf.msi,从http://etherboot.org下载

安装完后,去掉的VM的硬盘,从网络启动就可以了

原文链接:http://wiki.freebsdchina.org/doc/pxe/gpxe/iscsi

发表评论

电子邮件地址不会被公开。 必填项已用*标注