introduction

Unit Goal

        了解ISCSI工作原理

        设置iSCSI目标

        配置一个iSCSIf启动程序

Unit Sections

        What is iSCSI?

        Key iSCSI Terms

        Creating an iSCSI Target

        Managing iSCSI initiators

        Using Disks Larger Than Two Terabytes

Hands-On Activities

        Create an iSCSI Target

        Configure an iSCSI initiator

        Using GUID Partition Tables

Unit Test

        Modify an iSCSI Target

What is iSCSI

        iSCSI(internet small computer system interface)是基于网络协议传输SCSI命令(CDBs,Command Descriptor Blocks)。这使iSCSI不仅仅局限于使用在本地LAN中,还可以应用在WAS深圳internet上。

        旧时的观念,基于网络的iSCSI因为网络设备的限制,传输速度无法完全替代SAN设备,Fibre Channel。如果是大量数据的传输推荐使用单独的iSCSI,专用的网络。

        本课程的实验基本基于iSCSI上,因为这种技术比较容易模拟,想在cla***oom中模拟Fibre Channel,及时是SR-IOV也很难实现。

iSCSI Block Devices

        iSCSI和fibre channel的区别就是iSCSI是基于IP based network的,而fibre channel是基于fibre channel fabric的。下面的图片会显示出iSCSI和FC是如何被访问的。

image

Security

        iSCSI协议自身无法提供加密,虽然可以设置在服务端和客户端之间设置Two-way CHAP认证,但是这在建立连接时初始化的认证,而不是加密。所以iSCSI RFCs推荐使用独立的网络或者IPsec进行加密。

        另一种方法可以使用disk-encryption的方式,如LUKS(linux unified key setup),使用其他的工具对数据安全进行保证,但这也是额外的,并不是iSCSI本身的功能。

Redundancy

        iSCSI在网络层面,使用多路径的方式形成冗余。使用多网络接口连接的方式避免硬件和网络故障。

iSCSI Principles

1. whatforms of encryption can be used with iSCSI?  (B)

a. Built-in iSCSI over SSL

b. IPsec

c. Clinet-side disk encryption (e.g. luks)

d. Kerberos authentication and encryption

 

2. When comparing iSCSI with frbre channel, iSCSI is typically  (A,C)

a. cheaper

b. faster

c. more flexible

 

3. Applications running on a server must be compiled specifically to support iSCSI storage.  (B)

a. True

b. Fales

 

4. Why is it recommended that you run your iSCSI infrastructure on a separate physical network? (B,C)

a. Because iSCSI is incompatible with normal TCP/IP

b. For performance

c. For security

d. Because iSCSI requires special networking equipment.

 

Key iSCSI Terms

在讨论iSCSI的相关内容时,你需要了解一下专用名词

        IQN:A iSCSI Qualified Name,通过IQN来识别targets和initiators。IQN的格式采取 iqn.YYYY-MM.com.reversed.domain[:optional-extra-name]。YYYY-MM表示创建domain的第一个月,com.reversed.domain是你的倒域名(例如 www.example.com的倒域名则为 com.example.www),这部分有时也被叫做Naming Authority。optional 部分(中括号中的)通常用来识别特定的storage或者client。通常也可以用主机名来做此使用。

        日期部分可以确保IQN的唯一性,及时你的域名被卖掉,但是在创建IQN的那个月这个域名仍然是属于你们公司,所以不会出现IQN重复的情况。

        Target:在iSCSI中target是iSCSI server上的storage源。targets拥有唯一的IQN,targets提供0或者多个块设备叫LUNs(逻辑单元),提供一个LUN是很常见的,一个独立的服务器可以提供多个目标。

        Initiator:在iSCSI中client被叫做initiator,就如同目标发起者必须拥有一个唯一的IQN。initiator通常由软件实现,不过也可以通过购买硬件的initiator如同iSCSI HBAs.

        Node:一个单独的target或者initiator被称为一个node。

        Portal:在iSCSI中portal就是一个ip地址,用于建立target和initiator之间的连接。注意区分portal 和 node,也许他们的名字是一样的,但是实质上他们是不同的。

        iSNS:网络存储服务名,这个名称是为了让initiators更容易识别targets。这个不是一定必须的,大多数管理员没有设置iSNS.

Key iSCSI Terms

1. which of the following are valid iSCSI Qualified Names? (A,B)

a. iqn.1994-05.com.redhat:bigstorage

b. iqn.1994-05.com.redhat.bigstorage

c. iqn.1004-05-com.redhat:bigstorage

d. iqn.05-1994.com.redhat.bigstorage

 

2. an iSCSI target must always provide at least one block device.  (B)

a. True

b. False

 

3. iSNS is always needed to run an iSCSI infrastructure (B)

a. True

b. False

 

Creating an iSCSI Target

        如果之前没有配置或者安装iSCSI Target,首先,你需要安装 scsi-target-utils 软件包。

[root@node4 ~]# rpm -qa|grep scsi-target-utils
scsi-target-utils-1.0.24-2.el6.x86_64

        安装scsi-target-utils软件包之后,会增加一些服务命令,如下:

tgtd 服务:

[root@node4 ~]# service tgtd status
tgtd is stopped

tgtadm命令:

[root@node4 ~]# tgtadm --help
Usage: tgtadm [OPTION]

[root@node4 ~]# tgt-admin --help
Usage:
tgt-admin [OPTION]...

      常用命令: tgt-admin --dump > /etc/tgt/targets.conf   去掉target.conf配置文件中的注释信息。

Creating a Target Manually (手动创建Target)

        创建目标之前先保证你有存储给target的使用,可以是一个普通文件,一个分区,一个逻辑卷,或者整个硬盘,这里我们使用一个逻辑卷。

[root@node4 dev]# lvcreate -L 1g -n example vgsrv
  Logical volume "example" created

        先启动你的tgtd服务,然后使用以下命令创建target

[root@node4 dev]# service tgtd status
tgtd is stopped
[root@node4 dev]# service tgtd start
Starting SCSI target daemon: [  OK  ]
[root@node4 dev]#

[root@node4 dev]# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2013-10.com.example:exampletarget

        可以再tgtadm的man手册中找到命令的解析:

--lld <driver> --op new --mode target --tid <id> --targetname <name>
    Add a new target with <id> and <name>.

--lld <driver> --op delete --mode target --tid <id>
    Delete specific target with <id>. The target must have no active I_T nexus.

        注意:在进行delete操作时要时所有连接到target的client端全部断开,must have no active I_T nexus。

--targetname 使用IQN名,—tid 设置target ID,在同一个系统必须唯一。

        这里创建了target目标只是创建了控制器,你可以使用tgt-admin查看,查看内容应该如下:(但是仅仅只有LUN 0 控制器LUN)

[root@node4 dev]# tgt-admin -s
Target 1: iqn.2013-10.com.example:exampletarget        (target名称 iqn名)
    System information:       
        Driver: iscsi                                     iscsi驱动
        State: ready                                    状态,已准备吉安帕
    I_T nexus information:                         iscsi_target 关联信息
    LUN information:                                  LUN信息
        LUN: 0                                            LUN编号:0
            Type: controller                            类型:控制器
            SCSI ID: IET     00010000            
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1                大小:0MB,块大小:1
            Online: Yes                                   在线
            Removable media: No                    可移动媒体
            Prevent removal: No                      防止删除
            Readonly: No                                只读
            Backing store type: null                 存储类型
            Backing store path: None               存储路径
            Backing store flags:                       存储标识
    Account information:                             账户信息
    ACL information:                                   ACL控制信息

       添加一个LUN,内容为我们创建的那个LV作为target

[root@node4 dev]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/vgsrv/example

--lld <driver> --op new --mode logicalunit --tid <id> --lun <lun> --backing-store <path>
    Add a new logical unit with <lun> to specific target with <id>. The logical unit is offered to the
    initiators. <path> must be block device files (including LVM and RAID devices) or regular files. lun0 is
    reserved for a special device automatically created.

--mode 选择逻辑单元 logicalunit,—tid 1 根据之前判断创建target的ID号,—lun 1,lun 0被控制台占用。

        加入后再使用tgt-admin -s查看现在LUN信息,可以看到加进去的磁盘,type为disk。

[root@node4 dev]# tgt-admin -s
Target 1: iqn.2013-10.com.example:exampletarget
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 1074 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/vgsrv/example
            Backing store flags:
    Account information:
    ACL information:

        现在我们创建了target的backing-store,但是clinet还是不会被允许访问。默认情况下tgtadm是拒绝所有用户访问的(通过ACL)设置,则现在我们要在ACL加入目标。

[root@node4 network-scripts]# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.2.1

        加入之后在tgt-admin -s的信息中可以看到acl的信息

ACL information:
    192.168.2.1

在tgtadm的man手册中可以找到相关的绑定或者解绑的命令

--lld <driver> --op bind --mode target --tid <id> --initiator-address <address>
    Add the address to the access lists of the target with <id>. Initiators with the address can access to the
    target. ′ALL′ is a special address to allow all initiators to access to a target.

--lld <driver> --op bind --mode target --tid <id> --initiator-name <name>
    Add the initiator′s name to the access lists of the target with <id>. Initiators with the names can access
    to the target.

--lld <driver> --op unbind --mode target --tid <id> --initiator-address <address>
    Delete the address from the access lists of the target with <id>.

--lld <driver> --op unbind --mode target --tid <id> --initiator-name <name>
    Delete the initiator′s name from the access lists of the target with <id>.

      scsi-target-utils包还附带一个脚本称为tgt-setup-lun,将自动为您大部分的这些命令.可以通过man tgt-setup-lun查看相关信息。

Persistently Create a Target (在配置文件中创建target)

        以上内容创建target的时候是以命令的形式,这种方式一般用来进行测试,对于创建target来说,这不是最简单的方式。

        我们可以通过配置tgtd进程的配置文件来进行设置,/etc/tgt/targets.conf,配置格式如下:

<target iqn.2013-10.com.example:exampletarget>
        backing-store /dev/vgsrv/example
        initiator-address 192.168.2.1
</target>

        注意:如果使用命令模式,重启tgtd服务后,配置会消失

        也可以添加以下高级设置,如 vendor ID or a SCSI serial number,格式如下:

<target iqn.2013-10.com.example:exampletarget>
        <backing-store /dev/vgsrv/example>
                vendor_id Example Inc
                scsi_id targetdisk
                scsi_sn serial01
        </backing-store>
        initiator-address 192.168.2.1
</target>

        注意: 在原版官方教材中 vendor_id 设置 Example, Inc. 但是不成功,无效的请求,试着转义,跟引号都无效,而配置文件中的example也是 Example Inc 没有标点符号的。

        使配置文档生效需要重新启动tgtd 服务,不过如果有些client还在连接,那无法关闭,使用force-restart参数可以强制disconnect客户端。

[root@node4 network-scripts]# service tgtd force-restart
Force-stopping SCSI target daemon: [  OK  ]
Starting SCSI target daemon: [  OK  ]
[root@node4 network-scripts]#

        使用tgt-admin -e命令也可以让修改的配置文件生效,但是这个更新方法只会针对新增的client,而不会影响现有的连接。

[root@node4 network-scripts]# tgt-admin –e

-e, --execute
    Read /etc/tgt/targets.conf and execute tgtadm commands. If the target already exists, it won′t be
    processed. See --update.

        更新现有的target可以使用命令 tgt-admin-u <target>,<target>为IQN or the wildcard ALL,如果你想强制性的把正在连接的client端的target更新,需要加--force参数,但是如此可能会造成客户端的一些问题。

--update <value>
    Update all or selected targets. The target will be updated only if it′s not used (no initiator is connected
    to it).

    If you want to update targets which are in use, you have to add "--force" flag.

        Example usage:
            --update ALL             - ready all targets
        Example usage:
            --update ALL             - ready all targets
            --update tid=4           - ready target 4
                                       (target with tid 4)
            --update iqn.2008-08.com.example:some.target
                                     - update this target

[root@node4 network-scripts]# tgt-admin -u iqn.2013-10.com.example:exampletarget
[root@node4 network-scripts]# tgt-admin -u iqn.2013-10.com.example:exampletarget –force

Create an iSCSI Target

Lab Overview: in this exercise you will create an iSCSI target

Success Criteria: You will have successfully completed this lab when you have a new iSCSI target on your node4 machine.

Lab Outline : In this lab you will first create a logical volume to use as a backing-store,and then export that volume over iSCSI.

 

1. Create a new logical volume on node4 according to the specifications below.

Volume Group        vgsrv

Name                    storage

Size                       4GIB

 

[root@node4 ~]# vgs
  VG    #PV #LV #SN Attr   VSize VFree
  vgsrv   1   2   0 wz--n- 7.00g 5.00g
[root@node4 ~]# lvs
  LV      VG    Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
  example vgsrv -wi-a--- 1.00g                                          
  storage vgsrv -wi-a--- 1.00g                                          
[root@node4 ~]#

2. Make sure that the scsi-target-utils package is installed on node4.

[root@node4 ~]# rpm -qa|grep scsi-target-utils
scsi-target-utils-1.0.24-2.el6.x86_64
[root@node4 ~]#

3. Using the configuration file for the tgtd daemon specify a new target according to the specifications below,make sure to replace X with your cluster number.

iSCSI Qualified Name        iqn.2012-04.com.example.node4:first

Backing-Store                 /dev/vgsrv/storage

Allowed Clients                192.168.2.1

<target iqn.2012-04.com.example.node4:first>
        backing-store /dev/vgsrv/storage
        initiator-address 192.168.2.1
</target>

4. Enable and start the target deamon.

Target 2: iqn.2013-10.com.example:exampletarget
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00020000
            SCSI SN: beaf20
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: targetdisk
            SCSI SN: serial01
            Size: 1074 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/vgsrv/example
            Backing store flags:
    Account information:
    ACL information:
        192.168.2.1

Managing iSCSI Initiators

        使用客户端(an initiators)连接iSCSI target需要安装iscsi-initiator-utils软件包,这个软件包提供了两个脚本(/etc/init.d/iscsi and /etc/init.d/iscsid)和两个配置文件(/etc/iscsi/iscsid.conf and /etc/iscsi/initiatorname.iscsi)

[root@node1 dvd]# rpm -qa|grep iscsi-initiator-utils
iscsi-initiator-utils-6.2.0.872-41.el6.x86_64

        如果你希望修改你的initiator name 可以通过/etc/iscsi/initiatorname.iscsi配置文件进行修改,当你安装了iscsi-initiator-utils软件包后,会自动生成一个initiator name,但是可能对于你的生产环境并不规范,你可以通过这个配置文件进行整理。

[root@node1 dvd]# more /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2013-10.com.example:node1
[root@node1 dvd]#

        第二个配置文件/etc/iscsi/iscsid.conf包含了discoveries的相关信息,例如timeouts,data fragment sizes,automatic or manual logins 等

下面举常用范例做解释:

# - If the value is 0, IO will be failed immediately.
# - If the value is less than 0, IO will remain queued until the session
# is logged back in, or until the user runs the logout command.
node.session.timeo.replacement_timeout = 120

节点重连超时,默认为等待120秒,如果120秒内target没有恢复,则判定失败;
如果设置为0,则如果target发生错误,则立即返回failed immediately;
如果设置小于0,则一直尝试重连;

 

# To specify the time to wait for login to complete, edit the line.
# The value is in seconds and the default is 15 seconds.
node.conn[0].timeo.login_timeout = 15

# To specify the time to wait for logout to complete, edit the line.
# The value is in seconds and the default is 15 seconds.
node.conn[0].timeo.logout_timeout = 15

登录登出时等待超时时间,如果超过则判断失败

 

# Time interval to wait for on connection before sending a ping.
node.conn[0].timeo.noop_out_interval = 5

在等待队列中,发送ping数据包判断是否恢复的间隔。

 

# To request that the iscsi initd scripts startup a session set to "automatic".
# node.startup = automatic
#
# To manually startup the session set to "manual". The default is automatic.
node.startup = automatic

在使用启动脚本启动时,是否自动连接target,默认为自动。

        根据需求配置好之后,启动iscsi服务。先清空target跟initiator的iptables策略,再尝试启动

        重启iscsi,客户端不能在/var/lib/iscsi/nodes目录中。

[root@node1 iscsi]# iptables -F
[root@node1 iscsi]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]
[root@node1 iscsi]# service iscsi restart
Stopping iscsi: [  OK  ]
Starting iscsi: [  OK  ]
[root@node1 iscsi]#

        在使用target之前需要先discover the target,discover target之后相关信息会存储在/var/lib/iscsi/nodes 中。

[root@node1 ~]# cd /var/lib/iscsi/nodes/
[root@node1 nodes]# ls -rlt
total 8
drw-------. 3 root root 4096 Oct 22 23:41 iqn.2012-04.com.example.node4:first
drw-------. 3 root root 4096 Oct 22 23:41 iqn.2013-10.com.example:exampletarget
[root@node1 nodes]#

        在这些节点中存放了target的配置信息,如下。这些配置信息跟 /etc/iscsi/initiatorname.iscsi 相对应。 

[root@node1 192.168.2.4,3260,1]# pwd
/var/lib/iscsi/nodes/iqn.2013-10.com.example:exampletarget/192.168.2.4,3260,1

[root@node1 192.168.2.4,3260,1]# more default
# BEGIN RECORD 2.0-872.41.el6
node.name = iqn.2013-10.com.example:exampletarget
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.iscsi_ifacename = default
iface.transport_name = tcp
iface.vlan_id = 0
iface.vlan_priority = 0
iface.iface_num = 0
iface.mtu = 0
iface.port = 0
node.discovery_address = 192.168.2.4
node.discovery_port = 3260
node.discovery_type = send_targets
……
……

        同一个target可以在多路径模式下可以发现多个target,iSCSI service 也会存入不同的配置信息。for example,同一个target拥有两个ip address,在发现时,通过两个IP地址均可以进行载入。

        通过以下命令进行discover

[root@node1 192.168.2.4,3260,1]# iscsiadm -m discovery -t sendtargets -p 192.168.2.4
192.168.2.4:3260,1 iqn.2012-04.com.example.node4:first
192.168.2.4:3260,1 iqn.2013-10.com.example:exampletarget

-m, --mode op
       specify the mode. op must be one of discoverydb, node, fw, host iface or session.

-t, --type=type
       type  must  be  sendtargets (or abbreviated as st), slp, isns or fw. Currently only sendtargets, fw, and
       iSNS is supported, see the DISCOVERY TYPES section.

-p, --portal=ip[:port]
              Use target portal with ip-address ip and port. If port is not passed in the default port value is  3260.

      登录使用iscsi target

[root@node1 ~]# iscsiadm -m node -T iqn.2013-10.com.example:exampletarget -l
Logging in to [iface: default, target: iqn.2013-10.com.example:exampletarget, portal: 192.168.2.4,3260] (multiple)
Login to [iface: default, target: iqn.2013-10.com.example:exampletarget, portal: 192.168.2.4,3260] successful.
[root@node1 ~]#

-u, --logout
       logout for a specified record.

       This option is only valid for node and session mode.

-U, --logoutall==[all,manual,automatic]
       logout all sessions with the node or conn startup values passed in or all running sesssion, except  ones
       marked onboot, if all is passed in.

       This option is only valid for node mode (it is valid but not functional for session mode).

-l, --login
       For node and fw mode, login to a specified record. For discovery mode, login to all discovered  targets.

       This option is only valid for discovery and node modes.

-L, --loginall==[all|manual|automatic]
       For  node  mode,  login all sessions with the node or conn startup values passed in or all running sess-
       sion, except ones marked onboot, if all is passed in.

       This option is only valid for node mode (it is valid but not functional for session mode).

常见疑问解析

        Number 1. 不同的node可以分别配置属性,例如automatic等。配置/var/lib/iscsi/nodes中的配置文件可以实现。

        Number 2. 尚未discovery login target的时候,无法启动iscsi service。

        根据上述方法login之后可以在fdisk中看到storage信息

[root@node1 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007a876

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1332    10485760   83  Linux
/dev/sda3            1332        1462     1048576   82  Linux swap / Solaris

Disk /dev/sdc: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Note: 如果你的initiator的target已经有的node信息,重启服务可自动Login,因为在/var/lib/iscsi/node中存在 automatic的属性。

Requesting information from Targets

        可以通过iscsiadm命令查看targets相关命令,可以使用-P 参数选择信息模式

iscsiadm –m discovery [-P 0|1] 查看已发现targets相关信息

iscsiadm –m node [-P 0|1] 查看已获取target相关信息 ,(已经login,写入nodes中)

iscsiadm –m session [-P 0|1|2|3] 查看active session相关信息 –P 3参数可以查看已经被创建的targets设备信息。

Stop Using a Target

       使用 –u 参数 logout,前文已经列出相关参数,-U 为 logout ALL 等。

[root@node1 ~]# iscsiadm -m node -T iqn.2013-10.com.example:exampletarget -u
Logging out of session [sid: 5, target: iqn.2013-10.com.example:exampletarget, portal: 192.168.2.4,3260]
Logout of [sid: 5, target: iqn.2013-10.com.example:exampletarget, portal: 192.168.2.4,3260] successful.

        登出之后并没有在initiator删除相关配置,如果设置为automatic,当iscsi服务重启之后,会自动登录,如果要彻底删除,需要使用—op delete参数。无法指定删除node的某个入口信息。

[root@node1 ~]# iscsiadm -m node -T iqn.2013-10.com.example:exampletarget --op delete

        iscsi相关配置文档可以在/usr/share/doc/iscsi-initiator-utils-6.2.0.872/README找到。

Configure an iSCSI initiator

Lab Overvies: in this lab you will configure your node1 virtual machine to use the iSCSI target you create in the previous exercise.

Success Criteria: You will have successfully completed this exercise when your node1 virtual machine is connected to the iSCSI target running on node4.

Lab Outline Connect to an iSCSI target.

Before you begin..

Make sure that the iSCSI target you created in the previous exercise is still up and running

1. Make sure the iscsi-initiator-utils package is installed on node1.

2. set the initiator name on node1 to iqn.2013-10.com.example.clusterX:node1.

3. From node1 discover all targets on node4.storage1.clusterX.example.com

4. From node1 log in to the target you just discovered.

5. Verify that you are now connected to the iSCSI target.

Using Disks Larger Than Two Terabytes

        RHEL6基本分区模式是使用硬盘直接分区,这是我们实验经常使用的模式,不过这已经很古老了,现在使用这种方法分区会有很多问题。第一,这对你的使用空间大小是有限制的,他没有良好的扩展性,包括extended and logical partitions。第二如果空间大于2TiB,会出现很多问题。现在空间大于2TiB已经很普遍,在SAN构架中经常如此。这对我们是个挑战,我们需要改变。

        一种解决方法是使用GPT分区模式,以下为GPT(GUID Partition Table)的说明

与支持最大卷为 2 TB (terabytes) 并且每个磁盘最多有 4 个主分区(或 3 个主分区,1 个扩展分区和无限制的逻辑驱动器)的主启动记录 (MBR) 磁盘分区的样式相比,GUID 分区表 (GPT) 磁盘分区样式支持最大卷为 18 EB (exabytes) 并且每磁盘最多有 128 个分区。与 MBR 分区的磁盘不同,至关重要的平台操作数据位于分区,而不是位于非分区或隐藏扇区。另外,GPT 分区磁盘有多余的主要及备份分区表来提高分区数据结构的完整性。

        使用以下命令,将a GPT disk label 写入磁盘

[root@node4 ~]# parted /dev/wholedisk mklabel gpt

        转换为MBR类型的分区表

[root@node4 ~]# parted /dev/wholedisk mklabel msdos

Creating Partition With parted

        要使用GTP分区表,需要使用parted进行分区。以下为分区范例:

[root@node1 media]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart
Partition type?  primary/extended? p                                     
File system type?  [ext2]? ext3                                          
Start? 1049Kb                                                            
End? 200MB                                                               
(parted) print list
Model: IET VIRTUAL-DISK (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size   Type     File system  Flags
1      1049kB  200MB  199MB  primary

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
1      1049kB  211MB   210MB   primary  ext4            boot
2      211MB   10.9GB  10.7GB  primary  ext4
3      10.9GB  12.0GB  1074MB  primary  linux-swap(v1)

        相关命令可以再 parted模式下输入help查看。