<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>m^2</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/" />
    <link rel="self" type="application/atom+xml" href="http://msqr.us/m2/atom.xml" />
    <id>tag:msqr.us,2008-02-03:/m2//1</id>
    <updated>2010-01-21T20:03:36Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.32-en</generator>

<entry>
    <title>Felled By Bureaucracy</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2010/01/felled-by-bureaucracy.html" />
    <id>tag:msqr.us,2010:/m2//1.149</id>

    <published>2010-01-21T20:01:16Z</published>
    <updated>2010-01-21T20:03:36Z</updated>

    <summary> Noticed this little stone marker in the corner of a parking lot on a hill on a local university campus....</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Politics" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Environment" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="politik" label="politik" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><img alt="Felled By Bureaucracy" src="http://msqr.us/m2/archives/img/felled-by-bureaucracy.jpg" width="400" height="311" class="corners" /></p>

<p>Noticed this little stone marker in the corner of a parking lot on a hill on a local university campus.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Wish I Weren&apos;t Here</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2010/01/wish-i-werent-here.html" />
    <id>tag:msqr.us,2010:/m2//1.148</id>

    <published>2010-01-17T20:42:02Z</published>
    <updated>2010-01-17T20:47:06Z</updated>

    <summary> Summer has eluded Wellington thus far. Yesterday I heard on the radio that January has been 10 degrees cooler than average. And that&apos;s in Celsius....</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
    <category term="home" label="home" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><img alt="wellington-summer.jpg" src="http://msqr.us/m2/archives/img/wellington-summer.jpg" width="400" height="299" class="corners"/></p>

<p>Summer has eluded Wellington thus far. Yesterday I heard on the radio that January has been 10 degrees cooler than average. And that's in Celsius.<br />
</p>]]>
        
    </content>
</entry>

<entry>
    <title>Salty snapper</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2009/12/salty-snapper.html" />
    <id>tag:msqr.us,2009:/m2//1.147</id>

    <published>2009-12-14T21:27:12Z</published>
    <updated>2009-12-14T22:39:01Z</updated>

    <summary> I used to call myself a sushitarian. That is, I loved to eat raw fish but didn&apos;t particularly like cooked fish. In San Francisco it was easy to assess oneself in this manner, with sushi bars on every 3rd...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
    <category term="food" label="food" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><img alt="Salty snapper!" src="http://msqr.us/m2/archives/img/IMG_0372.jpg" width="400" height="400" class="corners" /></p>

<p>I used to call myself a sushitarian. That is, I loved to eat raw fish but didn't particularly like cooked fish. In San Francisco it was easy to assess oneself in this manner, with sushi bars on every 3rd corner of the city (including a nice one the very block we lived on). In New Zealand, however, sushi is not so abundant. So the other day at the waterfront farmer market when Lillian asked to get a fish from one of the boats that pulls up and sells its wares, I thought why not?</p>]]>
        <![CDATA[<p>Minette and I consulted and thought we might make a dish she had made in the past, where you bake the fish on top of thinly-sliced potatoes. With that in mind, we asked for something thick and firm for baking. The men on the boat suggested a whole snapper. We agreed.</p>

<p>When we got home Minette noticed the latest Cusine magazine was all about fish, and found a recipe for snapper cooked in salt. This conjured up memories of bacalao in Spain, so I jumped on it. The recipe was decidedly simple: stuff the fish with lemon and fennel and then encase it in a meringue of salt (3 egg whites with 1kg of rock salt). Lillian was pretty impressed.</p>

<p><img alt="Salty snapper 2!" src="http://msqr.us/m2/archives/img/IMG_0377.jpg" width="400" height="222" class="corners" /></p>

<p>And indeed, the snapper was deliciously soft, juicy, and salty.</p>

<p><img alt="Salty snapper 3!" src="http://msqr.us/m2/archives/img/IMG_0375.jpg" width="400" height="300" class="corners" /><br />
</p>]]>
    </content>
</entry>

<entry>
    <title>Things that go bump in the night</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2009/08/things-that-go-bump-in-the-nig.html" />
    <id>tag:msqr.us,2009:/m2//1.146</id>

    <published>2009-08-27T21:53:44Z</published>
    <updated>2009-08-27T22:02:06Z</updated>

    <summary>Last night around 2:10am Minette and I were awakened by a big shake of the whole house. &quot;Earthquake!&quot; we said simultaneously. It was just one shock wave, quite strong but orderly. Thankfully the children slept through it. It&apos;s not uncommon...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Outdoors" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p>Last night around 2:10am Minette and I were awakened by a big shake of the whole house. "Earthquake!" we said simultaneously. It was just one shock wave, quite strong but orderly. Thankfully the children slept through it. It's not uncommon to hear of analogies between Wellington and San Francisco, what with all the steep hills and large bay. Sitting on top of a major fault system is another similarity.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Refinement of automount script for LUKS encrypted disk image</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2009/07/refinement.html" />
    <id>tag:msqr.us,2009:/m2//1.145</id>

    <published>2009-07-16T21:33:41Z</published>
    <updated>2009-07-16T22:55:04Z</updated>

    <summary>In my previous post I showed an automount script for mounting a LUKS encrypted disk image as a loop device. The script was designed to always mount the same loop device, e.g. /dev/loop0. This prevented it from being able to...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Tech" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="geek" label="geek" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p>In my previous post I showed an automount script for mounting a LUKS encrypted disk image as a loop device. The script was designed to always mount the same loop device, e.g. <code>/dev/loop0</code>. This prevented it from being able to mount multiple disk images, so with some tweaks I refined the script to use any available loop device and thus support multiple disk images.</p>]]>
        <![CDATA[<p>The updated script looks like:</p>

<div class="code-block">
<pre class="brush: bash;">#!/bin/bash
# 
# Automount script to mount LUKS-encrypted disk image file.
# 
# This script must be executable to work (chmod 755).
# 
# Requires losetup and cryptsetup to be available in 
# one of /bin, /sbin, /usr/bin, or /usr/sbin.
#
# The LUKS key must exist as a file at /etc/&lt;key&gt;.key

key="$1"
los=""
cry=""
img="/cifs/lacie-2big/backup/$key.sparseimage"
mountopts="-fstype=ext3,defaults,noatime,nodiratime"

if [ ! -e "/etc/$key.key" ]; then
	exit 0
fi

if [ ! -e "$img" ]; then
	exit 0
fi

# search for losetup and cryptsetup
for P in /bin /sbin /usr/bin /usr/sbin
do
	if [ -z "$los" -a -x $P/losetup ]; then
		los=$P/losetup
	fi
	if [ -z "$cry" -a -x $P/cryptsetup ]; then
		cry=$P/cryptsetup
	fi
	if [ -n "$los" -a -n "$cry" ]; then
		break
	fi
done

# check if a loop device already attached to this image
dev=`$los -a |grep $img |cut -d: -f1`
if [ -z "$dev" ]; then
	# select any available loop device
	dev=`$los -f`
	if [ -z "$dev" ]; then
		echo "No loop device available for mounting $img" &gt;&2
		exit 1
	fi
	
	# attach loop device
	$los $dev $img
	
	# open with LUKS
	$cry isLuks $dev 2&gt;/dev/null
	if [ "$?" -eq "0" ]; then
		$cry --key-file /etc/$key.key luksOpen $dev luks-`$cry luksUUID $dev` &gt;/dev/null 2&gt;&amp;1
	fi
fi

# print out mapping for automount
echo $mountopts / :/dev/mapper/luks-`$cry luksUUID $dev`</pre>
</div>

<p>This script first checks if the disk image is already attached to a loop device, and if so will not attach it again. When attaching to a loop device, it uses <code>losetup -f</code> to find any unused loop device and attaches the disk image to that one.</p>

<p>These scripts can be obtained via anonymous CVS:</p>

<pre>cvs -d :pserver:anonymous@msqr.us:/data/cvs co twobig</pre>
]]>
    </content>
</entry>

<entry>
    <title>Configuring automount for LUKS encrypted disk image on SMB share</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2009/07/configuring-automount-for-luks.html" />
    <id>tag:msqr.us,2009:/m2//1.144</id>

    <published>2009-07-16T04:48:59Z</published>
    <updated>2009-07-16T04:57:54Z</updated>

    <summary>In my previous post, I detailed how I set up an LUKS-encrypted filesystem on a loop device (a.k.a. sparse disk image file). To make automated backups easier and not have to add commands in my backup script to handle the...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Tech" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="geek" label="geek" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p>In my previous post, I detailed how I set up an LUKS-encrypted filesystem on a loop device (a.k.a. sparse disk image file). To make automated backups easier and not have to add commands in my backup script to handle the mounting and unmounting of the disk image, I set up <code>automount</code> to:</p>

<ol>
	<li>Mount the SMB share when accessing the <code>/cifs</code> directory</li>
	<li>Attach a loop device and set up LUKS filesystem access when accessing the <code>/encrypted</code> directory</li>
</ol>]]>
        <![CDATA[<p>Following along with the examples in my previous posts, I have a SMB share available at <code>//lacie-2big/backup</code> with the encrypted disk image <code>linuxbackup.sparseimage</code> sitting on it. My goal was to be able to do this:</p>

<pre>$ ls /encrypted/linuxbackup</pre>

<p>and for automount to auto-magically mount the SMB share and then mount the encrypted disk image. Unfortunately I could not find a way for automount to handle this "cascading" or "recursive" mount operation. Instead I have to execute two commands:</p>

<pre>$ ls /cifs/lacie-2big/backup
<span class="console-output">linuxbackup.sparseimage</span>
$ ls /encrypted/linuxbackup
<span class="console-output">hda1  hda2  hda3  hda6  hda7  lost+found</span></pre>

<p>Still, two simple <code>ls</code> commands are better than the 4 hard-to-remember <code>mount</code>, <code>losetup</code>, <code>cryptsetup</code>, and <code>mount</code> commands needed to do this manually. And with the help of a small script along with what <code>automount</code> provides, I don't have to worry about the 4 hard-to-remember <code>umount</code>, <code>cryptsetup</code>, <code>losetup</code>, <code>umount</code> commands needed to unmount everything when I'm finished.</p>

<h2>Automount CIFS mount script</h2>

<p>I found online an example <code>automount</code> script based from the <code>auto.smb</code> one that comes in many distributions called <code>auto.cifs</code> that will work with SMB mounts requiring authentication. That script looks like:</p>

<pre>#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# Note: create a cred file for each windows/Samba-Server in your network
#       which requires password authentification.  The file should contain
#       exactly two lines:
#          username=user
#          password=*****
#       Please don't use blank spaces to separate the equal sign from the
#       user account name or password.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=root,gid=wheel"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
        if [ -x $P/smbclient ]
        then
                SMBCLIENT=$P/smbclient
                break
        fi
done
#echo $SMBCLIENT >&2
[ -x $SMBCLIENT ] || exit 1
if [ -e "$credfile" ]
then
        mountopts=$mountopts",credentials=$credfile"
        smbclientopts="-A "$credfile
else
        smbclientopts="-N"
fi
#echo $smbclientopts -gL $key >&2
$SMBCLIENT $smbclientopts -gL $key 2>/dev/null \
   | awk -v key="$key" -v opts="$mountopts" -F'|' -- '
        BEGIN   { ORS=""; first=1 }
	/Disk/  { if (first) { print opts; first=0 };
		  gsub(/ /, "\\ ", $2);
		  sub(/\$/, "\\$", $2);
		  print " \\\n\t /" $2, "://" key "/" $2 }
        END     { if (!first) print "\n"; else exit 1 }
        '
</pre>

<p>I created that as <code>/etc/auto.cifs</code> and made it executable. Then in <code>/etc/auto.master</code> I added this line:</p>

<pre>/cifs /etc/auto.cifs --timeout=60</pre>

<p>The credentials for mounting the SMB share are then stored in a <code>/etc/auto.smb.<em>lacie-2big</em></code> file, which is how I set things up originally in my last post. Now, after reloading the <code>autofs</code> service, I am able to:</p>

<pre>$ ls /cifs/<em>lacie-2big</em>/<em>backup</em>
<span class="console-output">linuxbackup.sparseimage</span></pre>

<h2>Automount LUKS script</h2>

<p>Then I created another <code>automount</code> script <code>/etc/auto.luks.loop.0</code>:</p>

<pre>#!/bin/bash
# This file must be executable to work! chmod 755!
# Make links to this file with the last digit replaced
# with other numbers for corresponding loop devices,
# e.g. if this script is executed as auto.luks.loop.1 the 
# /dev/loop1 device will be used.
#
# The LUKS key must exist as a file at /etc/<key>.key

key="$1"
los=""
cry=""
name=`basename $0`
l=${name##*.}
img="<em>/cifs/lacie-2big/backup/$key.sparseimage</em>"
mountopts="-fstype=ext3,defaults,noatime,nodiratime"

if [ ! -e "/etc/$key.key" ]; then
	exit 1
fi

# search for losetup and cryptsetup
for P in /bin /sbin /usr/bin /usr/sbin
do
	if [ -z "$los" -a -x $P/losetup ]; then
		los=$P/losetup
	fi
	if [ -z "$cry" -a -x $P/cryptsetup ]; then
		cry=$P/cryptsetup
	fi
	if [ -n "$los" -a -n "$cry" ]; then
		break
	fi
done

# check if loop device already attached, if not then attach it
chk=`$los -a |grep /dev/loop$l`
if [ -z "$chk" ]; then
	if [ ! -e $img ]; then
		echo "Image file $img not found." >&2
		exit 1
	fi
	$los /dev/loop$l $img
	$cry --key-file /etc/$key.key luksOpen /dev/loop$l \
		luks-`$cry luksUUID /dev/loop$l` >/dev/null 2>&1
fi

echo $mountopts / :/dev/mapper/luks-`$cry luksUUID /dev/loop$l`</pre>

<p>This script is hard-coded to look for disk image files in <code>/cifs/lacie-2big/backup</code> named <code><em>imagefilename</em>.sparseimage</code> where <em>filename</em> will be the automount directory name. The script uses the last number of the script name to determine which loop device to use, although it could be easily adapted to use any freely-available device (by way of <code>losetup -f</code>).</p>

<p>Then it uses <code>cryptsetup</code> to open the LUKS device, using a key file located at <code>/etc/<em>imagefilename</em>.key</code>. Then it configures <code>automount</code> to mount the LUKS filesystem. In short, the script basically does:</p>

<pre>$ losetup /dev/loop0 /cifs/lacie-2big/backup/linuxbackup.sparseimage
$ cryptsetup --key-file /etc/linuxbackup.key luksOpen /dev/loop0 \
	luks-`cryptsetup luksUUID /dev/loop0`
$ echo -fstype=ext3,defaults,noatime,nodiratime \
	/ :/dev/mapper/luks-`cryptsetup luksUUID /dev/loop0`</pre>

<p>That last line is what is returned to <code>automount</code> and causes it to mount the image file as a directory named <code><em>filename</em></code>.</p>

<p>Finally in <code>/etc/auto.master</code> I added this line:</p>

<pre>/encrypted /etc/auto.luks.loop.0 --timeout=600</pre>

<p>Afer having the <code>autofs</code> reload this configuration, I am then able to do this:</p>

<pre>ls /encrypted/linuxbackup
<span class="console-output">hda1  hda2  hda3  hda6  hda7  lost+found</span></pre>

<p><em>With the caveat that the <code>/cifs/lacie-2big/linuxbackup</code> directory is already mounted</em>. This is where I couldn't find a way for <code>automount</code> to mount both file systems in one call.</p>

<h2>Auto-umount</h2>

<p>One final piece remains to be automated, however: completely unmounting both the encrypted and SMB file systems. <code>automount</code> will take care unmounting the LUKS encrypted filesystem after the configured period of inactivity. However, it won't be able to unmount the SMB filesystem because the <code>auto.luks.loop.0</code> script has attached the <code>/dev/loop0</code> device to the disk image file on that share. In effect, the SMB share is still in use.</p>

<p>It would be <em>very</em> nice if <code>automount</code> provided a way to execute scripts when it unmounted a filesystem. But it does not. My solution was to write a small script that runs every so often (via cron) that looks to see if any loop devices are attached to filesystems that are "not in use" and if found, detach them. Here's the script, which I have stored at <code>/etc/auto.luks.loop.umount</code>:</p>

<pre>#!/bin/bash

los=""
cry=""

# search for losetup and cryptsetup
for P in /bin /sbin /usr/bin /usr/sbin
do
	if [ -z "$los" -a -x $P/losetup ]; then
		los=$P/losetup
	fi
	if [ -z "$cry" -a -x $P/cryptsetup ]; then
		cry=$P/cryptsetup
	fi
	if [ -n "$los" -a -n "$cry" ]; then
		break
	fi
done

for dev in `$los -a|cut -d: -f1`; do
	file=`$los -a|grep /dev/loop |sed 's/.*(\(.*\)).*/\1/'`
	dir=${file%/*}
	# check if the only open file on loopback file's filesystem 
	# is from automount, if so close loopback device so automount
	# can un-mount filesystem for us later
	match=`lsof |grep $dir|cut -d" " -f1 |grep -v automount`
	if [ -n "$match" ]; then
		echo "Loop device $dev attched to in-use filesystem $dir" >&2
	else
		echo "Loop device $dev on unused filesystem $dir"
		$cry isLuks $dev 2>/dev/null
		if [ "$?" -eq "0" ]; then
			echo "Closing LUKS on $dev"
			$cry luksClose luks-`$cry luksUUID $dev`
		fi
		echo "Unattaching loop device $dev"
		$los -d $dev
	fi
done</pre>

<p>It's not particularly clever. I'm sure it would not work on systems using loop devices for other things that what I'm using them for on my system and it's making assumptions on the output of <code>losetup</code>. But it does the job nicely for what I need. I have this run every so often via <code>cron</code>. After it runs, and if it found any loop devices it could detach, then <code>automount</code> will eventually unmount the SMB share for us and we're done.</p>

<p>These scripts can be obtained via anonymous CVS:</p>

<pre>cvs -d :pserver:anonymous@msqr.us:/data/cvs co twobig</pre>]]>
    </content>
</entry>

<entry>
    <title>Encrypted Backup of RHEL 5 system to SMB network share</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2009/07/encrypted-backup-of-rhel-5-sys.html" />
    <id>tag:msqr.us,2009:/m2//1.143</id>

    <published>2009-07-15T04:34:07Z</published>
    <updated>2009-07-15T04:47:50Z</updated>

    <summary>I purchased the LaCie NAS for backups of the various computers running around at home: a Mac desktop, a Mac laptop, and a Linux server. For the Macs they can just use Time Machine to backup to the NAS, which...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Tech" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="geek" label="geek" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p>I purchased the LaCie NAS for backups of the various computers running around at home: a Mac desktop, a Mac laptop, and a Linux server. For the Macs they can just use Time Machine to backup to the NAS, which broadcasts itself as a Time Machine-capable server. For the Linux server, however, it's not so simple.</p>]]>
        <![CDATA[<p>The goal for my backup is to preserve the native Linux filesystem attributes, i.e. ownership, permissions, etc. in an encrypted format. My current backup system, before the NAS, was to use rsync to copy changed files to an external FireWire hard drive formatted with a native Linux filesystem. Nothing fancy, to be sure, but it "saved the day" on more than one occassion.</p>

<p>The LaCie NAS only supports AFP, SMB, HTTP, and FTP protocols, however. The most logical one to use with Linux would be SMB, as the Samba project provides the necessary tools for mounting and using SMB network shares. The trouble is that a SMB share will not preserve the Linux filesystem attributes I need to preserve.</p>

<p>I came across a useful web page, titled <a href="http://users.softlab.ece.ntua.gr/~ttsiod/backup.html">Optimal remote backups with rsync over Samba</a>, that provided me with an excellent starting point for implementing my backup process. The idea is to use a sparse disk image file stored on the NAS and mounted as a loop-back device in Linux. I just needed to add encryption, which turned out to be quite easy with the LUKS support available in RHEL 5 (the distribution the server runs).</p>

<h2>Setup Tasks</h2>

<h3>1) Create the SMB share for the backup, with a username and password, on the NAS</h3>

<p>This was done using the NAS's web-based administration console. I created a user for the Linux server to connect as, and created a share for that user to use.</p>

<h3>2) Mount the SMB share on Linux server</h3>

<p>The Linux CIFS filesystem support provided by Samba allows us to mount the NAS network share. I know that later on I'll want to configure an <code>automount</code> for this share, and there are automount scripts available that can make use of a credentials file with the username/password for mounting the share with. So the first step is to create a credentials file with the username and password in it, named <code>/etc/auto.smb.<em>server</em></code>. Here <em>server</em> represents the IP address or DNS name of the NAS. The file should only be readable by root, and the format looks like:</p>

<pre>username=<em>linuxbackup</em>
password=<em>mypass</em></pre>

<p>Here <em>linuxbackup</em> is the user I created on the NAS for accessing the backup share. <b>Note</b> there shouldn't be any spaces around the equal signs.</p>

<p>Now create a mount point directory, and mount the SMB share:</p>

<pre>$ mkdir /mnt/nas-backup-share
$ mount -t cifs //<em>server</em>/<em>share</em> /mnt/nas-backup-share \
	-o lfs,credentials=/etc/auto.smb.<em>server</em>,uid=root,gid=wheel,\
	file_mode=0660,dir_mode=0770,rw</pre>

<h3>3) Create sparse disk image to hold backup filesystem</h3>

<pre>$ dd if=/dev/zero of=/mnt/nas-backup-share/linuxbackup.sparseimage \
    bs=1M count=1 seek=150000</pre>

<h3>4) Setup loop device</h3>

<pre>$ losetup /dev/loop0 /mnt/nas-backup-share/linuxbackup.sparseimage</pre>

<h3>5) Setup LUKS disk encryption</h3>

<p>RHEL 5 comes with the LUKS package for whole-disk encryption. It can be used with loop-back mounted devices. First I initialize the LUKS device with <code>luksFormat</code> and then open it with <code>luksOpen</code>:</p>

<pre>$ cryptsetup luksFormat /dev/loop0

<span class="console-output">WARNING!
========
This will overwrite data on /dev/loop0 irrevocably.

Are you sure? (Type uppercase yes):</span> YES
<span class="console-output">Enter LUKS passphrase: 
Verify passphrase: 
Command successful.</span>

$ cryptsetup luksOpen /dev/loop0 luks-`cryptsetup luksUUID /dev/loop0`
<span class="console-output">Enter LUKS passphrase: 
key slot 0 unlocked.
Command successful.</span>
</pre>

<p>Now the LUKS device is accessible like any normal block device at <code>/dev/mapper/luks-<em>UUID</em></code>
where <em>UUID</em> is the value returned by <code>cryptsetup luksUUID /dev/loop0</code>. Using this naming convention may not be friendly for using now, but later on I'll setup automount so I can refer to things with friendlier names that I can remember.</p>

<h3>6) Create filesystem for backup image</h3>

<p>The encrypted device is now ready to have a filesystem created on it. I created an ext3 filesystem, but any one Linux supports could be used:</p>

<pre>mkfs.ext3 -L BACKUP /dev/mapper/luks-`cryptsetup luksUUID /dev/loop0`
<span class="console-output">mke2fs 1.39 (29-May-2006)
Filesystem label=BACKUP
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
19202048 inodes, 38400127 blocks
1920006 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
1172 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.</span></pre>

<h3>7) Create strong random password for LUKS volume</h3>

<p>I can increase the strength of the password used to unlock the LUKS volume by creating a random one and removing the original one I setup. To create the random password, I can use <code>dd</code> again:</p>

<pre>$ dd if=/dev/urandom of=/etc/linuxbackup.key bs=32 count=1
<span class="console-output">1+0 records in
1+0 records out
32 bytes (32 B) copied, 0.00018131 seconds, 176 kB/s</span>
$ chmod 600 /etc/linuxbackup.key</pre>

<p>This creates a 256-bit key stored in the /etc/linuxbackup.key file that can be used to open the LUKS volume. Now I can remove our original key:</p>

<pre>$ cryptsetup luksDelKey /dev/loop0 0
<span class="console-output">Command successful.</span></pre>

<h3>8) Mount filesystem</h3>

<p>Finally I can mount the LUKS encrypted device like a normal filesystem:</p>

<pre>$ mkdir /mnt/linuxbackup
$ mount -t ext3 /dev/mapper/luks-`cryptsetup luksUUID /dev/loop0` \
    /mnt/linuxbackup -o defaults,noatime,nodiratime</pre>

<p>I can use <code>df</code> to verify that the filesystem is alive and well:</p>

<pre>$ df -h
<span class="console-output">Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/luks-259b10cd-d2f1-41a4-bf95-a533ac0c927c
                      145G  188M  137G   1% <em>/mnt/linuxbackup</em></span></pre>

<h2>Ready for backup</h2>

<p>Now that the encrypted device is mounted, I can use it for backups, using my normal <code>rsync</code>-based backup script.</p>

<h2>Unmounting the encrypted filesystem</h2>

<p>In order to completely umount the encrypted filesystem, I have to unmount it, close it with LUKS, detach the loop-back device, and finally unmount the NAS SMB share:</p>

<pre>$ umount /mnt/linuxbackup
$ cryptsetup luksClose luks-`cryptsetup luksUUID /dev/loop0`
$ losetup -d /dev/loop0
$ umount /mnt/nas-backup-share
</pre>

<h2>Automation tasks</h2>

<p>This was a good first step. Now the next goals are to automate the mounting of the encrypted filesystem with <code>automount</code> and to get the NAS to "sleep" when not in use to conserve power. I'll details those in a future post.</p>]]>
    </content>
</entry>

<entry>
    <title>Taming the LaCie 2big Network NAS</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2009/07/taming-the-lacie-2big-network.html" />
    <id>tag:msqr.us,2009:/m2//1.142</id>

    <published>2009-07-14T23:13:39Z</published>
    <updated>2009-07-15T00:01:10Z</updated>

    <summary>A little while ago I bought a LaCie 2big Network server to use for backups and storage. The drive is simple to use, but lacks the ability for the internal hard drives to &quot;sleep&quot; -- that is, spin down when...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Tech" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="geek" label="geek" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p>A little while ago I bought a LaCie 2big Network server to use for backups and storage. The drive is simple to use, but lacks the ability for the internal hard drives to "sleep" -- that is, spin down when not in use after a period of time. That's pretty annoying because the drive makes noise and wastes power while running, keeping the disks spinning. I decided I had to figure out a way to tame this little server.</p>]]>
        <![CDATA[<p>The drive does have "shut down" and "wake on lan" features that are accessible from its web-based admin UI. When "shut down" the entire server turns off, becoming totally unaccessible. It can be "woken up" with a wake-on-lan request, however. With a little bit of scripting, I figured I could at least make the server sleep overnight, when I don't expect to be using it.</p>

<p>It turned out not to be that difficult to do. I dusted off my (very disused) Perl skills and created a Perl program that can log into the NAS and boss it around, as well as send the wake-on-lan request to it to bring it back from hibernation.</p>

<p>To make the NAS sleep, I just execute</p>

<pre>twobig --host lacie-2big --credentials /etc/twobig.cred sleep</pre>

<p>To make the NAS wake up, I just execute</p>

<pre>twobig --host lacie-2big --credentials /etc/twobig.cred wake</pre>

<p>The script even checks if there are any connected users (as reported by the NAS) when the "sleep" command runs, and won't shut the NAS down if there are.</p>

<p>I can also use the script to ping the NAS, with</p>

<pre>twobig --host lacie-2big --credentials /etc/twobig.cred --timeout 90 ping</pre>

<p>This can be combined with the "wake" command, so the script does not return until the NAS has actually finished booting up, which can take nearly 90 seconds in my experience:</p>

<pre>twobig --host lacie-2big --credentials /etc/twobig.cred --timeout 90 wake ping</pre>

<p>I plan to integrate this into an automount script so the NAS can be woken up automatically when needed.</p>

<p>The script can be obtained via anonymous CVS:</p>

<pre>cvs -d :pserver:anonymous@msqr.us:/data/cvs co twobig</pre>]]>
    </content>
</entry>

<entry>
    <title>Up, up and away!</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/12/up-up-and-away.html" />
    <id>tag:msqr.us,2008:/m2//1.141</id>

    <published>2008-12-22T03:42:14Z</published>
    <updated>2008-12-24T01:09:26Z</updated>

    <summary> &quot;Up, up and away!&quot; reads the &quot;For Sale&quot; sign in front of our house. And after 44 days, we got a mini Christmas miracle by way of a sale! It was a painfully difficult process, so it&apos;s a huge...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Family" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="family" label="family" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image"><img alt="Up, up and away!" src="http://msqr.us/m2/archives/img/IMG_6359-crop.jpg" width="400" height="356" class="corners" /></span></p>

<p>"Up, up and away!" reads the "For Sale" sign in front of our house. And after 44 days, we got a mini Christmas miracle by way of a sale! It was a painfully difficult process, so it's a huge relief to have a happy outcome on this whole house-selling hooha.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Carrots. Lots of tiny carrots.</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/06/carrots-lots-of-tiny-carrots.html" />
    <id>tag:msqr.us,2008:/m2//1.140</id>

    <published>2008-06-07T03:28:30Z</published>
    <updated>2008-06-07T03:32:20Z</updated>

    <summary> I dug out my little patch of carrots today. I guess I didn&apos;t thin them out enough to grow past &quot;baby carrot&quot; size. It was a monumental cleaning job, attending to all those little carrots, but now the job...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Outdoors" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="home" label="home" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image"><img alt="Carrot harvest" src="http://msqr.us/m2/archives/img/IMG_6014-lo.jpg" width="400" height="267" class="corners" /></span></p>

<p>I dug out my little patch of carrots today. I guess I didn't thin them out enough to grow past "baby carrot" size. It was a monumental cleaning job, attending to all those little carrots, but now the job is done and soon they will be cooked with some mustard and honey... ummm.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Move over, baby Mozart</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/05/forget-baby-mozart.html" />
    <id>tag:msqr.us,2008:/m2//1.139</id>

    <published>2008-05-24T08:14:29Z</published>
    <updated>2008-05-24T08:48:08Z</updated>

    <summary> Lillian knows exactly what music she wants to listen to these days, and it isn&apos;t Mozart, Chopin, or any other &quot;baby classical&quot; you find in so many places. She asks for it, dare I say demands it, by name....</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Family" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="family" label="family" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image"><img alt="Hunky Dory" src="http://msqr.us/m2/archives/img/hunky-dory.jpg" width="400" height="399" class="corners"/></span></p>

<p>Lillian knows exactly what music she wants to listen to these days, and it isn't Mozart, Chopin, or any other "baby classical" you find in so many places. She asks for it, dare I say demands it, by name.</p>

<p>That name is David Bowie.</p>]]>
        <![CDATA[<p>It all started on March 2nd of this year. We had a gift certificate for Amazon, and decided a wise purchase (to avoid shipping fees) would be some digital music. They've been making a lot of noise lately as a potential iTunes-killer, what with their DRM-free 256 kbp/s MP3 selection, so this was a good way to test the unknown non-iTunes waters of legally-purchased digital music.</p>

<p>One of the albums we got was David Bowie's <em>Hunky Dory</em>. Minette and I had on several occasions mentioned that we wished we had some more Bowie in our music collection, since we literally had only <em>Space Oddity</em> and the <em>Under Pressure</em> single. We didn't have any particular album in mind, but listened to many different tracks on many different albums and decided to go with Hunky Dory.</p>

<p>The next day, March 2nd, 2008, I was obviously excited to listen to the new album. I put it on the stereo, cranked the volume to a comforably loud (but quite reasonably considerate) level and had a listen.</p>

<p>And it was good.</p>

<p>I must have explained to Lillian a few times that this new music was "David Bowie." Perhaps I said it very enthusiastically. Perhaps it just struck a chord (no pun intended) with her. Perhaps after playing the album 5 or 6 times over the next few days it got permanently etched in her impressionable synapsis. </p>

<p>Whatever the reason, she now <em>asks</em> to "hear David Bowie!" once, some times 28, times on any given day. She really can be quite tenacious about it, too. She might start intoning "ch-ch-ch-ch-changes!" (Changes, Hunky Dory) or she might chant "yeah girl!" ((Don't Sit Down), <em>Space Oddity</em>) or she might exclaim "Oh yeah!" (Queen Bitch, <em>Hunky Dory</em>).</p>

<p>Sometimes she might shout "here comes.... Bowie!" and we might cave in and turn it on (for the Nth time) only for her to dance a few groovy dance moves and then shout "Turn off!" until we turn it off. Then she might repeat this cycle as many times as we can bear.</p>

<p>After we'd listened to Hunky Dory about 1 million times, we put on Space Oddity once when she asked for Bowie. I did say, "OK, here's Bowie." quietly, and she listened intently and <em>knew it was so</em> and was happy. It's as if she actually recognizes Bowie's voice, not just the repetition of the songs from Hunky Dory. I was very impressed!</p>

<p>Perhaps she really does just like Bowie. Well good on ya, Lily! A fine choice, I have to agree.</p>]]>
    </content>
</entry>

<entry>
    <title>Here we go again...</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/03/here-we-go-again.html" />
    <id>tag:msqr.us,2008:/m2//1.138</id>

    <published>2008-03-09T01:02:32Z</published>
    <updated>2008-03-15T02:26:14Z</updated>

    <summary> It&apos;s happening... again!...</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Family" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="family" label="family" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image"><img alt="ultrasound-2007-02-29-sm.png" src="http://msqr.us/m2/archives/img/ultrasound-2007-02-29-sm.png" width="400" height="245" class="corners" /></span></p>

<p>It's happening... again!</p>]]>
        
    </content>
</entry>

<entry>
    <title>m^2 / 2008</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/02/m2-2008.html" />
    <id>tag:msqr.us,2008:/m2//1.137</id>

    <published>2008-02-03T06:39:55Z</published>
    <updated>2008-02-03T07:13:39Z</updated>

    <summary>m^2 gets a makeover.</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Tech" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="geek" label="geek" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p>My friend Brahm <a href="http://brahm.windeler.net/archives/000313.html" title="Brahm goes 4.0">did it</a> so I was inspired to go fer it, too. And hey, why not do a little design freshy-up along the way? So here it is: m<sup>2</sup> / 2008. A bit lighter, a bit more nostalgic. Inspiration came from my ever-growing collection of <a href="http://en.wikipedia.org/wiki/Moleskine" title="Moleskine on Wikipedia">Moleskine</a> notebooks, which I use for day-to-day note taking (work or otherwise). The doodles that appear between entries are scans I took from my notes.</p>

<p>There are still little missing pieces and things might not all be working... but I will just have to fix those things as I stumble on them.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Glaciers of the &apos;80s</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/01/glaciers-of-the-80s.html" />
    <id>tag:msqr.us,2008:/m2//1.130</id>

    <published>2008-01-28T01:00:02Z</published>
    <updated>2008-02-03T07:03:53Z</updated>

    <summary> I stumbled upon some photos from 1983 when my family visited Glacier National Park. I remember riding this cool bus with huge snow tires up to the base of some glaciers....</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Environment" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Family" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Outdoors" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="family" label="family" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="nostalgic" label="nostalgic" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image"><img alt="Standing on a glacier" src="http://msqr.us/m2/archives/img/1983-Glacier-NP-2.jpg" width="400" height="323" class="corners"/></span></p>

<p>I stumbled upon some photos from 1983 when my family visited Glacier National Park. I remember riding this cool bus with huge snow tires up to the base of some glaciers.</p>]]>
        <![CDATA[<p><img alt="Foremost Terra Bus" src="http://msqr.us/m2/archives/img/1983-Glacier-NP-3.jpg" width="400" height="305"/></p>

<p>That got me to thinking about the park and wondering how much of those glaciers remain today. Apparently they are <a href="http://www.nrmsc.usgs.gov/repeatphoto/">fading fast</a> (current estimate is for a glacier-free park by 2030).</p>

<p><img alt="Glacier" src="http://msqr.us/m2/archives/img/1983-Glacier-NP-4.jpg" width="400" height="369"/></p>

<p>Perhaps my own kids will never get the chance to see these particular glaciers.</p>

<p><img alt="Standing in front of a glacier" src="http://msqr.us/m2/archives/img/1983-Glacier-NP-1.jpg" width="400" height="510"/></p>

<p>Which strikes me as rather sad.</p>]]>
    </content>
</entry>

<entry>
    <title>Harvest time</title>
    <link rel="alternate" type="text/html" href="http://msqr.us/m2/archives/2008/01/-its-harvest-time-well.html" />
    <id>tag:msqr.us,2008:/m2//1.129</id>

    <published>2008-01-27T09:52:55Z</published>
    <updated>2008-02-03T07:04:45Z</updated>

    <summary> It&apos;s harvest time! Well, almost. The first zucchini has arrived. I will eat it tomorrow....</summary>
    <author>
        <name>msqr</name>
        
    </author>
    
        <category term="Outdoors" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="garden" label="garden" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="home" label="home" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://msqr.us/m2/">
        <![CDATA[<p><span class="mt-enclosure mt-enclosure-image"><img alt="IMG_5827.jpg" src="http://msqr.us/m2/archives/img/IMG_5827.jpg" width="400" height="267" class="corners" /></span></p>

<p>It's harvest time! Well, almost. The first zucchini has arrived. I will eat it tomorrow.</p>]]>
        
    </content>
</entry>

</feed>

