Recently, I acquired a used Xserve RAID. Good storage capacity, and way cheaper than buying new drives. In the interests of data security I'd like easily removed drives, such as those in the RAID, to have their contents encrypted.
The master server is just a house for VMs. And, because those VMs are generally free to be rebooted with wild abandon, entering passwords into the VMs controlling the RAID arrays would be a real downer. Fortunately, the master computer to which the RAID is attached is already set up with encrypted hard drives—which means I can store keyfiles for the RAID arrays on it without compromising security.
In fact, thanks to proper layering, the VMs don't even have to know the drives they're accessing are encrypted.
Here's how.
First, we'll need a key file. Random data will do nicely.
KEY_FILE=/etc/luks-keys/$VMNAME head -c /dev/random 1024 > $KEY_FILE chmod 400 $KEY_FILE
Next, set up encryption on the RAID array.
cryptsetup luksFormat $RAID_DEVICE $KEY_FILE
And then add it to crypttab, so encryption will be automatically set up and torn down at system start/shutdown.1
UUID=`cryptsetup luksUUID $RAID_DEVICE` echo $RAID_VOLUME UUID=$UUID $KEY_FILE luks >> /etc/crypttab cryptdisks_start $RAID_VOLUME
The encryption set up and running, it's just a matter of creating the VM.
I like to create a partition on the regular drive for the VM's OS. While not strictly necessary, it gives a bit of flexibility (e.g., the ability to switch between two different VMs controlling the RAID while testing different NAS distributions), and leaves the maximum amount of space on the RAID array for files.
lvcreate -L $SIZE -n $VOLNAME $VOLGROUP
That done, actually make the VM.
virt-install --name $VMNAME \ --disk /dev/$VOLGROUP/$VOLNAME \ --disk $RAID_VOLUME \ …
Or, if adding the encrypted disk to an existing VM:
virsh attach-disk $VMNAME $RAID_VOLUME $VMDEV --persistent
Once inside the VM, you can format the attached volume as normal, none the wiser to the encryption. It just works.
Of course, encryption means if your RAID array loses one too many disks your data is hosed irrecoverably, so be darn sure to have a good backup policy in place before you start storing critical data on it!
For the purpose of those backups, it might be desirable to ensure you can take snapshots of the filesystem. That's doable, too:
VGNAME=$RAID_VOLUME vgcreate $VGNAME $RAID_DEVICE lvcreate -L $SIZE -n volume $VGNAME mkfs -t $FSTYPE /dev/$VGNAME/volume
where $SIZE is some size smaller than the extent of the device. Exactly how
much smaller depends on how much data churn you're expecting while the volume is
snapshotted, but I'd say leaving ~10% for the snapshot is probably
sufficient.2
Then you can attach the logical volume to your VM
virsh attach-disk $VMNAME /dev/$VGNAME/volume $VMDEV --persistent
and use snapshots to back up the VM from outside with the VM none the wiser.
Note that the mkfs turns out to be important: if you don't format the logical volume before mounting it within the VM, the VM will see the LV rather than an unformatted block device and be very confused.
Using the mptfc driver with my fibre channel card, I was unable to get
echo '- - -' > /sys/class/scsi_host/$HOST/scan
to recognize a change in RAID
size, and don't recall having much luck actually specifying the parameters,
either.
Rescanning was, however, successful with
echo 1 > /sys/class/scsi_device/$DEV/device/resca
So if scan doesn't help, try rescan. It certainly beats rebooting!
1 Alternatively, you could add a libvirt hook to set up and tear down the encryption before and after the VM is booted and shutdown. That is left as an exercise to the reader.
2 As a point of reference, upgrading Debian from Stable to Testing requires ~7% of a 32GB volume.
Some time ago, we got a TV that supports DLNA. I had no idea what that was, but a quick consultation with Wikipedia left me eager to give it a try.
I've tried a couple of DLNA servers since then, and found all of them wanting in some manner. I've also been using Netflix streaming of late, so I'll add that to the comparison seeing as it fills the same niche.
Edit (16.05.2012): I seem to have spoken too soon on Serviio. Further testing on a wider range of files has shown it to sometimes have infuriatingly-long start-to-play times and that it works with fewer files than pms. Alas, it had such promise!
Netflix and DLNA are both awesome ideas with not-so-awesome implementations, but between the two Netflix is an incredible triumph. DLNA generally works, and is vastly superior to watching things on a computer monitor, but has little else in its favor (I suspect I'd ditch it entirely if I had an HTPC running XBMC). Netflix certainly has areas in need of improvement, but I was surprised at just how quickly and completely it supplanted any other method of watching video content—my biggest annoyance is actually the pause thing, believe it or not, because I pause to read things all the time.