ISCSI is a network protocol standard that allows the use of the SCSI protocol over TCP/IP networks. How do I setup Iscsi Initiator under Ubuntu Linux? How do I format and connect to an iSCSI volume under Ubuntu Linux? How do I store VMware or Virtualbox virtual machine images using iscsi storage?
You need to install the following packages under Ubuntu Linux:
- open-iscsi – Main package for setting up an iSCSI volume.
- open-iscsi-utils – iSCSI initiatior administrative utility.
Install Required Software
Type the following command:
$ sudo apt-get update
$ sudo apt-get install open-iscsi open-iscsi-utils
Open-iSCSI Configuration
The default configuration directory located at /etc/iscsi/ and configuration file is /etc/iscsi/iscsid.conf:
Our Sample Setup
- iSCSI server IP: 192.168.1.1
- iSCSI Username: vivek
- iSCSI password: yHni3Oq9wYzamS
Setup iScsi Username And Password
Edit /etc/iscsi/iscsid.conf, enter:
$ sudo vi /etc/iscsi/iscsid.conf
Uncomment as set it as follows:
node.session.auth.username = vivek node.session.auth.password = yHni3Oq9wYzamS discovery.sendtargets.auth.username = vivek discovery.sendtargets.auth.password = yHni3Oq9wYzamS
Save and close the file. Start / restart service, enter:
$ sudo service open-iscsi restart
Running Discovery
To run a discovery against the iscsi target host, enter:
$ sudo iscsiadm -m discovery -t sendtargets -p 192.168.1.1
Sample outputs:
192.168.1.1:3260,1 iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030
Note down the above output and use it as follows:
$ sudo iscsiadm --mode node --targetname iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030 --portal 192.168.1.1:3260 --login
Sample outputs:
Logging in to [iface: default, target: iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030, portal: 192.168.1.1,3260] Login to [iface: default, target: iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030, portal: 192.168.1.1,3260]: successful
You can see the following in your /var/log/messages (note down disk name):
$ tail -f /var/log/messages
Sample outputs:
Jul 2 12:54:04 vivek-laptop kernel: [ 4418.610787] scsi6 : iSCSI Initiator over TCP/IP
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.649208] scsi 6:0:0:0: Direct-Access QNAP iSCSI Storage 3.1 PQ: 0 ANSI: 5
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.649670] sd 6:0:0:0: Attached scsi generic sg3 type 0
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.650531] sd 6:0:0:0: [sdc] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.651889] sd 6:0:0:0: [sdc] Write Protect is off
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.652643] sd 6:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.654620] sdc: unknown partition table
Jul 2 12:54:05 vivek-laptop kernel: [ 4419.692364] sd 6:0:0:0: [sdc] Attached SCSI disk
/dev/sdc is new block level device.
How Do I Format /dev/sdc?
Use the fdisk command
$ sudo fdisk /dev/sdc
Sample session:
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xe7b08c12. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sdc: 21.5 GB, 21474836480 bytes 64 heads, 32 sectors/track, 20480 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xe7b08c12 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-20480, default 1): Press [Enter] Key Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480): Press [Enter] Key Using default value 20480 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Format As ext3 Filesystem
Type the following command:
$ sudo mkfs.ext3 /dev/sdc1
Format As ext4 Filesystem
Type the following command:
$ sudo mkfs.ext4 /dev/sdc1
Sample outputs:
mke2fs 1.41.11 (14-Mar-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5242876 blocks 262143 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 160 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Mount /dev/sdc1
Create a mount point:
$ sudo mkdir /data
$ sudo mount /dev/sdc1 /data
$ df -H
Find Out Your Disk I/O Speed
A quick way is to run dd command as follows:
$ cd /data
$ dd if=/dev/zero of=output.img bs=8k count=256k
Sample outputs:
262144+0 records in
262144+0 records out
2147483648 bytes (2.1 GB) copied, 25.57 s, 84.0 MB/s
84.0 MB/s is speed which is not bad for SOHO iscsi server.
Store VM using Vmware
You can now use new storage to store data or virtual machines. Just create a new VM and setup Location to /data/VMName:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 7 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Useful comprehensive topic to me,
Thanks Vivek
:-O Wow! 80MB/s impressive high-speed.
:-/ It seems I have to tune my local ATA-HD! (but this is another topic on which you already wrote)
What are average effective output rate of common storage today on your systems?
local : IDE, ATA, USB-Key, CD, DVD, Blue-Ray?
Linux raid1 SAS 74GB x 2 @ 15k :D
dd if=/dev/zero of=output2.img bs=8k count=256k
262144+0 records in
262144+0 records out
2147483648 bytes (2.1 GB) copied, 5.41068 seconds, 397 MB/s
Is it following this structure?
server 192.168.1.1 : provide a empty hard drive
client : setup iSCSI to mount server hard drive and run vmware
…a little bit in more detail. I tested this some time ago.
–BEGIN—
FIREWALL RULES:
SERVER (192.168.1.86):
CLIENT (192.168.1.2):
How do we configure Ubuntu/RHEL/CentOS to create persistent/same device node(e.g,/dev/sdc) every time on reboot for a particular iSCSI iqn exported from an iSCSI target ?
Persistent mounting on same path:
Create a mount point for the new file-system.
mkdir -p /mnt/iscsi
Update fstab to automatically mount the new filesystem at boot. Modern distros prefer to use the disk’s UUID for mounting in fstab, referring to the device by its “old school” nomenclature still works as well.
Determine the UUID of your new iSCSI disk and add it to /etc/fstab with:
echo $(blkid /dev/sdc1 | cut -d’ ‘ -f2 | sed s/\”//g)
Example output:
UUID=e227bd05-f102-4c08-ae4f-3dbfade128aa
Safety backup:
cp /etc/fstab /etc/fstab.old
Add this UUID to fstab:
printf “$(blkid /dev/sdc1 | cut -d’ ‘ -f2 | sed s/\”//g)\t/mnt/iscsi\text4\tnoatime\t0\t0\n” >> /etc/fstab
Check:
cat /etc/fstab
Mount the new iSCSI block device.
mount /mnt/iscsi
I am not getting any output from the sendtargets line. How do I troubleshoot?