Archive for the ‘Linux’ Category

VIM editor tip of the day

Sunday, November 2nd, 2008

If you’ve spent any time at all on this site then you know that VIM is my preferred text editor. Even though I’ve been using it for years I still learn something new about the editor from time to time. Here is something that I just figured out a couple of weeks ago. It turns out VIM provides a simple way to repeat exactly what you last did. By simply pressing the period key, VIM will repeat whatever command -or- text you last entered.

For example, lets say you’re editing an HTML file that has a list of links. Before each link you want to add a generic image. You could do this a few ways; type in the text each time, use a search and replace or copy and paste. Using period is just one more method to add to your toolbox. To use this trick, enter INSERT mode by pressing i. Enter in the text you want to enter before each link (or whatever it is you need to repeat a few times) and when you’re done press ESC. Move to the next line and press the period key. Whatever you typed previously will be inserted to the right of the cursor. You can do this as often as you like but as soon as you delete a letter, line, insert different text or whatever the “period key” shortcut will begin to do that action instead.

Another way to use this is if you’re deleting lines of text over and over. Say you want to delete 10 rows of text at a time until you’ve deleted what ever it is you need to delete. You could press d 10 down arrow and then each time you press the period key you’ll repeat the same action.

Adding high speed storage to that Macbook lacking firewire

Friday, October 17th, 2008

Here is a copy/paste of a post I did on a forum. It describes in very light detail how to add iSCSI based storage to a Mac. With the new Macbook lacking firewire, this might actually become a more popular method.

In the last couple of weeks I’ve been playing around with a few different bits of technology, one of them being iSCSI. iSCSI is a relatively cheap and efficient method of adding storage to a computer that uses your existing network infrastructure. If you have a gigabit network and a Linux server (I haven’t tested other solutions) you can add as much storage to your Mac as you can fit in your Linux system.

You might be thinking, “I have a 2TB USB/FW drive why would I want iSCSI?” USB and FireWire drives are a fine thing but lets look at some of their disadvantages.

* USB2 is actually slower than many FW400 devices
* If you have a mac with just one FW port and your external drive doesn’t include a FW port, you can’t attach anything else to that FW port AND use your drive
* External drives add noise
* External drives must be located close to the computer, not ideal in a HTPC setup

Here a really quick overview of how it is done, I can certainly provide more detailed information however. Here is a list of what you need to get the job done.

1. Linux server with gigabit ethernet
2. A hard drive or RAID set that you want to share to your Mac
3. gigabit switch
4. Mac with gigabit, the more recent the better
5. GlobalSAN iSCSI initiator for Mac
6. iSCSI Enterprise Target for Linux

Setup your Linux system and install IET. If you’re using Ubuntu, IET might be available in apt. I use Fedora so I compiled IET from source. Edit the /etc/ietd.conf file to point to your disk or RAID set (or even a file that was made using dd if=/dev/zero of=filename bs=1024 count=1 seek=n where n is the size of file you want in bytes). Start the ietd service, /etc/init.d/iscsi-target under Fedora.

Install the GlobalSAN iSCSI initiator on your Mac. Enter System Preferences and click the new GlobalSAN button. Add your Linux server’s IP address to the Discovery screen. Click on the target tab and your disk should be shown, click it and logon to it without a username or password UNLESS you configured one in IET. Be sure to check the persistent tab if you want this drive to appear each time you boot your Mac.

Open Disk Utility and format the iSCSI disk. Your Mac will format the new drive and it’ll soon appear on your desktop. You can use it like any other disk you’ve ever used. You can partition it, copy/delete files, whatever. As far as the Mac is concerned it is a normal hard drive.

In my setup I have an Intel Mac mini, 1.83Ghz C2D and a Linux server built in late January, 2.2Ghz C2D. The disk being shared to my mini is a single 120GB PATA drive. I am able to copy files to the drive with a top speed of 44MB/s. Reading is actually slow but I attribute that to a limitation with the mini’s internal drive. I haven’t been able to test using OpenSolaris as the iSCSI target though OpenSolaris would be a fantastic choice as a storage server.

To be fair, there are some negatives to this setup. The biggest one being you can’t have multiple Macs using the same disk at the same time. You can unmount the disk on one mac and mount it with another one, but having two macs connected at the same time risks your data.

Hosting a Fedora network install using Mac OS X

Sunday, September 28th, 2008

Sometimes it just seems that everything is out to get a guy, nothing goes right. This seems to be the case today when it comes to performing an upgrade on my Fedora Linux based file, web, email, XBMC and whatever else server. After burning three copies of the install media none of them work, despite correct SHA1 verification and burning with different drives. What’s a geek to do?

Do a network install!

I downloaded the full DVD hoping to do a local install from it so I could avoid the long downtime of doing an over the internet based network install. The problem however is that I either have two bad DVD burn drives or there is something goofy with the image I downloaded. Everything about the DVD iso checks out, the SHA1 is fine and I can loop back mount it without issue. Rather than give up I decided to do a network install by mounting the iso on my Mac mini and sharing the contents via web sharing. As it turns out, this is very easy to do.

This little mini howto assumes you have already downloaded the DVD install media for Fedora. If you haven’t, I suggest you do that first.

Enter System Preferences and choose sharing. Click on Web Sharing to enable your Mac’s web server. Be sure to note the IP address. Next, double click on the Fedora DVD install iso. OS X will mount it and make it available to you. Next, start terminal and type ‘cd /Library/WebServer/Documents’ without quotes and press enter. Type ‘ln -s /Volumes/Fed* fedora’ (*type Fed and then press tab to autocomplete) and press enter. On my system the complete command looks like ‘ln -s /Volumes/Fedora\ 9\ i386\ DV/ fedora’

Open finder and browse into your mounted DVD media. Look for a folder called images and copy out the boot.iso file. Burn this file to CD using OS X’s Disk Utility. Next, take that disk to your Linux machine and boot from it. Choose install or upgrade and then when asked where the install media is located choose URL. Enter http:///fedora where is the IP address from your Mac. That’s it, the install will then continue as if you were using a local CD/DVD.

iSCSI in Leopard now a reality — Updated

Thursday, September 4th, 2008

In all my playing with OpenSolaris and iSCSI I decided to give iSCSI using Linux and OS X another shot. Turns out the GlobalSAN iSCSI client for OS X, available for free from Studio Network Solutions, works much better than it did just a couple of months ago. Lock ups, so far, seem to be a thing of the past.

To make use of it I decided to pull the drive out of my external case and put it in my Linux system. I then exported it via the iSCSI Enterprise Target software (available here) already installed on the system. After installing the latest GlobalSAN iSCSI initiator software (available here)on my mini I was able to connect to the iSCSI Lun on my Linux machine.

So far I’m finding that I’m able to get nearly full speed out of the disk and am able to copy large files to the drive at around 44MB/s.

Update: One caveat I have found is it takes a lot longer for the Mac to enter sleep if it is connected to the iSCSI share.

Another bash for loop time saver

Monday, August 25th, 2008

People are sometimes amazed at how quickly I get some things done. Truth be told I’m lazy and hate having to do more than I need to. Sometimes it is great to have just enough programming background to be dangerous.

I’ve posted about for loops before and they are probably one of my most liked bash items. Here is another reason why.

I’m working on a web site and I need to edit a bunch of files, they all need the same edits done and there is no reason I should get interrupted from working on them all in series. Enter the for loop! With the following command I can edit each file in VIM and when I close the file the next file will open for me.

for I in `ls *.php`
do
vim $I
done

Nice and simple.

UNIX tips

Monday, August 25th, 2008

Not to toot my own horn, but it is rare that an article comes across with tips that I truly find useful. Up on the IBM website are some UNIX tips that I think are great. Some of them are truly new to me while most of them are things I continuously forget about.

UNIX tips: Learn 10 good UNIX usage habits

EyeTV and the HD Homerun

Monday, August 25th, 2008

A while back I posted about having ordered EyeTV and the HD Homerun. I promised a post once it all arrived and here it is.

If you didn’t visit any of the links I provided before then here is a quick over view of what I ordered. The HD Homerun is a network based dual ATSC/QAM tuner. ATSC is the new digital broadcast standard and QAM is the how many channels are distributed on the cable system. Chances are the cable TV provider in your area provides at least some QAM channels. The HD Homerun has two hook ups meaning I can record two shows at once or watch and record a show or even watch two shows at the same time. The HD Homerun will also allow you to use one of the ports for ATSC and the other for QAM if you so choose. The HD Homerun’s ethernet port runs at 100Mbit and easily supports watching a pair of channels. Based on some entirely unscientific google searching, I found that the highest bitrate available using ATSC is about 19Mb/s while QAM is around 56Mb/s. Like a wireless network, neither actually hit those rates often so the HD Homerun is quite capable of streaming two channels at the same time.

I went with the HD Homerun over any of the other tuner options because it doesn’t lock me into a tuner that works only on the Mac platform. As much as I love Mac and all I just didn’t want to drop cash on a solution that would tie me indefinitely to the Mac platform for watching and recording TV.

EyeTV is software for the Mac that can talk to the HD Homerun to watch a show or record (or both). It provides a some what confusing interface that lacks any sort of intuitive flow. This is really unlike most Mac apps. For example, when using the program guide you can click on a show to view details about the show such as a full description. Once on this screen, there is no clear indication of how to return to the program guide again. There is no back button of any sort and clicking on the Program guide button again doesn’t bring you back where you were. Instead, you are supposed just click anywhere on the detail screen to go back where you were.

Despite the interface EyeTV works rather well. One of my favorite things about EyeTV is how it works with the Mac to wake it when it is time to do a recording and the EyeTV helper app will launch EyeTV. While I have heard rumors of Windows Media Center being able to do this I’m not entirely sure that it can and can do it reliably.

Another thing EyeTV can do is re-encode and then share via HTTP any recordings that have via the network. The encoding is small enough to work with a 802.11g network yet of good quality. Best of all you’re not tied to just viewing the files on another Mac, Windows is welcome too.

If you looking for a way to watch and/or record TV the HD Homerun plus any DVR software package is a good bet. EyeTV for the Mac is definitely the way to go despite some interface shortcomings if you are a Mac user. If you like MythTV on Linux or Media Portal or Media Center on Windows the HD Homerun is a great choice.

How to rename your website with a for loop

Wednesday, August 6th, 2008

I recently found myself renaming a website and needed to change some common text in a bunch of php and template files. Here is the code I used to get the job done.

for I in `find . -name "*.php"`; do sed -i "s/old name/new name/g" $I; done
for I in `find . -name "*.tpl"`; do sed -i "s/old name/new name/g" $I; done

Sure a truly savvy person could have done this in one line but that’s just not as fun.

RAID is not backup

Friday, February 8th, 2008

One thing that a number of people overlook is that RAID is NOT a backup solution. That’s right, say it with me, “RAID is not a backup solution.” RAID is at most a data availability solution and nothing more. With that in mind it is always good to have a backup. This post will concentrate on creating a backup script and routine for my Linux server as well as my Mac. Since the Mac is UNIX based I can back it up in much the same way as I do my Linux server.

Please keep in mind that this method assumes a lot of things and should not be considered for a business environment where security is more important. My method involves creating a public/private ssh key without a passphrase and worse, the root password for my MySQL server is also coded into this script. Since this is all DIY, you can expand whatever you do to be a bit more secure.

(more…)

Software RAID setup

Monday, January 28th, 2008

I am in the process of setting up a box for someone and I thought I’d document the software RAID portion of it a little bit, in case it is helpful to anyone else.

I’m a bit of a command line junkie so it should come as no surprise then that I prefer to setup my software RAID sets using the command line tools available. The system in question this time is a newly installed CentOS 5 box. In this article I’ll concentrate on creating a mirrored set.

(more…)