1 #!/bin/sh 2 # 3 # This script illustrates the sequence of oper 4 # create a very simple LIO iSCSI target with a 5 # backstore. 6 # 7 # (C) Copyright 2014 Christophe Vu-Brugier <cvu 8 # 9 10 print_usage() { 11 cat <<EOF 12 Usage: $(basename $0) [-p PORTAL] DEVICE|FILE 13 Export a block device or a file as an iSCSI ta 14 EOF 15 } 16 17 die() { 18 echo $1 19 exit 1 20 } 21 22 while getopts "hp:" arg; do 23 case $arg in 24 h) print_usage; exit 0;; 25 p) PORTAL=${OPTARG};; 26 esac 27 done 28 shift $(($OPTIND - 1)) 29 30 DEVICE=$1 31 [ -n "$DEVICE" ] || die "Missing device or fil 32 [ -b $DEVICE -o -f $DEVICE ] || die "Invalid d 33 IQN="iqn.2003-01.org.linux-iscsi.$(hostname):$ 34 [ -n "$PORTAL" ] || PORTAL="0.0.0.0:3260" 35 36 CONFIGFS=/sys/kernel/config 37 CORE_DIR=$CONFIGFS/target/core 38 ISCSI_DIR=$CONFIGFS/target/iscsi 39 40 # Load the target modules and mount the config 41 lsmod | grep -q configfs || modprobe configfs 42 lsmod | grep -q target_core_mod || modprobe ta 43 mount | grep -q ^configfs || mount -t configfs 44 mkdir -p $ISCSI_DIR 45 46 # Create a backstore 47 if [ -b $DEVICE ]; then 48 BACKSTORE_DIR=$CORE_DIR/iblock_0/data 49 mkdir -p $BACKSTORE_DIR 50 echo "udev_path=${DEVICE}" > $BACKSTORE_DI 51 else 52 BACKSTORE_DIR=$CORE_DIR/fileio_0/data 53 mkdir -p $BACKSTORE_DIR 54 DEVICE_SIZE=$(du -b $DEVICE | cut -f1) 55 echo "fd_dev_name=${DEVICE}" > $BACKSTORE_ 56 echo "fd_dev_size=${DEVICE_SIZE}" > $BACKS 57 echo 1 > $BACKSTORE_DIR/attrib/emulate_wri 58 fi 59 echo 1 > $BACKSTORE_DIR/enable 60 61 # Create an iSCSI target and a target portal g 62 mkdir $ISCSI_DIR/$IQN 63 mkdir $ISCSI_DIR/$IQN/tpgt_1/ 64 65 # Create a LUN 66 mkdir $ISCSI_DIR/$IQN/tpgt_1/lun/lun_0 67 ln -s $BACKSTORE_DIR $ISCSI_DIR/$IQN/tpgt_1/lu 68 echo 1 > $ISCSI_DIR/$IQN/tpgt_1/enable 69 70 # Create a network portal 71 mkdir $ISCSI_DIR/$IQN/tpgt_1/np/$PORTAL 72 73 # Disable authentication 74 echo 0 > $ISCSI_DIR/$IQN/tpgt_1/attrib/authent 75 echo 1 > $ISCSI_DIR/$IQN/tpgt_1/attrib/generat 76 77 # Allow write access for non authenticated ini 78 echo 0 > $ISCSI_DIR/$IQN/tpgt_1/attrib/demo_mo 79 80 echo "Target ${IQN}, portal ${PORTAL} has been
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.