Jun 15

Although languages like APL, Prolog and COBOL might seem unusual to many of today’s programmers, they are serious languages developed to address a specific requirement or a particular model of programming. We’re looking here at those languages that have been designed, first and foremost, to be odd. Referred to as esoteric programming languages, some are intended as jokes, some as parodies of other languages, whereas others were designed to be downright strange.

Esoteric programming languages: is there room in your brain for these nutty devices?

Bizarre or not, though, all of them truly are programming languages in the sense that they really can be used to provide instructions to your PC. Our intention here isn’t to show you a lot about any one language – after all, you’re not exactly going to be using them for genuine programming projects – but to look at three of then, fairly briefly, to give you a feel for the variety of esoteric languages.

INTERCAL

The names of programming languages are often acronyms that give some clue as to their purpose. So BASIC is Beginners All-purpose Symbolic Instruction Code, COBOL is COmmon Business Oriented Language and FORTRAN is FORmula TRANslation. So you start to get a feel for INTERCAL when you read in the manual (which you can find at www.muppetlabs.com/~breadbox/intercal/intercal.txt) that its full name is “Compiler Language With No Pronounceable Acronym, which is, for obvious reasons, abbreviated INTERCAL”. It was designed with the aim of being as obtuse as humanly possible, mainly so you that you can amaze your fellow programmers by your ability to do something useful in this bizarrely complicated language which was designed specifically to have nothing at all in common with any other major language.

Ironically, since our stated aim is to show you how to program in esoteric languages, we’ve not even going to try with INTERCAL. Instead we’ll show you how to use the INTERCAL-J compiler using a sample program provided and then we’ll leave you to peruse the manual. We suggest you do this in a darkened room and clear a week or two from your diary before you start. If you consider this a dereliction of our duties, take a look at the INTERCAL program below, which has been provided to illustrate how fiendishly involved even a simple program can be. Its purpose is to read in 32-bit unsigned integers, treat them as signed, 2s-complement numbers, and print out their absolute values, terminating if the absolute value is zero. A comparable APL program runs to 16 characters.

DO (5) NEXT
(5) DO FORGET #1
PLEASE WRITE IN :1
DO .1 <- 'V":1~'#32768$#0'"$#1'~#3
DO (1) NEXT
DO :1 <- "'V":1~'#65535$#0'"$#65535'
~'#0$#65535'"$"'V":1~'#0$#65535'"
$#65535'~'#0$#65535'"
DO :2 <- #1
PLEASE DO (4) NEXT
(4) DO FORGET #1
DO .1 <- "'V":1~'#65535$#0'"$":2~'#65535
$#0'"'~'#0$#65535'"$"'V":1~'#0
$#65535'"$":2~'#65535$#0'"'~'#0$#65535'"
DO (1) NEXT
DO :2 <- ":2~'#0$#65535'"
$"'":2~'#65535$#0'"$#0'~'#32767$#1'"
DO (4) NEXT
(2) DO RESUME .1
(1) PLEASE DO (2) NEXT
PLEASE FORGET #1
DO READ OUT :1
PLEASE DO .1 <- 'V"':1~:1'~#1"$#1'~#3
DO (3) NEXT
PLEASE DO (5) NEXT
(3) DO (2) NEXT
PLEASE GIVE UP

So to business and in particular we’re going to compile and run a program that prints out prime numbers. J-INTERCAL runs from the command prompt so Select Run… from the Windows Start menu, enter ‘cmd’ into the Open box in the Run window before clicking on OK. Then, at the prompt in the command line window, type ‘cd c:\jintercal-0.12\samples\’ and you’ll notice that the prompt will change to reflect the new default directory which is, in fact, the one where you’ll find an INTERCAL source file called primes.i. To compile it, type ‘Java intercal.Compile primes.i’, noting the capital C in ‘Compile’. All being well it will create the Java class file primes.class that you’ll be able to see if you type ‘dir’ at the prompt to list all the files in the folder. Now to run it, type ‘Java primes’ and you’ll see prime numbers flash down the screen expressed as Roman numerals which is INTERCAL’s standard form of output.

Brainfuck

INTERCAL programs are long and convoluted, aided and abetted, to no small degree, by the requirement to write polite programs with sufficient PLEASE statements included. Not so with the inappropriately sweary Brainfuck. Its programs couldn’t be more different. The aim was to implement a language with the smallest possible compiler – the compiler we’re using is just over 2Kbytes in length (yes, Kbytes, not Mbytes) and the record is somewhat less than 200 bytes. This required simplicity and despite the fact BF is Turning complete, meaning that it can perform any computation that “serious” languages can perform, it has just eight instructions, each of which is represented by a single character. That doesn’t make for the most readable program – so again you’ll reach guru status if you can master it – but it does mean that we can teach you the language in its entirety.

There is no concept of named variables, as there is in most languages. Instead BF has a string of 8-bit memory locations and a pointer that records which of those locations the current instruction will operate on. Initially all the locations contain zero and the pointer is initialized to the left-most location. With that bit of background we can now introduce the eight instructions, which are:

+    Increment the value at the pointer
-    Decrement the value at the pointer
>    Move the pointer to the right
<    Move the pointer to the left
[    Start of loop
]    End of loop (exit if value at pointer is zero)
,    Input an ASCII character and store it at the pointer
.    Print the ASCII character at the pointer

Of course a simple instruction set invariably means a complicated program so the simplest of operations, that might be achievable in a single instruction of a conventional language, can take dozens of instructions in BF. As an example we’re going to create a program that accepts two single digit numbers as its input and outputs their sum. The program to do this is as follows and, despite the fact it has 30 instructions, it still only works correctly if the answer is represented by a single decimal digit:

, > + + + + + + [ < - - - > - ] , [ < + > - ] < .

Your first job is to create a file containing the code showed above using Notepad. Since the space character isn’t a valid instruction it’s ignored and although we put a space between each character to make the code easier to read, you can leave them out. Note also that the full-stop at the end is part of the program. Call the file add.b and place it in the c:\bfd100 folder. Actually Notepad will try to give the file the name “add.b.txt” so you’ll have to rename it in Windows Explorer.

Now start up the command line window and change the directory to c:\bfd100\ – if you’re not familiar with command line prompts we did something very similar when we started to use INTERCAL. At the prompt type ‘bfd add.b’. BF will respond with the message ‘File assembled’, and if you do a directory listing you’ll see that the file add.com has indeed been created. This is a DOS executable file so all you have to do to execute it is to type ‘add’ at the prompt. Now type in your two one-figure numbers (with no space or punctuation between them) and the program will display their sum, immediately after the input, again without a separating space.

Now a slight aside. To be quite honest, of the three languages here, BF is the only one that you might want to delve into. After all, it’s quite an interesting language in its own way, in contrast to the others which are, quite frankly, plain dumb, and that’s being charitable. So to start you on your voyage of discovery, let’s see how the simple program above manages to add together two numbers.

The comma reads the first of the two figures and places it where the pointer is positioned which is, initially, in the left most memory location. However, the value read is an ASCII character which, for the figures 0 to 9, are the codes 48 to 57 so, to yield the actual number represented, we need to subtract 48. That’s achieved with the rest of the code up to but not including the second comma. It does that by moving the pointer to the right and incrementing that memory location six times so that it contains the value 6 which will then be used as a loop counter. Next it enters a loop that decrements the ASCII code eight times and the loop counter once. Since this loop will execute eight times, and each time it will subtract six from the ASCII code, when it does exit 48 will have been subtracted from the value input. The second comma inputs a second ASCII code which, because of the position of the pointer, will be stored one location to the right of the first value and again this will be used as a loop counter. The second loop causes the first value to be input (now decremented by 48) to be incremented as many times as the value of the second ASCII code input. When the loop exits, the value in the left-hand memory location (which is a valid ASCII value for a digit since we only subtracted 48 from one of the input values) is printed out.

BF commands might be terse but that doesn’t mean that programs can’t be made readable. Since all but the eight characters representing instructions are ignored, comments can be placed anywhere, as the following program shows.

===INPUT NUMBER===
+      cont=1
[
-      cont=0
>,
======SUB10======
----------

[      not 10
<+>     cont=1
=====SUB38======
----------
----------
----------
--------

>
=====MUL10======
[>+>+<<-]>>[<<+>>-]< dup

>>>+++++++++
[
<<<
[>+>+<<-]>>[<<+>>-]< dup
[<<+>>-]
>>-
]
<<<[-]<
======RMOVE1====
<
[>+<-]
]
<
]

Java2K

Unlike our previous two languages which were supported by compilers, Java2K is implemented as an Integrated Development Environment (so it’s a bit of a mystery why it’s referred to as DIE for Win32 instead of IDE). But before you get too excited, this doesn’t mean a fancy integrated editor and all the works, it just means that immediately after compiling the code it runs it. To start it just double click on the Java2K.exe icon in the c:\java2k\ folder it’ll open in a command line window and announce its presence with the rather puzzling statement “ELVIS HAS LEFT THE BUILDING AT 0.0.1900 <chair>:”. To see it in action just type the name of one of the sample Java2K programs supplied, say “26”, and you’ll see the output which, in this case, is the letter “F”. Having seen something of the astonishing power of this remarkable language you’ll be eager, no doubt, to try out more of the sample programs. However if, for the moment, you can get over your understandable excitement, we’ll first take a look at Java2K behind the scenes.

Like INTERCAL and most other languages, but unlike BF, Java2K has operators that work on variables. Like BF, Java2K is obscure in the extreme but whereas in the case of BF that was by necessity (i.e. to achieve the goal of producing a tiny compiler), in the case of Java2K it’s by design. First of all, where most languages use decimal numbers, perhaps with the option of binary, octal or hexadecimal, Java2K uses numbers to the base 11 which, as the manual points out, is close enough to decimal. Because base 11 numbers require an additional digit to the usual 0-9, Java2K uses 0-9 plus space. The upshot of this is that since a space will be interpreted as the number ten, spaces can’t be used just to make programs more readable. Second, function names are numbers rather than words, and so too are the names of variables. So you can forget, for example, of using meaningful variable names such as “Total” or sensible instruction names such as “Print”. In the case of this latter instruction Java2K uses the instruction “1 1 “ (note the two spaces, after all this is a base 11 number) instead. And finally, on the subject of obscuration, because numbers are interpreted as functions or variables, you can’t use them as numerical constants. Instead, if you want to refer to the number one, you have to use some function that will produce 1 as its output. The classic way of doing this is to use the code “11 6/*/_\”. If we point out that “11 6” is the divide function, “*” returns a random number, “_” repeats the previous argument, “/” is a separator and “\” is an end-of-instruction marker, it should be clear that this will produce a 1. Surprisingly, then, this statement isn’t quite correct as we’re about to see.

1 1 /125 /131 /119 /125 /11 6/*/_\/_\/125 /13 2
/*/_\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2
/*/_\/_\\/119 /125 /11 6/*/_\/_\/125 /13 2/*/_\
/_\\\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/
_\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/
_\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/
_\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/
_\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/
_\/_\\/119 /125 /11 6/*/_\/_\/125 /13 2/*/_\/_\
\\\\\\\/*\1 1 /125 /119 /11 6/*/_\/13 2/*/_\\/
125 /131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/_\
/_\\/119 /125 /11 6/*/_\/_\/125 /13 2/*/_\/_\\\
/125 /131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/_
\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/_
\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/_
\/_\\/131 /119 /125 /11 6/*/_\/_\/125 /13 2/*/_
\/_\\/119 /125 /11 6/*/_\/_\/125 /13 2/*/_\/_\\

Using the Java2K IDE (sorry, DIE) run the program 13 which is supposed to display “Hello, World”. We’ve included a small chunk of it above. Run it a few times and you’ll probably notice something odd – it doesn’t always get it right. The reason for this is that unlike virtually any other language, Java2K is a probabilistic language rather than a deterministic one so all its functions generate the “correct” answer only 90% of the time; for the remaining 10% it will give a random result. So the method of generating a one that we saw above only has a 90% chance of success. And that’s just for generating a one. The obvious way of generating a two is to add two ones together using the code “125 /11 6/*/_\/_\” but we’re now introducing another instruction that also has a 90% chance of success so the combined likelihood of getting the expected result drops to 81%. In this light of this you might find it surprising that the program 13 manages to produce “Hello, world” as often as it does.

The fact is that there are clever tricks that Java2K programmers can use to improve a program’s success rate but the result is that even the simplest of programs can be extremely long, not to mention virtually incomprehendable. As proof of this why don’t you take a look at program 13 using Notepad. Having done so we suggest that you use the experience to convince yourself that there are better ways of spending your time than attempting to learn Java2K. If you choose to ignore this advice you’ll find the programming manual, in all it succinct glory, at www.p-nand-q.com/humor/programming_languages/java2k/manual.html but we won’t be responsible for the consequences.

Tags: acronym, API, business, Development, device, directory, Discovery, Environment, memory, requirement, sla, space, type, Windows, XP
Jun 15

Online apps let you become more productive on the move, doing away with software installation entirely.

Thanks to the ubiquity of internet access, web-based applications are taking off like never before. Beyond the realms of Twitter and Facebook lurks a fresh and vibrant world of online software that’s designed to run anywhere on our connected planet.

As the distinction between computers, mobile devices and the internet continues to blur, web applications are coming into their own, becoming globally important services. These are sites that do one useful thing and do it well.

But sites promoting applications have been around for donkey’s years, you might say. What’s the difference between a web app and an application that’s available for download on the web? Well, web apps are applications that run over the internet. So unlike the free utilities hosted on Sourceforge or similar, there’s no download, installation or configuration to carry out, nor hours of frustration to endure while you try to find the right libraries to compile them. Just point your browser at the relevant website and it will do the rest.

Outside of the box

Freed from the restrictions of an operating system’s windowing subsystem, software designers can allow their imaginations to run riot. Interfaces that owe more to high-tech thrillers than to Windows, Linux or Mac OS X are beginning to appear. Also emerging are more intuitive drag-and-drop interfaces that require at most a few seconds of exploration to get you going. Software use is slowly evolving and becoming as much about discovery and experimentation as it used to be about reading manuals and clicking options.

In this special roundup, we bring you 10 cool web apps that all share these traits. It’s a diverse bunch, ranging from future essentials to those that you’ll need infrequently. They all exhibit the sort of rich functionality that is beginning to appear through the medium of web browsers, and remove the need to download and install an application suite. If you want something, it’s probably already been written, and so we’ve also included a site that will help you to find other incredible web applications. Happy browsing!

Newsmap

Newsmap is a global news aggregator site like no other, and it’s almost guaranteed to get people peering over your shoulder as you use it. The app presents a page covered in blocks of different sizes. Each represents a story, coloured by subject. Newsmap takes input from news feeds and then gives the stories that are more prominent bigger boxes on-screen, a little like a tag cloud. Simply move your mouse over a story to see its details and a link to the original article.

PC Plus Verdict: 4/5

Instapaper

Instapaper is a way of bookmarking long web pages so that you can read them when you have time later on. The URLs are stored in Instapaper’s central database, so you can access them from anywhere. A range of iPhone apps support it, as does the Kindle, making it flexible and a great way of keeping hold of interesting things to read on long journeys. To use Instapaper, drag and drop the ‘Read Later’ icon onto your toolbar. When you subsequently find a page you want to save, just click the icon.

PC Plus Verdict: 4/5

Lovely Charts

There are plenty of times when you need access to some good chart-drawing software for just half an hour. However, it’s usually supplied as part of a far larger application. Lovely Charts is different. It’s a free web app that creates some very lovely charts indeed. After signing up and creating a new document, you simply drag and drop symbols and connectors from a range of predefined types to create the chart you want – anything from a simple flowchart to a complex route map.

PC Plus Verdict: 4/5

Bing Visual Search

Bing’s Visual Search capability is still in beta, but it’s already showing promise as a new way to search the expanding universe of information out there. On the main Bing page, click the ‘Visual Search’ link. Search categories are organised into galleries, and everything is point-and-click. Instead of typing in your search term, you simply click the relevant picture. The list of galleries is still small, but it’s an interesting glimpse of what could be to come.

PC Plus Verdict: 3.5/5

Fonolo

Calling Fonolo a work of genius is perhaps a little strong, but if you’re heartily sick of wading through phone menus to talk to a human being then it probably comes close. Fonolo walks you through company phone systems to find a human voice. If a company isn’t listed, you can add your own, and test the service by calling special test hardware set up by the developers. Ideal for Skype users, Fonolo’s is also available for the iPhone, which should see its popularity rise further.

PC Plus Verdict: 4/5

Netvibes

Netvibes allows you to create what it calls a dashboard for your interests. Unlike a simple RSS feed reader, the app has a large number of widgets that present feeds from your favourite sites in a highly editable form, making it very customisable. Netvibes is also partly a social-networking service. People can follow you and read your public page if their interests are the same as yours. For the sake of privacy, you can also set up a private page with feeds that only you can see.

PC Plus Verdict: 4/5

Floor Planner

People are crazy about home improvement at the moment, but good, free planning software is hard to find. The free version of Floor Planner allows you to create a plan, make specific rooms and then decide where to place the windows, doors and any of a large number of items of furniture. You can inspect your work in 3D from any angle to see exactly how your ideal home would look. You can then save your work and send it straight to your architect – easy peasy!

PC Plus Verdict: 4/5

Wakoopa

The brainchild of Dutch founders Wouter Broekhof and Robert Gaal, Wakoopa is a social-networking site that is designed to help its users discover new web apps and other software they might enjoy. It does so by first searching for people that use the same apps and installed software as you do. It then finds the software they use but you don’t, and which they rate highly. These it recommends to you. But how does Wakoopa know what software you and others use? A downloadable tracker monitors the sites you visit and the installed applications you use.

Every 15 minutes, it sends this information to your Wakoopa profile for those on your contacts list to take a look at. When your contacts search for new apps, this information is cross-matched with their own to generate a selection of software recommendations picked especially for them.

It’s a simple idea, and one that lets you explore an ever-expanding universe of web apps and installable applications and utilities without ever having to spend hours scouring the web for information – plus you know that none of the programs will turn out to be malware.

Explore and amaze

Once the tracker is installed, right-clicking on the Wakoopa icon in the system tray enables you to suggest a new application that others may like to try. To keep the underlying database free of spam, any suggestions you make that aren’t either installed apps or something that runs in your browser will not be accepted.

When you find a particularly intriguing application in Wakoopa that you’ve never heard of before, clicking on its symbol opens a page giving its details, alternatives that you might like to try and – perhaps most importantly – both good and bad comments from its existing users. This enables you to quickly make decisions about whether to use the app without the frustration of downloading and installing it, only to later discover that it’s not for you.

As well as relying on custom recommendations generated via your contacts list, you can also use the Wakoopa search box to simply enter an application field, making software experimentation as easy and hassle-free as it could ever possibly be.

PC Plus Verdict: 4/5

RescueTime

You’re in the middle of writing an important email but the right words won’t come, so you decide to spend a couple of minutes reading your friends’ statuses on Facebook to clear your head. By the time you’re finished, you fancy having a look at what the celebrities on Twitter are up to. News doesn’t read itself, so it’s off to the RSS feeds next, stopping on the way back to drop by a hobby forum. Armed with more coffee after posting a detailed rebuttal of another forum member’s argument, it’s time to check Facebook again for any replies, and perhaps to glance at Twitter again to make sure that Stephen Fry hasn’t unexpectedly returned. What began as a break to clear your head has somehow blossomed into over an hour of wasted time.

With so many cool new web apps appearing, distractions can only get worse. Some are great for getting things done, but without that vital pinch of self-control, we risk becoming ever busier while paradoxically achieving far less. RescueTime promises to show you how you spend your time online, and also to help you develop the increasingly important skill of self-control.

After installing a Data Collector plug-in, you tell RescueTime the three most distracting and three most productive things you do online. Data Collector then logs the time you spend using your local apps as well as the websites you visit, and can even monitor which of your browser tabs is active. You can also tell it to ignore the time you spend away from the PC so that you get an accurate view of your working day.

Once the Data Collector plug-in has gathered enough data, you can go to your RescueTime account and view detailed reports containing information on everything from the sites you visit to how efficiently you use your time based on how you categorise your activities.

The personal Solo Lite version of the service is free. The paid-for Solo Pro edition ($6 to $9 a month) allows you to block unproductive websites when you visit them too much, and alerts you when Data Collector notices you’re spending too much time dodging work. But you don’t need to splash out: the free service provides a fascinating insight, and helps you to learn a skill that will surely become as essential as using a search engine.

PC Plus Verdict: 4/5

Tags: application, apps, Computer, computers, database, developers, device, Discovery, email, facebook, functionality, Hardware, information, interface, Internet, iphone, linux, Mobile Devices, network, Networking, Personal, Software, Spam, system, system tray, type, web, web application, web applications, widgets, Windows, XP
May 13

Linux is blessed with a variety of methods for accessing, expanding and building dynamic, scalable storage solutions. And they’re not just for industry experts either – even everyday Linux users can get access to a great deal of functionality by sharing and accessing data across a network.

Set up iSCSI and your data will stream from your PC like a magical rainbow. Perhaps. If you’re very lucky.

But there’s a new generation of solutions that can increase performance, offer more features and improve security – one of which is iSCSI. As its name implies, iSCSI is a version of the SCSI protocol, which is responsible for shuffling data between various SCSI devices. The key difference with iSCSI is that instead of transporting data across local cables and buses, the ‘i’ takes that data across the internet or your local network, attaching remote storage devices to your local system. It’s perfect for storage area networks (SANs) in particular, and you’ll find network administrators in enterprises of all sizes singing the praises of iSCSI’s ability to combine big-business fibre channel commands with generic networking hardware, saving their departments thousands of pounds in both hardware and infrastructure costs. iSCSI is also a great general-purpose remote storage solution that could easily replace the NFS protocol.

Understanding iSCSI

You can now find iSCSI in many network-attached storage (NAS) devices for the home and even standard Linux installations. This is because it’s a great storage protocol for an expanding network. It might be hard work to master, but you can build a working configuration with relative ease. The great advantage that iSCSI has over some of the alternatives is that drives are exported as block devices, just as blocks of data would be transported over an old SCSI cable. This means that, to the Linux kernel, these drives are handled exactly like local block devices. This makes it perfect for connecting the storage area of a database to the client application or, more recently, the virtual storage devices used by VMware and VirtualBox virtual machines. It’s also ideal if you want to run a machine without any local storage – traditionally the domain of NFS.

Use ‘apt-get install iscsitarget’ to add the appropriate packages to your installation.

Before getting started, your first step should be to familiarise yourself with some of the concepts that are used by iSCSI. These appear to take their names from the Terminator films, with the two most important being the Initiator and the Target. The Initiator is the iSCSI equivalent of the client. It’s the machine you want to have access to the remote data – the one that’s running the applications, or your desktop. The Target is the place the Initiator grabs the data from – another machine running the iSCSI server software and managing the requests to and from the storage medium. You’ll often find NAS drives running the Target server, for example, and you’ll only need to run the Initiator on your local machine in order to access the Target drive.

Set up the Target

It’s possible to share a large variety of different storage types over iSCSI, but the easiest to configure are entire drives. iSCSI connects devices at the block level, which means the job of partitioning and formatting can be left to the Initiator rather than the machine that’s attached directly to the hard drive. On our system, the drive we used was listed as /dev/sdb, and we’ll stick with this example throughout this tutorial. The system drive is normally /dev/sda. To find out what yours is, type fdisk -l on the command line for an overview of what’s connected to your system.

Edit the configuration file in nano. You’ll need to add a line which ensures iSCSI is switched on.

On the Target machine, you first need to install the ‘iscsitarget’ package. You can do this either from the Synaptic package manager or by typing sudo apt-get install iscsitarget on the command line. This will also install several configuration files, and the first of these that we need to look at is ‘/etc/default/iscsitarget’. You can type sudo nano followed by the path to the file name to edit it on the command line, or use your favourite desktop editor if you prefer. We only need to make a single edit here – making sure ‘ISCSITARGET_ENABLE=true’ is the only line in the file. Nano users need to press [Ctrl]+[X], then [Y] to save the changes.

Edit configuration files

The next file we need to edit is ‘/etc/ietd.conf’, which you’ll need to open in an editor. This document contains a working configuration, with lines using the # symbol designated as comments and therefore out of action.

The first line we need to edit defines what’s known as the iSCSI qualified name, or IQN for short. Just search for Target, followed by iqn. As with pages on the net, this IQN name has to be unique to your installation, and it takes the form of ‘iqn’, followed by the year and month, then a reversed version of your domain name. This is then followed by a colon and a reference to whatever you’re going to call the target storage device. This can be anything you like. Here’s what we chose:

iqn.2010-01.com.example:storage.disk2

Next, we need to define the drive that’s going to be shared over iSCSI. Remove the # symbol from the line starting with ‘Lun’ and modify it to read Lun 0 Path=/dev/sdb,Type=fileio. You need to change ‘/dev/sdb’ to the location of the drive that you’ve decided to share. Next, uncomment the Alias line at the bottom of the current section and save the file.

You’ll need to do some deeper editing to the ‘/etc/ietd.conf’ file.

You may have noticed that there are two lines available for a username and password, but we’re going to leave these untouched for now because we’re running our iSCSI device over a trusted network. You can always come back to this point and change the configuration after you’ve got the basic connection working, if you think that you need to.

To enable the device to be shared, open ‘/etc/initiators.allow’ and add iqn.2010-01.com.example:storage.disk2 ALL. When you get the connection working, you’ll need to change ‘ALL’ to the IP address of the machines allowed to access your iSCSI device, but for now we’re trying to remove all obstacles that could stop us getting the connection working. Start the Target server by typing sudo /etc/init.d/iscsitarget start.

Set up the Initiator

It’s now the turn of the other machine, the Initiator. To begin, you need to install the ‘open-iscsi’ package. Once that’s done, open the ‘/etc/iscsi/iscsid.conf’ configuration file and look for the line starting with ‘node.startup’. Change the default value of ‘manual’ to automatic, save the file and restart the service by typing sudo /etc/init.d/open-iscsi restart.

Make sure you change the node startup option to ‘manual’.

Almost everything is now configured and ready to go. Our next step is to probe the Target machine to see what storage services it offers, hopefully listing our drive in the process. Type iscsiadm -m discovery -t st -p, followed by the IP address of the Target. You can find this by typing ipconfig on the Target machine. If everything is set up correctly, you should see the IQN of your drive as output to the iscsiadm. This is the output we received:

iscsiadm -m discovery -t st -p 192.168.1.61
192.168.1.61:3260,1 iqn.2010-01.com.example:storage.disk2

Now you know that the Target machine is correctly configured and that iSCSI can see the remote storage device, you need to type iscsiadm -m node. This will automatically create configuration files within /var/lib/iscsi/nodes for the storage unit on your local machine, which will allow the Initiator to mount the device automatically when the service is restarted. You may need to do this manually by typing sudo /etc/init.d/open-iscsi restart.

The remote drive should now be mounted locally. The best way to check is to type fdisk -l to list all the storage devices attached to your machine. The iSCSI drive should be part of the output, but you won’t see any indication that it’s being connected over a network. That’s the great advantage of using iSCSI.

Mount the drive

iSCSI passes the block information, so you need to format the remote drive from the Initiator machine before it can be used. This process is exactly the same as partitioning and formatting any other drive on your system. You could use fdisk on the command line, for example, or you could take the easy route and use a graphical partitioning tool like GParted, which you can install through your distro’s package manager.

After launching GParted, you first need to select the remote drive from the dropdown list in the top-right of the main window. As with fdisk, the iSCSI drive looks exactly like a local drive, so you need to take special care to select the correct device. You can lose data from other drives permanently with GParted, so proceed with caution.

If you’re hooked up to your target drive you should be able to treat it like any locally connected module – including partitioning it.

With the remote drive selected, click on the large grey area in the middle of the window marked ‘unallocated’. This is the unpartitioned area on your remote drive. Click on ‘New’. By default GParted will use the entire disk, but you’re free to subdivide the remote drive in exactly the same way you would a local one if you prefer. Leave ‘Primary Partition’ selected, then select ‘ext4’ as the filesystem and give your drive a meaningful label before clicking ‘Add’. Click on ‘Apply’ to make the changes to the remote drive, and then simply sit back and wait while the formatting process finishes.

Now that the drive is correctly formatted and partitioned, it’s time to mount it onto the local filesystem so you can start reading and writing data to it. You can use the ‘mount’ command to attach the drive just as you would any other, but there’s one small difference that you have to consider whenever you use multiple iSCSI devices – they might not always have the same /dev path. The solution is to navigate to the device using the /dev/disk/by-path/ nodes, so you can be sure you’re getting the same disk every time.

If you type ls /dev/disk/by-path, for example, you can easily see which devices are using the IQN address. In our example, we mounted the remote drive onto the local /mnt/iscsi folder with the following commands:

mkdir /mnt/iscsi
mount /dev/disk/by-path/ip-192.168.1.61\:3260-iscsi-iqn.2010-01.com.example\:storage.disk2-lun-0-part1 /mnt/iscsi

You can now read and write files to the /mnt/iscsi mount point, and these are passed directly to the remote drive just as if they were connected using an extremely long SCSI cable.

iSCSI on NAS boxes

Two of the trickiest parts of using iSCSI are finding the hardware and configuring the Target machine, but luckily there may be another option if you have a Linux-based network-attached storage box. Many of these will offer up a chunk of the storage inside the box over an iSCSI connection, and you can usually activate and configure this facility with just a couple of clicks. Some of these will let multiple Initiators access a single target and enable you to add CHAP password authentication. Then it’s simply a case of running the iSCSI discovery procedure on your Initiator hardware. If you’ve chosen to use a password and username, you’ll need to run the ‘iscsiadm’ command on the Initiator to add those values to the configuration file for that Target. The command takes the following format:

iscsiadm -m node --targetname IQN --portal IP AND PORT OF TARGET --op=update --name node.session.auth.

You need to run this three times, changing the end parameters each time. With the first execution, add authmethod –value=CHAP to the authentication check. For the second, add username –value=username to specify the username for the connection, and for the third execution add password –value=password to specify the password.

Create a virtual hard drive

Many more technical distributions, such as Fedora, use logical volume management (LVM) for local storage and filesystems. One of the advantages of LVM is that you can shrink, expand and create partitions on the fly from the pool of storage on your machine. Logical volumes can be used for all sorts of tasks. Virtual machines often use them to keep data from the main system, and they’re handy if you enjoy playing with filesystems. They’re also useful if you want to try iSCSI, because you don’t need to have a spare hard drive – you just need the space within your logical volume pool.

The key to adding new virtual drives is the ‘lvcreate’ command. We used the following command to create a 10GB logical volume: lvcreate -L10G -n vdrive vg. This creates a volume called ‘vdrive’ in a volume group called ‘vg’. You’ll need to take a look in your /dev directory to discover the name of the logical volume group used by your installation. After creating the drive, it appears in the /dev volume tree just like any other device and you can share it across the iSCSI connection like a real hard drive.

Even without LVM, there are other options for dynamically shared storage. You could create an image file, for example, by typing dd if=/dev/zero of=/mnt/iscsi.img bs=1024k count=1000. The ‘count’ value is the size of the image, while ‘/mnt/iscsi.img’ is the file that’s created. You can use that path as the source for the iSCSI Target on the ‘Lun 0’ line in the ‘/etc/ietd.conf’ configuration file, and use it like a real partition.

Virtualisation

iSCSI is commonly used by cloud applications and the world of virtualisation. This is so you can access the same hard drive data regardless of where the virtual machine is running. If you’re in the market for a major, enterprise-grade virtualisation solution that uses iSCSI, take a look at VMware’s ESXi solution, which is available for free from www.vmware.com.

Boot options

If you want the Target iSCSI device to be available each time you boot the Initiator machine, you will need to add the remote device to the ‘/etc/fstab’ file. The quickest way to do this is to copy another line in the file and change the parameters to suit the iSCSI device. Make sure the path uses the ‘by-name’ format so that you can be sure you get the same drive at each boot.

Tags: application, authentication, business, database, desktop, device, directory, Discovery, functionality, generation, Hardware, industry experts, information, Internet, ip address, linux, Nano, network, Networking, parameters, partition, performance, security, Server, Software, space, storage, storage service, system, type, virtual machine, virtualisation, vmware, XP