Ubuntu iSCSI
So, had the fun task of mounting and formatting an iSCSI drive today on an Ubuntu 8.10 machine, so I thought since I’m making more of an effort on my blog, that I’d add to my Reference materials and outline the general process. So, without further adieu, here we go.
Update: I would like to point out there’s an error in Ubuntu 8.04 that causes your system to hang on shutdown. I’ve detailed the problem and solution here in a blog post.
Install Open-iSCSI
# sudo apt-get install open-iscsi
Modify the default configuration
# sudo vim /etc/iscsi/iscsid.conf
*note you can use any editor you want, I like vim
Now in iscsid.conf modify as necessary, I had to modify the following lines:
node.startup = automatic
node.session.auth.username = YOUR-ISCSI-USERNAME
node.session.auth.password = YOUR-ISCSI-PASSWORD
discovery.sendtargets.auth.username = YOUR-ISCSI-USERNAME
discovery.sendtargets.auth.password = YOUR-ISCSI-PASSWORD
Save and close the file then restart the iSCSI service:
# sudo /etc/init.d/open-iscsi restart
Next you’ll need to run a discovery against the host to find out what targets it has available.
# sudo iscsiadm -m discovery -t sendtargets -p IP_ADDRESS_OF_SERVER
At this point you should see a list of targets available, you’ll want to copy the ID (generally starting with “iqn.”) to your clipboard and then login to the node:
# sudo iscsiadm --mode node --targetname TARGET_ID --portal IP_ADDRESS_OF_SERVER:3260 --login
Last but not least restart the iSCSI service, and you should be in business.
Formatting the drive
Next up is formatting the drive that you just connected, if you followed the preceeding portion of the guide, you should be able to type the following command to find the descriptor that the drive was as.
# sudo tail /var/log/messages
It will generally be in the form /dve/sd[a-z]. Once you have the descriptor, you’ll want to partition the drive. I personally like using LVM on iSCSI drives, as it theoretically allows you to expand the drive as you need without having to re-format it.
# sudo fdisk /dev/sdx
Enter 'n' for new
Use the defaults for the drive information
Enter 't' to change the partitions type
The partition you just created should automatically be selected
Change the type to '8e' which is the code for Linux LVM
Now enter 'w' to write the partition table to the disk
Once you have the drive formatted, you can view your partition using:
# sudo fdisk -l
It should be something of the form /dev/sdx1.
Now its time to actually format a filesystem on it – I like reiserfs.
# sudo mkfs.reiserfs /dev/sdx1
Now all you need to do is mount your drive and you’re all set.
A few other notes
To Disconnect a Drive:
iscsiadm -m node -T TARGET_ID -u
To attach a drive:
iscsiadm -m node -T TARGET_ID -l