Mirrored Drives with Ubuntu

Mirrored drives are also known as a RAID 1 configuration.  It is important to note that running mirrored drives should not be used as a substitute for doing backups.  My motivation for running a RAID 1 is simply that with the drive densities today, I expect these drives to fail.  A terabyte unit is cheap enough that multiplying the cost by two isn’t a big deal, and it gives my data a better chance of surviving a hardware failure.

I purchased two identical drives several months apart – in the hopes of getting units from different batches. I even put them into use staggered by a few months as well.  The intent here was to try to avoid simultaneous failure of the drives due to similarities in manufacture date / usage.  In the end, the environment they are in is probably a bigger factor in leading to failure but what can you do?

Linux has reasonable software raid support.  There is a debate of the merits of software raid vs. hardware raid, as well as which level of raid is most useful.  I leave this as an exercise up to the reader.  The remainder of this posting will be the details of setting up a raid 1 on a live system.  I found two forum postings that talked about this process, the latter being most applicable.

We will start with the assumption that you do have the drive physically installed into your system.  The first step is to partition the disk.  I prefer using cfdisk, but fdisk will work too.  This is always a little scary, but if this is a brand new drive it should not have an existing partition table.  In my scenario I wanted to split the 1TB volume into two partitions, a 300Gb and a 700Gb.

Now let’s use fdisk to dump the results of our partitioning work:

$ sudo fdisk -l /dev/sdd

Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot         Start         End      Blocks   Id  System
/dev/sdd1               1       36473   292969341   83  Linux
/dev/sdd2           36474      121601   683790660   83  Linux

Next we need to install the RAID tools if you don’t have them already:

$ sudo apt-get install mdadm initramfs-tools

Now recall that we are doing this in a live system, I’ve already got another 1TB volume (/dev/sda) partitioned and full of data I want to keep. So we’re going to create the RAID array in a degraded state, this is the reason for the use of the ‘missing’ option. As I have two partitions I need to run the create command twice, once for each of them.

$ sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 missing /dev/sdd1
$ sudo mdadm --create --verbose /dev/md1 --level=mirror --raid-devices=2 missing /dev/sdd2

Now we can take a look at /proc/mdstat to see how things look:

$ cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdd2[1]
683790592 blocks [2/1] [_U]

md0 : active raid1 sdd1[1]
292969216 blocks [2/1] [_U]

unused devices: <none>

Now we format the new volumes. I’m using ext3 filesystems, feel free to choose your favorite.

$ sudo mkfs -t ext3 /dev/md0
$ sudo mkfs -t ext3 /dev/md1

Mount the newly formatted partitions and copy data to it from the existing drive. I used rsync to perform this as it is an easy way to maintain permissions, and as I’m working on a live system I can re-do the rsync later to grab any updated files before I do the actual switch over.

$ sudo mount /dev/md0 /mntpoint
$ sudo rsync -av /source/path /mntpoint

Once the data is moved, and you need to make the new copy of the data on the new degraded mirror volume the live one. Now unmount the original 1TB drive. Assuming things look ok on your system (no lost data) now we partition that drive we just unmounted (double and triple check the device names!) and format those new partitions.

All that is left to do is add the new volume(s) to the array:

$ sudo mdadm /dev/md0 --add /dev/sda1
$ sudo mdadm /dev/md1 --add /dev/sda2

Again we can check /proc/mdstat to see the status of the array. Or use the watch command on the same file to monitor the progress.

$ cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdd2[1]
683790592 blocks [2/1] [_U]

md0 : active raid1 sda1[2] sdd1[1]
292969216 blocks [2/1] [_U]
[>....................] recovery = 0.6% (1829440/292969216) finish=74.2min speed=65337K/sec

unused devices: <none>

That’s all there is to it.  Things get a bit more complex if you are working on your root volume, but in my case I was simply mirroring one of my data volumes.

BitPim and the Samsung M300

Jenn has a pay-as-you-go cell phone, while its a relatively inexpensive phone (Samsung M300) it has reasonable battery life, and its small.  One of the unexpectedly useful features was a camera, sure its not able to take very nice photos but sometimes your phone is the only camera you have handy “in the moment” (like when the kids go on a mud-puddle adventure).

Unfortunately with the pay-as-you-go plan, there wasn’t any way to get the pictures off the camera.  No data service meant you couldn’t email them from the phone, and the phones bluetooth connectivity seems to be limited to headset profiles.  The data cable was cheap enough on eBay so I thought I’d take a risk and see what could be done with one.

Once I had the cable, it was time to find some software.  BitPim seemed to be the right choice for me (free, and available on Linux).  The Ubuntu repositories have a version that works [sudo apt-get install bitpim].

You’ll want to run it as root, or mess with the /dev entries for USB to grant your user enough rights to access the phone.  The BitPim software handles the capabilities of the M300 in two ways, treating the one phone as effectively two devices.  The first is the “media” version, this allowed me to copy down the pictures from the phone.  The PIM version needed a bit more fiddling as it wasn’t actually detected properly.  I did manage to get it to download the contents of the phonebook from the phone.

Now it turns out that the Bell Mobility firmware for this phone seems to be different enough from the US version that BitPim simply won’t work for writing to the phonebook.  Someone else ran into exactly the same problem as I did. Of course, this was after I managed to delete all 60 phonebook entries that were already stored in the phone. Oops.  I think Jenn has now forgiven me.

I’ll reference the excellent HowardForums for all your cellular information needs. And a pointer to a Samsung page which provides a data access utility (that sadly still fails with the firmware I have).

Beachcombing

A bit of an absence from updating the blog over the past month, due primarily to being busy with work/home.  I hope to get back to my regular cadence of something every week or so, and I’m going to start with something lighthearted.  There are several more technical articles I’ve got on the go, hopefully I’ll get those cleaned up and ready to post soon.

Late last summer we headed west to Vancouver Island, this is a regular trip as many of my relatives are out that way.  We took a break from visiting family and spent some time in Parksville, specifically down on Rathtrevor Beach.  The first morning we were there, I took a walk with my daughter as the tide was out.  Not five minutes from the cabin I came across a cell phone (pictured above) sitting on the wet sand.

Not seeing anyone around for literally miles, there was a very slim chance I was going to get this back to the owner.  I figured I’d see if it was in working shape or not.  Turns out it didn’t work, and was likely pretty water logged.  Popping it open let me determine the exact model number (Samsung SGH-J706), and based on the SIM card which revealed the carrier it appeared to be a pay as you go phone.

Things started to seem grim when I took a look at the charge port on the phone, not a great sign to see corrosion and salt build up.  It was pretty clear this was very likely junk, but I couldn’t just pitch it into the trash.  It ended up coming home with me where I got a chance to open it up [you could probably tell that was coming..]

The J706 is a slider phone, the screen slides up to reveal a keyboard underneath.  Pretty slick, and I can’t help but think back to The Matrix whenever I have one of these in my hand.  Disassembling the slider was educational, I was able to take it all apart – and put it back together.

Unfortunately, once I had it apart it was pretty clear this wasn’t ever going to work again.  I often wonder if its possible to repair phones that have gotten wet (you see these on eBay from time to time) but a good soak in saltwater looks like a one way ticket for electronics.  The LCD screen seems to have been fairly well sealed, and some of the parts may have been in a working state as well – but it should be evident from the photo that much of it was a complete write-off.

Reassembled and cleaned up, it looked cosmetically fine.  The slider mechanism worked smoothly too.  In the end, I took it into BestBuy’s cell phone trade-in program: I figured that at least they could recycle it properly.  I was up-front with them about the non-working condition of the phone, and they did check it for water damage (there is a little indicator under the battery usually).  The representative told me if it had been in working shape it was worth $60, I figured that was the end of the conversation and told him just to recycle it – but he stopped me and said, let’s see what I can give you for it.  Turns out it was worth $7.61 – I walked away with a gift card feeling pretty lucky.