Mar 14 2009
Freebsd7.1 Iscsi Initiator 配置
1、加载Iscsi Initiator 模块
freebsd从7.0开始已经包含了Iscsi Initiator ,不需要安装后再使用,但在使用前,需要加载模块。
# kldload -v iscsi_initiator.ko
如果想以后开机后自动加载,则
#vi /boot/loader.conf
# Beginning of the iSCSI block added by david@09.03.13
iscsi_initiator_load=”YES”
2、查找iscsi存储
# iscontrol -v -d targetaddress=192.168.130.101 initiatorname=nxl
PS:192.168.130.101为存储IP,initiatorname可以省略,省略时默认为:iqn.2005-01.il.ac.huji.cs:
如果正常会显示类似信息:
TargetName=iqn.1984-05.com.dell:powervault.6001ec9000e7791b00000000489e9368
TargetAddress=192.168.130.101:3260,1
保证freebsd能ping 通存储。
3、在存储上做会话映射主机及虚拟磁盘
此步骤因不同的存储进行配置
4、加入iscsi存储
#iscontrol targetaddress=192.168.130.101 initiatorname=nxl TargetName=iqn.1984-05.com.dell:powervault.6001ec9000e7791b00000000489e9368
如果正常,会显示类似信息
iscontrol[8146]: running
iscontrol[8146]: (pass0:iscsi0:0:0:0): tagged openings now 0
iscontrol[8146]: cam_open_btl: no passthrough device found at 0:0:1
iscontrol[8146]: cam_open_btl: no passthrough device found at 0:0:2
iscontrol[8146]: cam_open_btl: no passthrough device found at 0:0:3
iscontrol: supervise starting main loop
使用camcontrol devlist可以显示系统当时的设备或使用dmesg查看会显示系统有存储设备找到。类似:
da0 at iscsi0 bus 0 target 0 lun 0
da0:
5、对存储进行分区等操作
使用sysinstall,
Select Custom > 3 Partition > Select iSCSI device name such as da1. Once formatted just mount device, enter:
在使用中我使用dell md3000i 分了1.9T的空间,提示
WARNING: A geometry of 253981/255/63 for da0 is incorrect. Using |
|a more likely geometry. If this geometry is incorrect or you |
|are unsure as to whether or not it’s correct, please consult |
|the Hardware Guide in the Documentation submenu or use the |
|(G)eometry command to change it now. |
| |
|Remember: you need to enter whatever your BIOS thinks the |
|geometry is! For IDE, it’s what you were told in the BIOS |
|setup. For SCSI, it’s the translation mode your controller is |
|using. Do NOT use a “physical geometry”.
5.1#dd if=/dev/zero of=/dev/da0 bs=1k count=1
用这个命令把磁盘阵列的主引导区删除,之后可用
#fdisk /dev/da0 命令检查,可看到cylinders, heads, sectors还是原先BIOS不认的数值,不管它。
5.2.强行设置分区
#fdisk –i /dev/da0
为了确保容量不变,要根据交互界面提示,输入上述cylinders, heads, sectors值,一路确认或者根据实际情况做下去,其中文件系统的sysid选择165。(我试过GPT,sysid为238,也是可以的。)
5.3.创建新文件系统
#newfs –U /dev/da0,选择softupdate支持
5.4.安装文件系统
#mount /dev/da0 /where_I_like_to_mount
df -h 显示1.8T空间,估计因为计算方法不一样所以空间大小显示不一,下次有机会时使用GPT分区测试一下,看看是不是这个原因。
GPT分区指南:
GPT 分区
创建一个新的空的GPT
gpt create -f /dev/da0
-f 清除MBR及分区表
清除一个已经存在的非空的GPT
gpt destroy /dev/da0
将一个新的分区加入分区表
gpt add -t ufs /dev/da0
-b 指定分区的开始扇区数
-i 指定使用GPT表中的一个空闲entry,默认第一个
-s 指定分区大小,不指定则使用全部空间
从分区表删除指定分区
gpt remove [b|i|s|t] /dev/da0
设定卷标
gpt label -a -l bigs /dev/da0
-a all partitions should be labeled
-b label the partition that starts at the given block number
-i label the partition with the given partition number
对独占整个磁盘的分区可以简单地执行:
newfs -U /dev/da0
6.开机自动加载ISCSI存储
不少文章这样处理:
# vi /etc/iscsi.conf
Append config directives as follows:
officeiscsi {
authmethod = CHAP
chapIName = YOUR-ISCSI-USERNAME
chapSecret = YOUR-ISCSI-PASSWORD
initiatorname = nxl
TargetName = iqn.XYZZZZZZZZZZZZZ # whatever “iscontrol -v -d ” gives you
TargetAddress = 192.168.1.100:3260,1 # your iscsi server IP
}Save and close the file.
Where,
officeiscsi { : Start config for iSCSI.
authmethod : Set authentication method to chap
chapIName : Your username
chapSecret : Your password
initiatorname : if not specified, defaults to iqn.2005-01.il.ac.huji.cs:
TargetName : is the name by which the target is known, not to be confused with target address, either obtained via the target administrator, or from a discovery session.
TargetAddress : is of the form domainname[:port][,portal-group-tag] to quote the RFC: The domainname can be specified as either a DNS host name, a dotted-decimal IPv4 address, or a bracketed IPv6 address as specified in [RFC2732].
} : End of config
Start an iSCSI session
The following command will read options from /etc/iscsi.conf, use the targetaddress found in the block nicknamed myiscsi, login and negotiate whatever options are specified, and start an iscsi-session.
# iscontrol -c /etc/iscsi.conf -n officeiscsi
also need to update /etc/fstab file:
/dev/da0 /iscsi ufs rw 3 3
但我使用iscontrol -c /etc/iscsi.conf -n officeiscsi命令就是不能正确加载存储,所以我采用如下方法:
vi /usr/local/etc/rc.d/iscis.sh
iscontrol targetaddress=192.168.130.101 TargetName=iqn.1984-05.com.dell:powervault.6001ec9000e7791b00000000489e9368
sleep 60
mount /dev/da0 /iscsi/
让它开机后加载。但这个脚本不理想,在关机时没有自动 umount,我对shell的学习还不够,等有时间时再完善一下脚本,也希望shell达人指点一二。
转载原创文章请注明,转载自:Tuifei.com[http://www.tuifei.com]
本文链接: http://www.tuifei.com/2009/03/14/freebsd71-iscsi-initiator.htm