{"id":219,"date":"2012-05-09T10:08:17","date_gmt":"2012-05-09T09:08:17","guid":{"rendered":"http:\/\/www.tinone71.com\/wordpress\/?p=219"},"modified":"2015-01-09T15:47:38","modified_gmt":"2015-01-09T15:47:38","slug":"using-iscsi-on-ubuntu-10-04","status":"publish","type":"post","link":"https:\/\/www.tinone71.com\/wp\/?p=219","title":{"rendered":"Using iSCSI on Ubuntu 10.04"},"content":{"rendered":"<div style=\"\" class=\"ssag-opads-main     \" ><\/div><p>his guide explains how you can set up an iSCSI target and an iSCSI initiator (client), both running Ubuntu 10.04. The iSCSI protocol is a storage area network (SAN) protocol which allows iSCSI initiators to use storage devices on the (remote) iSCSI target using normal ethernet cabling. To the iSCSI initiator, the remote storage looks like a normal, locally-attached hard drive.<\/p>\n<p>I do not issue any guarantee that this will work for you!<\/p>\n<p>1 Preliminary Note<\/p>\n<p>I&#8217;m using two Ubuntu 10.04 servers here:<\/p>\n<p>server1.example.com (Initiator): IP address 192.168.0.100<br \/>\nserver2.example.com (Target): IP address 192.168.0.101<\/p>\n<p>Because we will run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing<\/p>\n<p>sudo su<\/p>\n<p>2 Setting Up The Target (server2)<\/p>\n<p>server2:<\/p>\n<p>First we set up the target (server2):<\/p>\n<p>aptitude install iscsitarget<\/p>\n<p>Open \/etc\/default\/iscsitarget&#8230;<\/p>\n<p>vi \/etc\/default\/iscsitarget<\/p>\n<p>&#8230; and set ISCSITARGET_ENABLE to true:<\/p>\n<p>ISCSITARGET_ENABLE=true<\/p>\n<p>We can use unused logical volumes, image files, hard drives (e.g. \/dev\/sdb), hard drive partitions (e.g. \/dev\/sdb1) or RAID devices (e.g. \/dev\/md0) for the storage. In this example I will create a logical volume of 20GB named storage_lun1 in the volume group vg0:<\/p>\n<p>lvcreate -L20G -n storage_lun1 vg0<\/p>\n<p>(If you want to use an image file, you can create it as follows:<\/p>\n<p>mkdir \/storage<br \/>\ndd if=\/dev\/zero of=\/storage\/lun1.img bs=1024k count=20000<\/p>\n<p>This creates the image file \/storage\/lun1.img with a size of 20GB.<\/p>\n<p>)<\/p>\n<p>Next we edit \/etc\/ietd.conf&#8230;<\/p>\n<p>vi \/etc\/ietd.conf<\/p>\n<p>&#8230; and comment out everything in that file. At the end we add the following stanza:<\/p>\n<p>[&#8230;]<br \/>\nTarget iqn.2001-04.com.example:storage.lun1<br \/>\nIncomingUser someuser secret<br \/>\nOutgoingUser<br \/>\nLun 0 Path=\/dev\/vg0\/storage_lun1,Type=fileio<br \/>\nAlias LUN1<br \/>\n#MaxConnections 6<\/p>\n<p>The target name must be a globally unique name, the iSCSI standard defines the &#8220;iSCSI Qualified Name&#8221; as follows: iqn.yyyy-mm.[:identifier]; yyyy-mm is the date at which the domain is valid; the identifier is freely selectable. The IncomingUser line contains a username and a password so that only the initiators (clients) that provide this username and password can log in and use the storage device; if you don&#8217;t need authentication, don&#8217;t specify a username and password in the IncomingUser line. In the Lun line, we must specify the full path to the storage device (e.g. \/dev\/vg0\/storage_lun1, \/storage\/lun1.img, \/dev\/sdb, etc.).<\/p>\n<p>Now we tell the target that we want to allow connections to the device iqn.2001-04.com.example:storage.lun1 from the IP address 192.168.0.100 (server1.example.com) (comment out the ALL ALL line because that would allow all initiators to connect to all targets)&#8230;<\/p>\n<p>vi \/etc\/initiators.allow<\/p>\n<p>[&#8230;]<br \/>\niqn.2001-04.com.example:storage.lun1 192.168.0.100<br \/>\n#ALL ALL<\/p>\n<p>&#8230; and start the target:<\/p>\n<p>\/etc\/init.d\/iscsitarget start<\/p>\n<p>3 Setting Up The Initiator (server1)<\/p>\n<p>server1:<\/p>\n<p>On server1, we install the initiator:<\/p>\n<p>aptitude install open-iscsi<\/p>\n<p>Next we open \/etc\/iscsi\/iscsid.conf&#8230;<\/p>\n<p>vi \/etc\/iscsi\/iscsid.conf<\/p>\n<p>&#8230; and set node.startup to automatic:<\/p>\n<p>[&#8230;]<br \/>\nnode.startup = automatic<br \/>\n[&#8230;]<\/p>\n<p>Then we restart the initiator:<\/p>\n<p>\/etc\/init.d\/open-iscsi restart<\/p>\n<p>Now we connect to the target (server2) and check what storage devices it has to offer:<\/p>\n<p>iscsiadm -m discovery -t st -p 192.168.0.101<\/p>\n<p>root@server1:~# iscsiadm -m discovery -t st -p 192.168.0.101<br \/>\n192.168.0.101:3260,1 iqn.2001-04.com.example:storage.lun1<br \/>\nroot@server1:~#<\/p>\n<p>iscsiadm -m node<\/p>\n<p>root@server1:~# iscsiadm -m node<br \/>\n192.168.0.101:3260,1 iqn.2001-04.com.example:storage.lun1<br \/>\nroot@server1:~#<\/p>\n<p>The settings for the storage device iqn.2001-04.com.example:storage.lun1 on 192.168.0.101:3260,1 are stored in the file \/etc\/iscsi\/nodes\/iqn.2001-04.com.example:storage.lun1\/192.168.0.101,3260,1\/default. We need to set the username and password for the target in that file; instead of editing that file manually, we can use the iscsiadm command to do this for us:<\/p>\n<p>iscsiadm -m node &#8211;targetname &#8220;iqn.2001-04.com.example:storage.lun1&#8221; &#8211;portal &#8220;192.168.0.101:3260&#8221; &#8211;op=update &#8211;name node.session.auth.authmethod &#8211;value=CHAP<br \/>\niscsiadm -m node &#8211;targetname &#8220;iqn.2001-04.com.example:storage.lun1&#8221; &#8211;portal &#8220;192.168.0.101:3260&#8221; &#8211;op=update &#8211;name node.session.auth.username &#8211;value=someuser<br \/>\niscsiadm -m node &#8211;targetname &#8220;iqn.2001-04.com.example:storage.lun1&#8221; &#8211;portal &#8220;192.168.0.101:3260&#8221; &#8211;op=update &#8211;name node.session.auth.password &#8211;value=secret<\/p>\n<p>Now we can log in, either by running&#8230;<\/p>\n<p>iscsiadm -m node &#8211;targetname &#8220;iqn.2001-04.com.example:storage.lun1&#8221; &#8211;portal &#8220;192.168.0.101:3260&#8221; &#8211;login<\/p>\n<p>root@server1:~# iscsiadm -m node &#8211;targetname &#8220;iqn.2001-04.com.example:storage.lun1&#8221; &#8211;portal &#8220;192.168.0.101:3260&#8221; &#8211;login<br \/>\nLogging in to [iface: default, target: iqn.2001-04.com.example:storage.lun1, portal: 192.168.0.101,3260]<br \/>\nLogin to [iface: default, target: iqn.2001-04.com.example:storage.lun1, portal: 192.168.0.101,3260]: successful<br \/>\nroot@server1:~#<\/p>\n<p>&#8230; or by restarting the initiator:<\/p>\n<p>\/etc\/init.d\/open-iscsi restart<\/p>\n<p>(If you want to log out, you can run<\/p>\n<p>iscsiadm -m node &#8211;targetname &#8220;iqn.2001-04.com.example:storage.lun1&#8221; &#8211;portal &#8220;192.168.0.101:3260&#8221; &#8211;logout<\/p>\n<p>)<\/p>\n<p>In the output of<\/p>\n<p>fdisk -l<\/p>\n<p>you should now find a new hard drive (\/dev\/sdb in this example); that&#8217;s our iSCSI storage device:<\/p>\n<p>root@server1:~# fdisk -l<\/p>\n<p>Disk \/dev\/sda: 32.2 GB, 32212254720 bytes<br \/>\n255 heads, 63 sectors\/track, 3916 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk identifier: 0x00016be9<\/p>\n<p>Device Boot Start End Blocks Id System<br \/>\n\/dev\/sda1 * 1 32 248832 83 Linux<br \/>\nPartition 1 does not end on cylinder boundary.<br \/>\n\/dev\/sda2 32 3917 31205377 5 Extended<br \/>\n\/dev\/sda5 32 3917 31205376 8e Linux LVM<\/p>\n<p>Disk \/dev\/sdb: 21.5 GB, 21474836480 bytes<br \/>\n64 heads, 32 sectors\/track, 20480 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk identifier: 0x00000000<\/p>\n<p>Disk \/dev\/sdb doesn&#8217;t contain a valid partition table<br \/>\nroot@server1:~#<\/p>\n<p>To use that device, we must format it:<\/p>\n<p>fdisk \/dev\/sdb<\/p>\n<p>server1:~# fdisk \/dev\/sdb<br \/>\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br \/>\nBuilding a new DOS disklabel with disk identifier 0x882944df.<br \/>\nChanges will remain in memory only, until you decide to write them.<br \/>\nAfter that, of course, the previous content won&#8217;t be recoverable.<\/p>\n<p>The number of cylinders for this disk is set to 20480.<br \/>\nThere is nothing wrong with that, but this is larger than 1024,<br \/>\nand could in certain setups cause problems with:<br \/>\n1) software that runs at boot time (e.g., old versions of LILO)<br \/>\n2) booting and partitioning software from other OSs<br \/>\n(e.g., DOS FDISK, OS\/2 FDISK)<br \/>\nWarning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)<\/p>\n<p>Command (m for help): Command action<br \/>\na toggle a bootable flag<br \/>\nb edit bsd disklabel<br \/>\nc toggle the dos compatibility flag<br \/>\nd delete a partition<br \/>\nl list known partition types<br \/>\nm print this menu<br \/>\nn add a new partition<br \/>\no create a new empty DOS partition table<br \/>\np print the partition table<br \/>\nq quit without saving changes<br \/>\ns create a new empty Sun disklabel<br \/>\nt change a partition&#8217;s system id<br \/>\nu change display\/entry units<br \/>\nv verify the partition table<br \/>\nw write table to disk and exit<br \/>\nx extra functionality (experts only)<\/p>\n<p>Command (m for help): Command action<br \/>\ne extended<br \/>\np primary partition (1-4)<br \/>\nPartition number (1-4): First cylinder (1-20480, default 1): Using default value 1<br \/>\nLast cylinder or +size or +sizeM or +sizeK (1-20480, default 20480): Using default value 20480<\/p>\n<p>Command (m for help): Selected partition 1<br \/>\nHex code (type L to list codes):<\/p>\n<p>0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot<br \/>\n1 FAT12 24 NEC DOS 81 Minix \/ old Lin bf Solaris<br \/>\n2 XENIX root 39 Plan 9 82 Linux swap \/ So c1 DRDOS\/sec (FAT-<br \/>\n3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS\/sec (FAT-<br \/>\n4 FAT16 5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx<br \/>\n6 FAT16 42 SFS 86 NTFS volume set da Non-FS data<br \/>\n7 HPFS\/NTFS 4d QNX4.x 87 NTFS volume set db CP\/M \/ CTOS \/ .<br \/>\n8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility<br \/>\n9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt<br \/>\na OS\/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access<br \/>\nb W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R\/O<br \/>\nc W95 FAT32 (LBA) 52 CP\/M 9f BSD\/OS e4 SpeedStor<br \/>\ne W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs<br \/>\nf W95 Ext&#8217;d (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT<br \/>\n10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12\/16\/<br \/>\n11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux\/PA-RISC b<br \/>\n12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor<br \/>\n14 Hidden FAT16 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary<br \/>\n17 Hidden HPFS\/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto<br \/>\n18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep<br \/>\n1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT<br \/>\n1c Hidden W95 FAT3 75 PC\/IX<br \/>\nHex code (type L to list codes):<\/p>\n<p>Command (m for help):The partition table has been altered!<\/p>\n<p>Calling ioctl() to re-read partition table.<br \/>\nSyncing disks.<br \/>\nserver1:~#<\/p>\n<p>Afterwards, the output of<\/p>\n<p>fdisk -l<\/p>\n<p>should look as follows:<\/p>\n<p>root@server1:~# fdisk -l<\/p>\n<p>Disk \/dev\/sda: 32.2 GB, 32212254720 bytes<br \/>\n255 heads, 63 sectors\/track, 3916 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk identifier: 0x00016be9<\/p>\n<p>Device Boot Start End Blocks Id System<br \/>\n\/dev\/sda1 * 1 32 248832 83 Linux<br \/>\nPartition 1 does not end on cylinder boundary.<br \/>\n\/dev\/sda2 32 3917 31205377 5 Extended<br \/>\n\/dev\/sda5 32 3917 31205376 8e Linux LVM<\/p>\n<p>Disk \/dev\/sdb: 21.5 GB, 21474836480 bytes<br \/>\n64 heads, 32 sectors\/track, 20480 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<br \/>\nSector size (logical\/physical): 512 bytes \/ 512 bytes<br \/>\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<br \/>\nDisk identifier: 0x725b9dff<\/p>\n<p>Device Boot Start End Blocks Id System<br \/>\n\/dev\/sdb1 1 20480 20971504 83 Linux<br \/>\nroot@server1:~#<\/p>\n<p>Now we create a filesystem on \/dev\/sdb1&#8230;<\/p>\n<p>mkfs.ext4 \/dev\/sdb1<\/p>\n<p>&#8230; and mount it for test purposes:<\/p>\n<p>mount \/dev\/sdb1 \/mnt<\/p>\n<p>You should now see the new device in the outputs of&#8230;<\/p>\n<p>mount<\/p>\n<p>root@server1:~# mount<br \/>\n\/dev\/mapper\/server1-root on \/ type ext4 (rw,errors=remount-ro)<br \/>\nproc on \/proc type proc (rw,noexec,nosuid,nodev)<br \/>\nnone on \/sys type sysfs (rw,noexec,nosuid,nodev)<br \/>\nnone on \/sys\/fs\/fuse\/connections type fusectl (rw)<br \/>\nnone on \/sys\/kernel\/debug type debugfs (rw)<br \/>\nnone on \/sys\/kernel\/security type securityfs (rw)<br \/>\nnone on \/dev type devtmpfs (rw,mode=0755)<br \/>\nnone on \/dev\/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)<br \/>\nnone on \/dev\/shm type tmpfs (rw,nosuid,nodev)<br \/>\nnone on \/var\/run type tmpfs (rw,nosuid,mode=0755)<br \/>\nnone on \/var\/lock type tmpfs (rw,noexec,nosuid,nodev)<br \/>\nnone on \/lib\/init\/rw type tmpfs (rw,nosuid,mode=0755)<br \/>\nnone on \/var\/lib\/ureadahead\/debugfs type debugfs (rw,relatime)<br \/>\n\/dev\/sda1 on \/boot type ext2 (rw)<br \/>\n\/dev\/sdb1 on \/mnt type ext4 (rw)<br \/>\nroot@server1:~#<\/p>\n<p>&#8230; and<\/p>\n<p>df -h<\/p>\n<p>root@server1:~# df -h<br \/>\nFilesystem Size Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/server1-root<br \/>\n18G 838M 16G 5% \/<br \/>\nnone 243M 180K 242M 1% \/dev<br \/>\nnone 247M 0 247M 0% \/dev\/shm<br \/>\nnone 247M 36K 247M 1% \/var\/run<br \/>\nnone 247M 0 247M 0% \/var\/lock<br \/>\nnone 247M 0 247M 0% \/lib\/init\/rw<br \/>\nnone 18G 838M 16G 5% \/var\/lib\/ureadahead\/debugfs<br \/>\n\/dev\/sda1 228M 17M 199M 8% \/boot<br \/>\n\/dev\/sdb1 20G 172M 19G 1% \/mnt<br \/>\nroot@server1:~#<\/p>\n<p>You can unmount it like this:<\/p>\n<p>umount \/mnt<\/p>\n<p>To have the device mounted automatically at boot time, e.g. in the directory \/storage, we create that directory&#8230;<\/p>\n<p>mkdir \/storage<\/p>\n<p>&#8230; and add the following line to \/etc\/fstab:<\/p>\n<p>vi \/etc\/fstab<\/p>\n<p>[&#8230;]<br \/>\n\/dev\/sdb1 \/storage ext4 defaults,auto,_netdev 0 0<\/p>\n<p>For test purposes, you can now reboot the system:<\/p>\n<p>reboot<\/p>\n<p>After the reboot, the device should be mounted:<\/p>\n<p>mount<\/p>\n<p>root@server1:~# mount<br \/>\n\/dev\/mapper\/server1-root on \/ type ext4 (rw,errors=remount-ro)<br \/>\nproc on \/proc type proc (rw,noexec,nosuid,nodev)<br \/>\nnone on \/sys type sysfs (rw,noexec,nosuid,nodev)<br \/>\nnone on \/sys\/fs\/fuse\/connections type fusectl (rw)<br \/>\nnone on \/sys\/kernel\/debug type debugfs (rw)<br \/>\nnone on \/sys\/kernel\/security type securityfs (rw)<br \/>\nnone on \/dev type devtmpfs (rw,mode=0755)<br \/>\nnone on \/dev\/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)<br \/>\nnone on \/dev\/shm type tmpfs (rw,nosuid,nodev)<br \/>\nnone on \/var\/run type tmpfs (rw,nosuid,mode=0755)<br \/>\nnone on \/var\/lock type tmpfs (rw,noexec,nosuid,nodev)<br \/>\nnone on \/lib\/init\/rw type tmpfs (rw,nosuid,mode=0755)<br \/>\nnone on \/var\/lib\/ureadahead\/debugfs type debugfs (rw,relatime)<br \/>\n\/dev\/sda1 on \/boot type ext2 (rw)<br \/>\n\/dev\/sdb1 on \/storage type ext4 (rw,_netdev)<br \/>\nroot@server1:~#<\/p>\n<p>df -h<\/p>\n<p>root@server1:~# df -h<br \/>\nFilesystem Size Used Avail Use% Mounted on<br \/>\n\/dev\/mapper\/server1-root<br \/>\n18G 839M 16G 5% \/<br \/>\nnone 243M 180K 242M 1% \/dev<br \/>\nnone 247M 0 247M 0% \/dev\/shm<br \/>\nnone 247M 36K 247M 1% \/var\/run<br \/>\nnone 247M 0 247M 0% \/var\/lock<br \/>\nnone 247M 0 247M 0% \/lib\/init\/rw<br \/>\nnone 18G 839M 16G 5% \/var\/lib\/ureadahead\/debugfs<br \/>\n\/dev\/sda1 228M 17M 199M 8% \/boot<br \/>\n\/dev\/sdb1 20G 172M 19G 1% \/storage<br \/>\nroot@server1:~#<\/p>\n","protected":false},"excerpt":{"rendered":"<p>his guide explains how you can set up an iSCSI target and an iSCSI initiator (client), both running<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/219"}],"collection":[{"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=219"}],"version-history":[{"count":1,"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tinone71.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}