Wednesday, July 22, 2009

Setting up Linux Software RAID in Ubuntu 9.04

I decided that I needed some data redundancy for my media collection and personal documents.   I was running zfs for awhile, with 2, 1 gig drives, but then I decided to switch to Linux Software Raid.

I found 2 pretty articles on how to setup and configure a Linux Software RAID.

In my particular setup, I had 2, 1 gig disks, but I wanted to re-use those while switching to the software raid setup.  So, do that, I basically, stole a disk from the zfs raid setup, partitioned it, created the linux raid, formatted it, and then copied the zfs drive to the newly created linux raid device.  Pretty easy right?  Well, it was, but i'll into some extra details about the complete process.

I had 2 sata devices, /dev/sda, and /dev/sdb

First, install mdadm
# sudo apt-get install mdadm

When you install mdadm, it will want to install postfix.  I don't know why, but it does.  I just answered the basic install questions and carried on.

Next, prepare 1 of your 2 disks for a linux raid.
# sudo fdisk /dev/sda

If it doesn't have a partition, then create one (n), and then change the partition type to Raid Auto Detect (t then fd)

You should now have a /dev/sda1 device.  You can verify this using the print command (p) and then write (w) your changes.

Next, we create the raid array.  In my case, I will eventually have 2 disks, but I wanted to create the array with just a single disk (/dev/sda1) for now, and then add in the other disk (/dev/sdb1) later.

Creating the array was pretty simple.
# sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 missing
Notice that for the second device, I used the word, "missing".  This is special reserved word for mdadm and it is used to acknowledge that you are creating an array, but you do not yet have all the devices.  You need at least 1 device, which I did have.

Now that you've created the array, we need to format it.
# sudo mkfs.ext4 /dev/md0

That should take a few minutes, and we are now ready to mount the device.

# sudo mkdir /media/Transfer
# sudo mount /dev/md0 /media/Transfer

We now have a mounted device under /media/Tranfer.  We'll use that to transfer all the files from our old device onto the new device.  In my case, my zfs drive was mounted under /home, so I used rsync to sync the zfs mounted drive with my newly mounted linux raid device

# sudo rsync -av /home /media/Transfer

This will take a long time, depending on your disk size.  In my case, it took a couple of hours.

Once the transfer is complete, I then added in my other zfs drive to my linux raid.  This required that I partition the drive in the same way that I partitioned my other drive.  Basically, using fdisk, I created a new partition, and then set the partition type to fd (Linux Raid)

Once that was done, all I needed to do was add the new drive to my existing linux raid array.

# sudo mdadm --manage /dev/md0 -a /dev/sdb1

Once you do this, you'll notice your hard drive light will remain on or flash very quickly.  Basically the Raid Array is now copying all data from the source disk to the newly added disk.  This will take a couple of hours as well, but the system is fully usable during that time.

You can check the status of the Raid at any time by issuing the command
# cat /proc/mdstat

The output will be something like,

Personalities : [raid1]
md0 : active raid1 sda1[2] sdb1[0]
      976759936 blocks [2/1] [U_]
      [========>............]  recovery = 44.4% (434131840/976759936) finish=135.6min speed=66645K/sec


Finally, don't forget to update your /etc/fstab to reflect that your new mount device is /dev/md0 and not whatever it used to be.  In my case, it was a matter of changing the device to that /home was mounted as device /dev/md0

Tuesday, March 31, 2009

Tip: How to find to which jar a class file belongs

It's a common problem in larger projects, where you are using a Class reference, but you don't know which of the 20 jars in your project is actually providing the implementation.

In my case, I needed to know which jar file was providing the Hex class.

System.out.println(Hex.class.getProtectionDomain().
getCodeSource().getLocation().toString());

It turns out that it's in axis2.jar :)


Wednesday, February 4, 2009

Using Bookmarks in Your Development Projects

I've recently began helping with large project at work.  The project contains a very large codebase, and in working through all the pieces, I thought, "I wish I could just bookmark some of these locations, so that I could return to particular areas later on".   This thought hit me after I spent about 10 minutes trying to find a piece of code that I knew I visited earlier in the week.

It appears that I didn't have to look far for a bookmarking feature.  I use Eclipse, and the great folks on that project have already thought about this.  To bookmark a section of code, simply right click in the left hand margin of the code editor, and you'll see an "Add Bookmark..." link.  Click it, and you will create a bookmark in the code that you can then use to quickly jump back to that location.

You'll also want to add the "Bookmarks" view to your perspective as well.  Simply click Window -> Show View and enter Bookmark.  Then add that view.

Bookmarks isn't something that you'll need/want when you are browsing your own projects, but it can certainly save time when you are browsing code in a larger project that you are not yet familiar with.

Bookmarking... It's a good thing. (Sometimes)

Tuesday, January 6, 2009

Apple Store: Music to be DRM Free this year

Well it appears that Apple music will finally become totally DRM free by the end of the first quarter of this year.

The Apple Keynote for this year was quite dull, but that was one small piece of good news to come out of it.

How long before TV and Video execs realize that DRM is bad for their content as well?