On-Demand RAID for Laptop with SSD and USB Disk

Summary:  DRBD provides a nifty way of allowing a “RAID when available” setup, which offers more flexibility then MDADM.  When in “RAID” mode, DRBD performs about 10% slower then MDADM, but provides near SSD performance when DRBD is not mirroring.  Importantly you don’t need to have the USB drive connected all the time, so its great if you want to grab your laptop and have it mirror to your USB disk when you get back to base.

The Project

I have an HP Folio Laptop with 128 gig Samsung MZPA128 SSD drive built in, and a 2.5″ spinning disk connected to my PC over USB3 when at home – running Ubuntu.  My research on SSD drives leads me to believe that they are about as unreliable as hard drives, but with the added disadvantage that when they fail, they normally fail catastrophically, unlike hard drives where you can often  recover most data.   While RAID is not a valid method of backing up, I want the “best of both worlds” in terms of performance and resiliency.

Tests and Benchmarks

The baseline tests for the SSD and HDD were performed using raw LVMs formatted with EXT4 (defaults).

Performance results for  SSD: bonnie++ -s 8000 -u 1000:1000

folio         8000M   798  99 190836  20 95514  10  4230  99 256948  14  6882 170
folio         8000M   812  99 189668  18 95897  10  4213  99 257911  13 13106 262
folio         8000M   789  99 177182  18 95188  10  4149  99 253408  15  6537 163

Performance results for HDD: bonnie++ -s 8000 -u 1000:1000

folio         8000M   751  97 65353   9 25092   5  3675  97 78205   7 148.6   5
folio         8000M   771  96 66600   9 25452   5  4131  96 75136   7 149.3   5

MDADM

1 configuration stuff-up and complete reinstall later I have a raid array for testing built with the following command: mdadm –create /dev/md0 –level=mirror –write-behind=1024 –raid-devices=2 /dev/sda6 -W /dev/sdc1 -b /ssdgen/mdadm.bitmap

folio         8000M   805  98 33984   5 33185   5  3967  97 220468  12  2724  60
folio         8000M   783  99 34145   4 33485   5  4009  97 235770  12  2539  60

DRBD Protocol A

folio         8000M   761  98 31097   5 30644   6  3799  97 190543  14  2118  75
folio         8000M   798  99 31910   5 31631   6  4078  99 238925  12  2037  73

DRBD Protocol A, Unplugged

folio         8000M   811  99 110606  14 81152   8  4206 100 258376  13  2791 109

Setup to Support DRBD configuration.

I configured DRBD on top of LVM to allow the greatest flexibility with resizing file systems.  The configuration details I used were as follows:

root@folio:/home/davidgo# pvs
  PV         VG     Fmt  Attr PSize   PFree  
  /dev/sda5  intssd lvm2 a-   119.00g      0 
  /dev/sdc1  usbhdd lvm2 a-   298.09g 193.98g
root@folio:/home/davidgo# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  intssd   1   3   0 wz--n- 119.00g      0 
  usbhdd   1   1   0 wz--n- 298.09g 193.98g
root@folio:/home/davidgo# lvs
  LV       VG     Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  root     intssd -wi-ao  13.04g                                      
  ssd_drbd intssd -wi-ao 104.11g                                      
  swap     intssd -wi-ao   1.86g                                      
  hdd_drbd usbhdd -wi-ao 104.11g

The DRBD Configuration is

global
{
        usage-count no;
}

common 
{
        syncer
        {
                # Rate in Megabytes
                rate 15M;
        }

        net
        {
                max-buffers 250;
        }
}

resource drbd0
{
        protocol A;
        startup
        {
            become-primary-on folio;
        }

        on  folio
        {
            device /dev/drbd0;
            disk /dev/mapper/intssd-ssd_drbd;
            address 127.0.0.1:7790;
            meta-disk "internal";
        }

        on drbd2
        {
            device /dev/drbd1;
            disk /dev/mapper/usbhdd-hdd_drbd;
            address 127.0.0.1:7791;
            meta-disk "internal";
        }
}

resource drbd1 
{
        protocol A;

        on  folio
        {
                device /dev/drbd1;
                disk /dev/mapper/usbhdd-hdd_drbd;
                address 127.0.0.1:7791;
                meta-disk "internal";
        }

        on drbd2 
        {
                device /dev/drbd0;
                disk /dev/mapper/intssd-ssd_drbd;
                address 127.0.0.1:7790;
                meta-disk "internal";
        }
}

In order to get “Automatic RAID when available working”, I usedle a custom script and UDEV. The UDEV command will need to be modified to match your device, but mine looks as follows:

/etc/udev/rules.d/95-drbdusb.rules:

# Generated by inspecting output of
# udevadm info -a -p $(udevadm info -q path -n /dev/sdd1)
# We can use "parents" info as well, not only the sdd block

KERNEL=="sd?1", ATTRS{product}=="SK7301", ATTRS{serial}=="000020110813",RUN+="/usr/local/bin/reconnectdrbd"

/usr/local/reconnectdrbd:

#! /bin/bash
/sbin/lvchange -a n /dev/usbhdd/hdd_drbd
/sbin/vgexport -a
sleep 2
/sbin/vgimport -a
/sbin/lvchange -a y /dev/usbhdd/hdd_drbd
/sbin/drbdadm attach drbd1

Remember to “chmod 755 /usr/local/reconnectdrbd”

If you have problems getting automatic recovery working (as I did), try running it manually after connecting the drive. If that works, check the udev rule is working and the script is being called (I found adding a line “/bin/date >> /tmp/debugme.log” and inspecting this file helped prove the udev rule was not matching).

This script almost certainly contains bits which are unnecessary, but its “good enough” for what I want to do.   (The same can probably be said of the DRBD configuration !!!)

Linux and Samsung CLX-3185FN

I recently acquired a Samsung CLX-3185FN colour laser MFC. Although the device claims to work with Linux, it is a bit of a mixed bag.  Below are my views and outcomes of lessons learned thus far.

Background and Review

FWIW I use Ubuntu 12.04 64-bit, and am only interested in connecting the device across a network.    I am blown away by the speed and quality of the printer for black-and white laser printing relative to my Brother Fax2820 [laser printer] and multi-page scanning relative to my HP Officejet 6500 [ scanner, theoretical occasional color printing which never worked because cartridges dried up ].

For black-and-white scanning to email this device outperforms the OKI MB470 I use at work, and leaves the HP Officejet 6500 for dust.  Using the defaults it produces very clear pdfs of small size.  I find the scanning interface unnecessarily clunky, for example defaulting to USB scanning when no USB device is connected, with no apparent way to change the default behaviour or set up a “speed scan” button – at least with the firmware installed.

Colour scanning (using the flat bed) is very slow relative to the HP Officejet, but produces (subjectively) impressive images.

I don’t like the exorbitant prices of replacement toners and the “DRM” implemented in the printer and cartridges to extort this – a set of cartridges (let alone drum) will set me back more then the printer.   I am aware of ways to hack this device to use much cheaper toner – something I will be experimenting with soon.

Unsolved Issue –  Printing Graphics

Even using the latest driver from Samsung, printing images in draft mode worked fine, however printing normal or high quality images did not work for the most part (but regular documents worked OK).

I did manage to get a couple of pictures to work, and thought I had solved the problem, but have been unable to reproduce the feat, and Samsung offered exactly no help (see below).   I have, however come up with a work-around – Despite what the manual says, it is possible to print colour jpg files from a USB key plugged into the front of the device.  Its not fast or particularly convenient, but it works.

For reference, the presenting problem is/was that the image was duplicated twice on the page, stretched to full length, with white gaps.  The higher the quality of the image sent to the printer, the bigger the gaps.

Both GIMP and GTHUMB exhibited the same problem.

I have not had a chance to pursue it (I have a great HL5340D black and white printer, and am using the Samsung for scanning – and the very occasional picture for my son), but it looks like there may be an unofficial forum which can help – http://www.bchemnet.com/suldr/forum/

Solved Issues

Scanning

Initially I could not get the printer to work with XSANE, no matter what drivers I tried to use from Samsung or what I configured, however the solution turned out to be trivial to fix – The solution was simply a matter of adding the line “tcp 10.0.3.247” to /etc/sane.d/xerox_mfp.conf  – This works a charm – pity the manual is devoid of any hint of this solution.  It almost goes without saying that you would replace 10.0.3.247 with the IP address of your scanner.

Other

I installed other Samsung Linux software – Smartpanel and PSU.  Neither of these pieces of software provided any meaningful functionality and I would not bother with them again.

Also of note was Samsungs complete cop-out when it comes to supporting Linux. In response to a reasonably detailed email asking for help with the issues I was having with colour printing, their response (grammatical errors and all) was:

Thank you for your email, Unfortunately we can’t suppor Linux as it’s all open source

WE provide the drivers for the unit you have but can’t provide any further support on the operating system

All I can suggest is that you try and install the unit on a PC and see if you’re stull getting the same problem IF you are then return the unit back to the store as there may be a fault with it