Now Reading
How to create and setup LUNs using LVM
0

How to create and setup LUNs using LVM

To create and setup LUNs using LVM on RHEL/CentOS/Fedora

LUN is a Logical Unit Number that shared from the iSCSI Storage Server. The iSCSI target server physical drive shares its drive to initiate over TCP/IP network. It form a large storage as SAN (Storage Area Network) with a collection of drives. LUNs are defined in LVM as per space availability in real environment. Creating LUNs using LVM is explained in this article.

Importance of LUN

  • It is used for storage purpose.
  • It is used to install Operating systems and also in Clusters, Virtual servers, SAN etc.

To Create LUNs using LVM in iSCSI Target Server

Using ‘fdisk -l’ command, find out the list of drives in every partitions on the system.

[root@linuxhelp ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b5211
    Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048     5122047     2048000   82  Linux swap / Solaris
/dev/sda3         5122048    41943039    18410496   83  Linux
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 byt

Creation of LVM Drive for LUNs

Use /dev/sdb drive for creating a LVM.
Now Partition the drive using the following fdisk command,

[root@linuxhelp ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb4237527.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-83886079, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): +15G
Partition 1 of type Linux and of size 15 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xb4237527
      Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    31459327    15728640   8e  Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Creation of Logical Volume for LUNs

Create Physical volume using ‘pvcreate’ command.

[root@linuxhelp ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

Next create a Volume group with name of iSCSI.

[root@linuxhelp ~]# vgcreate vg1 /dev/sdb1
  Volume group "vg1" successfully created

Define 6 Logical Volumes for 6 LUNs in our iSCSI Target server.

[root@linuxhelp ~]# lvcreate -L 2G -n lv1 vg1
  Logical volume "lv1" created
[root@linuxhelp ~]# lvcreate -L 2G -n lv2 vg1
  Logical volume "lv2" created
[root@linuxhelp ~]# lvcreate -L 2G -n lv3 vg1
  Logical volume "lv3" created
[root@linuxhelp ~]# lvcreate -L 2G -n lv4 vg1
  Logical volume "lv4" created
[root@linuxhelp ~]# lvcreate -L 2G -n lv5 vg1
  Logical volume "lv5" created
[root@linuxhelp ~]# lvcreate -L 2G -n lv6 vg1
  Logical volume "lv6" created

Confirm it by listing the Physical volume, Volume group and logical volumes.

[root@linuxhelp ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sdb1  vg1  lvm2 a--  15.00g 3.00g
[root@linuxhelp ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg1    1   6   0 wz--n- 15.00g 3.00g
[root@linuxhelp ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Move Log Cpy%Sync Convert
  lv1  vg1  -wi-a----- 2.00g                                             
  lv2  vg1  -wi-a----- 2.00g                                             
  lv3  vg1  -wi-a----- 2.00g                                             
  lv4  vg1  -wi-a----- 2.00g                                             
  lv5  vg1  -wi-a----- 2.00g                                             
  lv6  vg1  -wi-a----- 2.00g 

To Define LUNs in Target Server

Run the following command to create the LUNs in the target server.

[root@linuxhelp ~]# targetcli
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block create iscsi_block1 /dev/vg1/lv1
Created block storage object iscsi_block1 using /dev/vg1/lv1.
/> /backstores/block create iscsi_block2 /dev/vg1/lv2
Created block storage object iscsi_block2 using /dev/vg1/lv2.
/> /backstores/block create iscsi_block3 /dev/vg1/lv3
Created block storage object iscsi_block3 using /dev/vg1/lv3.
/> /backstores/block create iscsi_block4 /dev/vg1/lv4
Created block storage object iscsi_block4 using /dev/vg1/lv4.
/> /backstores/block create iscsi_block5 /dev/vg1/lv5
Created block storage object iscsi_block5 using /dev/vg1/lv5.
/> /backstores/block create iscsi_block6 /dev/vg1/lv6
Created block storage object iscsi_block6 using /dev/vg1/lv6.
/> /iscsi create iqn.2015-06.com.linuxhelp.server
Created target iqn.2015-06.com.linuxhelp.server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/acls create iqn.2015-06.com.linuxhelp.client
Created Node ACL for iqn.2015-06.com.linuxhelp.client
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/luns create /backstores/block/iscsi_block1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2015-06.com.linuxhelp.client
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/luns create /backstores/block/iscsi_block2
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.2015-06.com.linuxhelp.client
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/luns create /backstores/block/iscsi_block3
Created LUN 2.
Created LUN 2->2 mapping in node ACL iqn.2015-06.com.linuxhelp.client
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/luns create /backstores/block/iscsi_block4
Created LUN 3.
Created LUN 3->3 mapping in node ACL iqn.2015-06.com.linuxhelp.client
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/luns create /backstores/block/iscsi_block5
Created LUN 4.
Created LUN 4->4 mapping in node ACL iqn.2015-06.com.linuxhelp.client
/> /iscsi/iqn.2015-06.com.linuxhelp.server/tpg1/luns create /backstores/block/iscsi_block6
Created LUN 5.
Created LUN 5->5 mapping in node ACL iqn.2015-06.com.linuxhelp.client
/> ls
o- / ................................................................................... [...]
  o- backstores ........................................................................ [...]
  | o- block ............................................................ [Storage Objects: 6]
  | | o- iscsi_block1 ........................... [/dev/vg1/lv1 (2.0GiB) write-thru activated]
  | | o- iscsi_block2 ........................... [/dev/vg1/lv2 (2.0GiB) write-thru activated]
  | | o- iscsi_block3 ........................... [/dev/vg1/lv3 (2.0GiB) write-thru activated]
  | | o- iscsi_block4 ........................... [/dev/vg1/lv4 (2.0GiB) write-thru activated]
  | | o- iscsi_block5 ........................... [/dev/vg1/lv5 (2.0GiB) write-thru activated]
  | | o- iscsi_block6 ........................... [/dev/vg1/lv6 (2.0GiB) write-thru activated]
  | o- fileio ........................................................... [Storage Objects: 0]
  | o- pscsi ............................................................ [Storage Objects: 0]
  | o- ramdisk .......................................................... [Storage Objects: 0]
  o- iscsi ...................................................................... [Targets: 1]
  | o- iqn.2015-06.com.linuxhelp.server ............................................ [TPGs: 1]
  |   o- tpg1 ......................................................... [no-gen-acls, no-auth]
  |     o- acls .................................................................... [ACLs: 1]
  |     | o- iqn.2015-06.com.linuxhelp.client ............................... [Mapped LUNs: 6]
  |     |   o- mapped_lun0 .................................... [lun0 block/iscsi_block1 (rw)]
  |     |   o- mapped_lun1 .................................... [lun1 block/iscsi_block2 (rw)]
  |     |   o- mapped_lun2 .................................... [lun2 block/iscsi_block3 (rw)]
  |     |   o- mapped_lun3 .................................... [lun3 block/iscsi_block4 (rw)]
  |     |   o- mapped_lun4 .................................... [lun4 block/iscsi_block5 (rw)]
  |     |   o- mapped_lun5 .................................... [lun5 block/iscsi_block6 (rw)]
  |     o- luns .................................................................... [LUNs: 6]
  |     | o- lun0 ........................................ [block/iscsi_block1 (/dev/vg1/lv1)]
  |     | o- lun1 ........................................ [block/iscsi_block2 (/dev/vg1/lv2)]
  |     | o- lun2 ........................................ [block/iscsi_block3 (/dev/vg1/lv3)]
  |     | o- lun3 ........................................ [block/iscsi_block4 (/dev/vg1/lv4)]
  |     | o- lun4 ........................................ [block/iscsi_block5 (/dev/vg1/lv5)]
  |     | o- lun5 ........................................ [block/iscsi_block6 (/dev/vg1/lv6)]
  |     o- portals .............................................................. [Portals: 1]
  |       o- 0.0.0.0:3260 ............................................................... [OK]
  o- loopback ................................................................... [Targets: 0]
/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

Now restart the target services to see the changes.

[root@linuxhelp ~]# systemctl restart target
[root@linuxhelp ~]# targetcli
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ................................................................................... [...]
  o- backstores ........................................................................ [...]
  | o- block ............................................................ [Storage Objects: 6]
  | | o- iscsi_block1 ........................... [/dev/vg1/lv1 (2.0GiB) write-thru activated]
  | | o- iscsi_block2 ........................... [/dev/vg1/lv2 (2.0GiB) write-thru activated]
  | | o- iscsi_block3 ........................... [/dev/vg1/lv3 (2.0GiB) write-thru activated]
  | | o- iscsi_block4 ........................... [/dev/vg1/lv4 (2.0GiB) write-thru activated]
  | | o- iscsi_block5 ........................... [/dev/vg1/lv5 (2.0GiB) write-thru activated]
  | | o- iscsi_block6 ........................... [/dev/vg1/lv6 (2.0GiB) write-thru activated]
  | o- fileio ........................................................... [Storage Objects: 0]
  | o- pscsi ............................................................ [Storage Objects: 0]
  | o- ramdisk .......................................................... [Storage Objects: 0]
  o- iscsi ...................................................................... [Targets: 1]
  | o- iqn.2015-06.com.linuxhelp.server ............................................ [TPGs: 1]
  |   o- tpg1 ......................................................... [no-gen-acls, no-auth]
  |     o- acls .................................................................... [ACLs: 1]
  |     | o- iqn.2015-06.com.linuxhelp.client ............................... [Mapped LUNs: 6]
  |     |   o- mapped_lun0 .................................... [lun0 block/iscsi_block1 (rw)]
  |     |   o- mapped_lun1 .................................... [lun1 block/iscsi_block2 (rw)]
  |     |   o- mapped_lun2 .................................... [lun2 block/iscsi_block3 (rw)]
  |     |   o- mapped_lun3 .................................... [lun3 block/iscsi_block4 (rw)]
  |     |   o- mapped_lun4 .................................... [lun4 block/iscsi_block5 (rw)]
  |     |   o- mapped_lun5 .................................... [lun5 block/iscsi_block6 (rw)]
  |     o- luns .................................................................... [LUNs: 6]
  |     | o- lun0 ........................................ [block/iscsi_block1 (/dev/vg1/lv1)]
  |     | o- lun1 ........................................ [block/iscsi_block2 (/dev/vg1/lv2)]
  |     | o- lun2 ........................................ [block/iscsi_block3 (/dev/vg1/lv3)]
  |     | o- lun3 ........................................ [block/iscsi_block4 (/dev/vg1/lv4)]
  |     | o- lun4 ........................................ [block/iscsi_block5 (/dev/vg1/lv5)]
  |     | o- lun5 ........................................ [block/iscsi_block6 (/dev/vg1/lv6)]
  |     o- portals .............................................................. [Portals: 1]
  |       o- 0.0.0.0:3260 ............................................................... [OK]
  o- loopback ................................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.

For more help topics browse our website www.linuxhelp.com

Be the first to comment, we value your suggestions. For further queries please comment below.

Leave a Response