Wednesday, 29 April 2009

Encrypted Timecapsule backups

Timecapsule backups aren't encrypted which seems a little dumb - as if someone nicks your TC then they've also got all your data in the clear too. There's a simple procedure that this smart post lays out - but I've copied it here in case that page goes away as it is so handy:
  • Set up Time Machine to back up to an AFP drive. I don’t think this will work with a local hard drive.
  • Let Time Machine start backing up, then stop the back up. This will have created _.sparsebundle on the AFP drive.
  • Disable Time Machine.
  • Open a Terminal and run these commands (replace name_mac with your mac's name, and TC_drive_name with your TimeCapsule's network drive name - ls /Volumes to check):
    $ cd /Volumes/TC_drive_name/
    $ mv name_mac.sparsebundle name_mac-old.sparsebundle
    $ hdiutil convert -format UDSB -o name_mac.sparsebundle -encryption AES-256 name_mac-old.sparsebundle

    It will ask you for a password. Type in a password you won’t forget.
  • Double click the sparsebundle in the Finder (You should find it in your TimeCapsule network drive). You will be prompted for your password. Type that in and tick the “Remember password” check box.
  • Open /Applications/Utilities/Keychain Access and find name_mac.sparsebundle. Right click it and select Copy name_mac.sparsebundle.
  • Select System Keychain on the left hand side of Keychain Access and paste it in the main area. Allow this action if you are asked. Remember to lock the System Keychain when you are done.
  • If using Snow Leopard then (as suggested here) you'll need to copy "" from the old to the new sparsebundle. You can do this by going to the volume using Terminal as above and then doing:
    $ cd /Volumes/TC_drive_name/
    $ cp name_mac-old.sparsebundle/ name_mac.sparsebundle
  • Unmount the volume and then tell Time Machine to get busy.
  • Time Machine should not have no problem backing up to the encrypted volume. If everything works as planned, feel free to delete the name_mac-old.sparsebundle
[updated: 21sept09, 21aug10]

Tuesday, 28 April 2009

Mounting a Xen .xm (xmfile) disk image file

You've probably wondered how to mount one of these pesky things. It turns out they're actually just entire disk images with a boot sector and often with multiple partitions. On Linux you can use the losetup tool - It allows one to mount a disk image on a /dev/loopX device. If it has multiple partitions then you need to find out where in the image the particular partitions are that you want to mount. Firstly you mount the entire image on a [spare] loop device e.g.:
sudo losetup /dev/loop0 diskimage.xm
Then run fdisk to check out the partition table (in sectors):
sudo fdisk -ul /dev/loop0
It will list the partitions - note down the start of the partition you're interested it and multiply it by 512 (the number of bytes per sector): e.g. If the first partition starts at 63 you multiply it by 512 and get 32256 then you use that as the 'offset' argument (i.e. how far into the disk image your chosen partition resides) to the losetup command:
sudo losetup -o32256 /dev/loop0 diskimage.xm
Next you need to determine the filesystem type - you maybe able to check this what fdisk reports, but you can also use the file command:
file -s /dev/loop0
Then mount that partition onto a spare directory on your system (e.g. ext3 filesystem on /mnt):
sudo mount -text3 /dev/loop0 /mnt
And it should then be mounted at /mnt and away you go. Thanks to this page for getting me going - plus a comment there mentions that there's simpler way to mount the image - if you're running a kernel version > 2.6.26 (You can specify modprobe loop max_part=63 and it will create the partitions automatically on calling losetup - but that only works if loop is a module - which it isn't in Ubuntu 9.04).

[corrected 2oct09]