[root@kvm5 ~]# yum -y install targetcli
[root@kvm5 ~]# systemctl enable target.service ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
[root@kvm5 ~]# systemctl start target.service
[root@kvm5 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 4G 0 disk ├─vda1 252:1 0 200M 0 part /boot ├─vda2 252:2 0 3.4G 0 part │ ├─vg_kvm5usb-swap 253:0 0 124M 0 lvm [SWAP] │ └─vg_kvm5usb-root 253:1 0 3.1G 0 lvm / └─vda3 252:3 0 130M 0 part └─vg_kvm5home-vo 253:2 0 80M 0 lvm /home
[root@kvm5 ~]# fdisk /dev/vda
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.
Command (m for help): p
Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 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: 0x000f2281
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 411647 204800 83 Linux
/dev/vda2 411648 7579647 3584000 8e Linux LVM
/dev/vda3 7579648 7845887 133120 8e Linux LVM
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (7845888-8388607, default 7845888):
Using default value 7845888
Last sector, +sectors or +size{K,M,G} (7845888-8388607, default 8388607):
Using default value 8388607
Partition 4 of type Extended and of size 265 MiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (7847936-8388607, default 7847936):
Using default value 7847936
Last sector, +sectors or +size{K,M,G} (7847936-8388607, default 8388607): +100M
Partition 5 of type Linux and of size 100 MiB is set
Command (m for help): p
Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 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: 0x000f2281
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 411647 204800 83 Linux
/dev/vda2 411648 7579647 3584000 8e Linux LVM
/dev/vda3 7579648 7845887 133120 8e Linux LVM
/dev/vda4 7845888 8388607 271360 5 Extended
/dev/vda5 7847936 8052735 102400 83 Linux
Command (m for help): t
Partition number (1-5, default 5):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@kvm5 ~]# partprobe
[root@kvm5 ~]# pvcreate /dev/vda5 Physical volume "/dev/vda5" successfully created [root@kvm5 ~]# vgcreate iscsi_vg /dev/vda5 Volume group "iscsi_vg" successfully created [root@kvm5 ~]# lvcreate -n iscsi_vol -L 10M iscsi_vg Rounding up size to full physical extent 12.00 MiB Logical volume "iscsi_vol" created.
[root@kvm5 ~]# targetcli targetcli shell version 2.1.fb37 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. />
iscsi_vol 設定名為 kvm5.disk1 的 block-type backing store。
/backstores> /backstores/block create kvm5.disk1 /dev/iscsi_vg/iscsi_vol Created block storage object kvm5.disk1 using /dev/iscsi_vg/iscsi_vol.
/backstores> /iscsi create iqn.2015-08.wang.deyu:kvm5 Created target iqn.2015-08.wang.deyu:kvm5. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260.
/backstores> /iscsi/iqn.2015-08.wang.deyu:kvm5/tpg1/acls create iqn.2015-08.wang.deyu:kvm7 Created Node ACL for iqn.2015-08.wang.deyu:kvm7
/backstores> /iscsi/iqn.2015-08.wang.deyu:kvm5/tpg1/luns create /backstores/block/kvm5.disk1 Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2015-08.wang.deyu:kvm7
/> /iscsi/iqn.2015-08.wang.deyu:kvm5/tpg1/portals create 192.168.122.5 Using default IP port 3260 Could not create NetworkPortal in configFS.
/> /iscsi/iqn.2015-08.wang.deyu:kvm5/tpg1/portals delete 0.0.0.0 3260 Deleted network portal 0.0.0.0:3260
/> /iscsi/iqn.2015-08.wang.deyu:kvm5/tpg1/portals create 192.168.122.5 Using default IP port 3260 Created network portal 192.168.122.5:3260. />
/> ls o- / ..................................................................... [...] o- backstores .......................................................... [...] | o- block .............................................. [Storage Objects: 1] | | o- kvm5.disk1 ... [/dev/iscsi_vg/iscsi_vol (12.0MiB) 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-08.wang.deyu:kvm5 .................................... [TPGs: 1] | o- tpg1 ........................................... [no-gen-acls, no-auth] | o- acls ...................................................... [ACLs: 1] | | o- iqn.2015-08.wang.deyu:kvm7 ....................... [Mapped LUNs: 1] | | o- mapped_lun0 ........................ [lun0 block/kvm5.disk1 (rw)] | o- luns ...................................................... [LUNs: 1] | | o- lun0 ................. [block/kvm5.disk1 (/dev/iscsi_vg/iscsi_vol)] | o- portals ................................................ [Portals: 1] | o- 192.168.122.5: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