RHEL5 iSCSI Target/Initiator

iSCSI is a protocol that allows you to use a disk in a remote machine, locally as a block device. It is a very popular SAN protocol, which allows the consolidation of storage into one large storage pool.

In iSCSI terminology, a target is a storage resource located on an iSCSI server and an initiator is a client which will be connecting to a target.

In this post I will demonstrate how to setup an iSCSI target and initiator on RedHat Enterprise Linux 5.

Target

RHEL5 has the stgt target daemon included with it. This is the server which allows initiators (clients) to connect to the disks using the iSCSI protocol. It is installable using yum:

yum install scsi-target-utils

To share a disk over iSCSI, you can either use a disk image, or a block device. I prefer to use LVM logical volumes as LVM allows easy management of free space.

Stgt’s configuration file lives in /etc/tgt/targets.conf, although most configuration can be done using the command line (although this is not persistant across reboots, so I prefer to use the configuration file).

To create a target, just add the following lines:

backing-store /dev/DiskArray/Archive1

Please note that you must replace iqn.2009-02.com.hamzahkhan:archive1 with your own domain name, and resource name. It must be in the iSCSI Qualified Name (IQN) format, iqn.yyyy-mm.{reversed domain name}:an_easy_to_remember_lablel.

The second line, backing-store /dev/DiskArray/Archive1 specifies the disk/disk image that is to become the target, I am using LVM logical volume although the procedure is exactly the same for disk images, and real physical disks.

By default, stgt will allow all IPs to connect to the target, which is highly insecure! To change this behaviour, it is possible to specify IP addresses which are allowed to use the targets. To do this, just place the following line under backing-store:

initiator-address 10.1.0.4

This will allow 10.1.0.4 to access the target.

Now, use chkconfig to make stgt start at boot, and start up the daemon.

/etc/init.d/tgtd start

chkconfig tgtd on

Thats all there is to it on the server side! All done :)

You can now connect to the target using any initiator, such as the one built into Windows Vista (although I have never tried using Windows).

Initiator

RedHat have included an iSCSI daemon which is also installable using yum:

yum install iscsi-initiator-utils

To connect to the target, edit /etc/iscsi/initiatorname.iscsi and change InitiatorName to something you prefer (Remember! it must be in the IQN format, iqn.yyyy-mm.{reversed domain name}:an_easy_to_remember_lablel. I usually use iqn.2009-02.com.hamzahkhan:hostname_of_box). Next start up iSCSId:

/etc/init.d/iscsid start

and use iSCSI target descovery to find the targets on the server:

iscsiadm -m discovery -t st -p $SERVERS_IP

If all is well, it should output the names of all the targets that the initiator is allowed to connect to!

Next, we need to create the disk nodes. To do this, RedHat have provided a nice start up script. This script will login to all the targets that the iSCSI daemon knows about. We have already used the iscsiadm command to tell the iSCSI daemon which targets exist on the server, so using the script is all that is left:

/etc/init.d/iscsi start

Thats all there is to it! :)

You should have a new disk node in /dev/. You can use lsscsi (yum install lsscsi) to find the exact name if you have a lot of USB/SATA/SCSI drives connected to the machine already.

Now all you have to do is partition the disk, and dump your files onto it :)

Please remember, you must NEVER mount a partition on two machines at the same time. Doing so will cause data loss!

It IS possible to mount the same disk on multiple machines, but this requires a special clustered filesystem such as GFS.

OpenSWAN

Lately I’ve been playing with OpenSWAN and IPSec in general.

For the last few years I’ve been using OpenVPN as my home VPN server, but recently I bought a few Intel PRO/100 S Server Ethernet adaptors. From looking on the Intel site the only big difference I could see between these and regular Intel PRO/100 cards was that it has IPSec offloading, which I also remembered seeing IPSec support on my iPhone. So that got me looking into replacing OpenVPN with OpenSWAN on my home router.

In the past, I have come across IPSec quite often, but I never really looked into it. After a bit of reading, I decided to buy “Building And Integrating Virtual Private Networks With OpenSWAN“. I haven’t finished reading the book, but I can say that it is a very well written book for people looking to get started with IPSec. It has quite a nice introduction on the internet and why encryption is so important on the internet. It also explains how encryption was originally only used by the military and how governments around the world tried to stop encryption being used widely across the internet.

On Linux, there are two IPSec stacks, NETKEY and KLIPS. KLIPS is currently the more stable one, and from what I understand, the one which is easier to use. NETKEY on the other hand, is quite a new stack, but due to various reasons, KLIPS was not allowed to be included in the Linux kernel by default, where as NETKEY is.

Since my router machine is running RedHat Enterprise Linux 5, which only includes support for NETKEY, I have been using the NETKEY IPSec stack. So far, the only problem with the NETKEY stack is that creating firewall rules for encrypted packets is much more difficult than it would be using KLIPS, although I was not too disapointed by this since the KLIPS does not have IPv6 support, which, since I like IPv6 so much, is a must for me! :)

Although I had a bit of a problem with the OVH kernel, after a bit of tweaking and compiling and a lot of rebooting, I was able to create an encryted tunnel between my OVH RPS and my home router. If it had not been for all the trouble I had with the OVH kernel (it took quite a while to get the RPS to boot from the iSCSI disk using my custom kernel, rather than use netboot to fetch an OVH kernel), the tunnel would have been set up within a few minutes, which I found amazing as it takes a bit more time and effort to do with OpenVPN.

So far, I haven’t managed to figure out how to use the IPSec offloading feature of my ethernet cards, but I don’t think thats is really a problem considering my router machine is powerful enough to handle the few IPSec connections that I  have setup (Its a 2.4GHz Pentium 4 machine with 1GB ECC Reg RAM).

After a bit more reading, I decided it would be fun to try and get my iPhone connected to my IPSec Server, so over the next few days, hopefully thats what I will be doing! :)

Western Digital 1TB Hard Drive

A few months ago, I bought a Western Digital 1TB Hard Drive (http://www.wdc.com/en/products/products.asp?DriveID=336) for my server.

Since every WD drive I have bought in the past has served me very well, I assumed this drive would do the same…. but VERY annoyingly, I just got an email from smartmon tools telling me that there are an increasing number of bad sectors on the drive! :(

eBuyer has agreed to replace the drive since it is still under warrenty, but the problem is that I have the drive in an LVM volume group, so backing up the data is a little difficult.

It would be easy if I had another 1TB Hard Drive to add to the volume group, the pvmove all the data off the broken one, but I do not have a spare 1TB drive, and eBuyer (naturally), didn’t agree to sending me the new drive before I give the old drive back to them.

I also have 1TB Seagate drive in the volume group, which is performing very well, so very reluctantly, I might just ask eBuyer if they would let me switch it for a Seagate one.

Oh well, I guess for now, my only option would be to buy another 1TB drive, move all the data onto that drive, remove the old drive from the VG, get it replaced, then if I feel brave enough, add the new one to the VG. I’ll have quite a large volume group if I do that (3TB!).

Speaking of which, if anyone has any tips for boosting LVM performance when using large volume groups, please tell me! :)

iPhone WordPress!

Out of boredom I decided to try out the WordPress application for iPhone. It seem quite useable :) .

Hackintosh!

So after my last blog post, I decided to try out OS X inside a virtual machine ….. but after four tries, I gave up and just wiped my hard drive and installed natively.

Installation went surprisingly well, and most of my hardware is “liked” by the hacked versions of OS X (I used iATKOS 5i). Everything that should be working, is working except for my sound card… which is partially working. I hear sound, but the front audio ports for headphones and microphones does not work, and neither does the back microphone socket, but I’m still quite happy with that considering OS X wasn’t designed to be run on my hardware (and apparently with some hacking, I can make those things work too).

So far I’ve been using OS X for two days, and I must say, I like it much more than I had expected.

My first computer was a Mac, and I used a Mac till OS 8.something (in 1999 my dad bought me a my first PC because Macs were, and still are quite pricy). I was originally quite reluctant to leave Mac OS, but eventually had to BUT I soon discovered Linux, and started using and loving it.

For the last 5/6 years I’ve been using Linux, and I only really used OS X two or three times at my Dad’s work place. I originally thought I would LOVE to have a Mac (with OS X), but a few days ago I changed my mind because I thought I had become too used to Linux (which I have!) and would not be able to use OS X to do everything I want.

I thought there would be lots of things that I would not like about OS X, but it turns out the list is actually a lot smaller than I thought.

There are a few things I don’t like about OS X, and some things I miss from Linux. For example:

  • I really hate the keyboard bindings. This is probably because I’m now used to Linux shortcuts etc. I managed to “fix” some of them (eg in the Terminal app I wanted page up/down to actually send the page up/down characters).
  • I STILL dislike iTunes, although it is much better than in Windows. I really miss MPD with gmpc.
  • I don’t really like the dock. This is probably one of the things that most people DO like, but I’m not really a fan of it.
  • I can’t seem to find a decent IRC client on it. X-Chat Aqua isn’t really quite as nice as it is on Linux, and Linkinus isn’t too good either in my opinion.
  • I don’t really like the fact that OS X doesn’t depend THAT much on log files. It does use them, but I don’t think the details it gives are always useful.
  • I kinda miss the ability to configure things from the command line. I don’t know if you can configure things from the command line in OS X, but from what I understand you can’t really do much system configuration from the command line except small hacks.

Overall, I like OS X, and will probably continue using it on my machine till I get a real Mac (hopefully in September).

Some of the things I like about OS X:

  • Undoubtably the thing I like most is how everything is so tightly integrated with each other. While this is also possible on Linux, it DOES need a lot of configuration to get it perfect. On OS X, it is all ready to go, out of the box. Linux is also heading that way, with things like d-bus interaction between apps has become more and more efficient, but not all apps take advantage of this yet.
  • I like the fact that everything looks the same, and isn’t “odd”. By this I mean there is no “KDE” look, or Gnome Look. Everything fits in fine with the UI. I know you can use special tools etc to make KDE apps fit into Gnome, and vice-versa, but again that requires configuration. Personally I didn’t ever bother doing that, although I didn’t really like how KDE apps didn’t fit into my Gnome desktop.
  • Close source applications work better on OS X than their Linux equivalents. For example Skype is on Linux and on Mac OS X, but the Mac version is MUCH more stable than the Linux version. I guess this is mainly due to all the sound systems that are available in Linux. Skype switched to ALSA recently from OSS, but now a lot of people want PulseAudio support too, or ESound support etc. There are too many choices I think, and I think that is causing a bit of chaos. This issue would probably be fixed a lot faster if Skype were open source, but I don’t think people should live in a dream world where everything is open source, sure it would be nice, but lets face it, thats never gonna happen. So in reality, the better choice will indeed be the one that works, and in my opinion, so far in OS X is the better choice.

On OS X, I’ve managed to actually have a pretty good quality conversation over Skype with my sister, which I haven’t been able to on Linux.

I don’t know if this makes me sound like I’m anti-Linux now, believe me I’m not! I LOVE Linux still (more than I like OS X!), in-fact I’m running it inside a VMware Fusion virtual machine right now and will wipe my machine and put Gentoo back on it as soon as I get a real Mac to sit beside my Gentoo machine.

I also thought I’d mention this: I know a lot of Linux users who say EVERYONE should use Linux, and there is no excuse for using Microsoft or Apple products. This goes to the people who think this way: You are all idiots :) .

Some people say Apple and Microsoft products should be avoided because they are buggy. Sure Windows IS buggy, and sure OS X probably has some bugs too (I haven’t found any yet!). BUT truthfully, can anyone say that Linux applications are bug free? The only difference is that you have the ability to fix the bugs yourself…. which is quite a useless ability if you are a normal user who doesn’t give a damn about how the internal works, and doesn’t have a clue what C++ is!

To be quite honest, A LOT of Linux applications have A LOT of bugs. NetworkManager is quite buggy, so I stopped using it and manually setup wpa_supplicant to connect to my wireless network, but I don’t think my Dad can do that! A normal user like my father needs GUIs to do everything, they are easier to use for someone who has no clue how to use a CLI (and doesn’t want to learn how to use it!). Naturally Linux IS becoming more and more user friendly, and I think there WILL be a point where I can safely install Linux on either of my parents computers, and not have to worry about them not knowing how to do something, but till that day comes I REALLY think it is pointless and ignorant for people to tell everyone to boycott Apple and Microsoft, and switch to Linux unless they are willing to understand the internals a little and figure out how to manually edit things from the CLI, which over 90% of the world’s population probably isn’t :) .

Besides… Apple products are really nice in my opinion, not very buggy and they work very well! (I love my iPhone <3!!!)

Lol like most of my posts, I wrote this while super sleepy so it probably makes no sense, oh well.

iPhone / Linux / Mac OS X / Windows

Last week my phone contract ended, so I decided to upgrade to an iPhone 3G.

Till now, my main two phones have been the SE P910i and K800i, both of which have served me very very well for what I was using them for. There are a few reasons I decided to switch over to an iPhone. Firstly, I was originally using my K800i with a 2GB M2 memory stick as my MP3 player. As I soon noticed, 2GB isn’t really enough sometimes. I think the iPhone’s 16GB worth of space will give much more freedom. Also, I usually use my PSP to watch movies/TV shows when ever I go on the train or bus. I really like using the PSP for that purpose, the screen size is not bad, and the quality is pretty good too. BUT, then I have to carry around 2 phones and a PSP which can be quite irritating. So considering the size of the iPhone screen isn’t much smaller than the PSPs, it would be a perfect replacement to watch videos on, and have only 1 gadget to carry around. Thirdly, I often use my P910i to go on IRC or MSN from places where I can’t access a computer (Grandmothers house etc). I really liked using my P910i for this purpose, it was easy to type on and the application I use on it for MSN/Jabber/Yahoo is quite nice too (IM+). But from what I have seen, iPhone alternatives are just as good, or even better and have less bugs (afaik, IM+ for UIQ2 phones is no longer developed :( ).

In “preperation” for my iPhone getting delivered tomorrow, I decided to actually “try” out iTunes. After 3 hours of playing with it, I can say this much: I hate it :D .

The main reason for this is that I cannot make it “watch” a folder. All of my music is stored on my server, where my brothers dump music too. Quite often my brothers have put music there without me knowing, and so a “folder watch” feature would be very nice in iTunes. On Linux, I use MPD as my music player. I have a crontab script which makes MPD update its database every hour, so if there is anything new on my server, it will automatically be added to my library. After some googling I found iTunes Library Updater (http://itlu.ownz.ch/wordpress/) which works I guess but it still requires quite a bit of user interaction.

After Googling a bit more, I got the impression that even in Mac OS X I would have this problem which got me thinking: I would feel quite uncomfortable in OS X, just as I do in Windows.

I never really thought about it before but most of what I do on Linux, I do through the command line (Which is why I wanted a Mac for so long I guess). I find the command line much more efficiant than using a GUI, and imo Mac OS X is most popular due to its idiot-proof GUIs etc. Now that I think about it, when I first go on any machine, I open some sort of terminal. On Windows, I fire up Putty before anything else and on Linux Gnome Terminal is on my auto-startup apps list.

I accept that Linux does have a lot of things missing, but I think that OS X and Windows both have just as many things missing from them, and so far I think Linux is fixing these missing things faster than Apple or Microsoft are. (I guess thats mainly because most of these “issues” with OS X and Windows don’t effect the everyday user, but do effect Geeks!).

I was originally intending on listing reasons why I think I wouldn’t feel comfortable in OS X, but that will come another day (after I have actually tried out OS X).

A lot of you know I’ve wanted a Mac for AGES, but I can now say that I’m not sure if I really want to switch to OS X… of course I will try it out, who knows, I might be wrong!

Now to find an easy way to put music/videos onto the iPhone from Linux….

Astaro Mail Gateway

astaroI finally moved my email server back home!

For quite a while now, I’ve been using Google Mail to host my email for all my domains, but I’ve always felt that it wasn’t as “nice” as running your own server.

Some reasons I moved away from Google are:

  1. Although it might just be me, I’ve noticed that their IMAP server isn’t very stable. Quite often I haven’t been able to log in for quite a while.  (This was the main reason!)
  2. I _REALLY_ dislike the labeling feature of Gmail. It makes IMAP messy, same email in multiple folders (even though I don’t use lables!)
  3. I find the “Google Mail” folder annoying on IMAP, every time I get an email it shows up as a new email in my Inbox folder and Google Mail folder

Anyway, I setup Postfix with MySQL (I will be converting to LDAP soon) and noticed that I actually get quite a bit of spam.

From past experience, I knew that setting up a spam/antivirus filter requires quite a bit of maintinance, so I wanted a “lazy persons” solution.

After a bit of Googling, I came accross Astro Mail Gateway.

So I downloaded their VMware appliance and booted it up. It wasn’t as easy as I thought initially since the VMware image seems to have IPtables running which blocks access to the web interface, although I only had 4 hours sleep at that time so I could be wrong. So I had to log into the console, and disable IPtables temporarily, get into the web interface and configure the IP addresses to match my network (the default config uses 192.168.0.0/24, where as I use 10.1.0.0/16). After this it seems the UI added the various rules to IPtables to let me access everything properly.

After a bit more configuring I had a fully functional spam filtering proxy! :D

The only issue I’ve had with Astro so far is that it won’t accept my home user licence so in 28 days or so it will stop functioning :( , but hopefully the Astro support guys will reply to me and tell me how to fix that! :) .

What is really nice about Astro is that it makes nice graphs for you, and gives a lot of statistics such as Top Spamming countries, and Top malware reports (So far I’ve got 70% of my spam from the US!).

The only thing I wish Astaro Mail Gateway had is IPv6 support, but its not urgent I guess considering IPv6 isn’t used so widely yet.

Facebook!

After three or four quite useless posts, I thought it might be time for a “real” post, so here it goes! :)

As everyone might know, Facebook have rolled out the new layout and have removed the old one. In a final “fight” to use the old one, A LOT of facebook users joined the Facebook developers group, only to find that the old layout has been removed completely (as far as I know).

A lot of people think that there was not any “real” problem with the old facebook but the issue with the old layout that triggered the need for a new layout was the fact applications were shown on one page. This meant that some pages became VERY cluttered for the users who seemed to add every application available!

In my opinion, the main reason Facebook is such a sucessful site compared to other social networking sites is that it is neat. If you look at Hi5, MySpace, BeBo, they all use quite flat pages (very little to no AJAX!) which the user can modify the layout of through the use of CSS.

Most normal users would tell you they would LOVE to be able to customise the look of their profiles on Facebook, but most geeks would probably cringe at this idea. Why? Most people who use such social networking sites don’t really know much CSS or HTML, so they write bad CSS and create horrid pages which take way too long to render and sometimes even crash the browser.

Users who add too many applications are in effect doing the same thing. There are too many things to render (images, text, colours, sometimes even flash!), and so your over all Facebook “experience” is brought down to something which is not so plesurable.

Although most people may be thinking that the new layout gives them a worse experience, I’m pretty certain, it is much better than having cluttered profile pages which sometimes crash your browser :) .

I will accept that the new layout COULD be better, but there is no doubt about it, the new layout beats the old one overall.

Wii song

Just to be clear, I don’t really hate the Wii. I just found the song funny :P

Nerd Tests


I am nerdier than 93% of all people. Are you a nerd? Click here to find out!

I’m bored and Woof posted that link, I BLAME HIM!