Author Archives: thtieig

How to build a Debian package from source

There are plenty of articles on the net… but here I’m posting my notes about compiling netatalk.

First of all, you need the minimum packages:

apt-get install build-essential dh-make autotools-dev

I needed this on my Raspberry Pi for this article, and I didn’t want to make dirty the system using the common “make / make install” commands.

This are the simple steps I’ve followed (all as root – even if it’s not the best practise).

mkdir /tmp/netatalk
cd /tmp/netatalk
wget http://downloads.sourceforge.net/project/netatalk/netatalk/3.1.7/netatalk-3.1.7.tar.gz
tar xzvf netatalk-3.1.7.tar.gz
cd netatalk-3.1.7

Make sure the folder has this format: <name_of_the_package>-<version> ALL in lowercase!

dh_make -e [email protected] -f ../netatalk-3.1.7.tar.gz

It will ask for the type of the package. To make things easier, just select single entering s.

Edit the file debian/control adding the missing bits (example below):

Source: netatalk
Section: net
Priority: extra
Maintainer: root <[email protected]>
Build-Depends: debhelper (>= 8.0.0), autotools-dev
Standards-Version: 3.9.3
Homepage: http://netatalk.sourceforge.net/
#Vcs-Git: git://git.debian.org/collab-maint/netatalk.git
#Vcs-Browser: http://git.debian.org/?p=collab-maint/netatalk.git;a=summary

Package: netatalk
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: AppleTalk user binaries
 Open Source AFP fileserver capable of serving many Macintosh clients simultaneously as an AppleShare file server (AFP)

Then, add debian/rules adding this line, to pass custom configure parameters:

override_dh_auto_configure:
	dh_auto_configure -- --with-init-style=debian-sysv --with-zeroconf

The <TAB> is what you have to press to indent the code. Without that TAB, the file won’t work properly. Before dh_auto_configure there is a TAB 🙂
MAKE SURE that the syntax gets highlighted like this:

debian_rules

I’ve read that it should be good to run dpkg-depcheck -d ./configure before the next step.
Honestly, I didn’t do that because it requires an extra package called devscripts that installs loads of dependencies, which I didn’t want to add on my Raspberry pi.
In a different situation, I would probably have done that.

Then run:

dpkg-buildpackage -us -uc

…and wait.

If you get something like this…

dpkg-deb: building package `netatalk' in `../netatalk_3.1.7-1_armhf.deb'.
dpkg-genchanges >../netatalk_3.1.7-1_armhf.changes
dpkg-genchanges: including full source code in upload
dpkg-source --after-build netatalk-3.1.7
dpkg-buildpackage: full upload (original source is included)

…you’ve been lucky! And you can cd .. and you should have your package .deb created and ready to be installed with a simple dpkg -i .deb

Good luck! 🙂

NOTE: I’ve noticed that the compile might fail due to ‘acl‘ package missing. I’m not a master in compiling, so what I’ve done is the following

apt-get install acl

Than I’ve modified include/atalk/acl.h start at line 63, adding #define O_IGNORE 0 to make it look like following:

#define O_NETATALK_ACL 0
#define O_IGNORE 0
#define chmod_acl chmod

This trick was from here
Than, you need to commit the change with the following command: dpkg-source --commit and save adding a little description like “patch to compile with no ACLs” or something like that.
This made me possible to finish the building of the package and have the deb.

 


 

UPDATE: Debian jessy systemd

# Packages to install

apt-get install build-essential libevent-dev libssl-dev libgcrypt11-dev libkrb5-dev libpam0g-dev libwrap0-dev libdb-dev libtdb-dev libmysqlclient-dev avahi-daemon libavahi-client-dev libacl1-dev libldap2-dev libcrack2-dev systemtap-sdt-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev tracker libtracker-sparql-1.0-dev libtracker-miner-1.0-dev autotools-dev debhelper 

# How to edit debian/rules

override_dh_auto_configure:
	dh_auto_configure -- --with-init-style=debian-systemd  --without-libevent --without-tdb --with-cracklib --enable-krbV-uam --with-pam-confdir=/etc/pam.d --with-dbus-sysconf-dir=/etc/dbus-1/system.d --with-tracker-pkgconfig-version=1.0

And here the already compiled file netatalk_3.1.8

Backup Raspberry Pi SD on your Mac… and restore.

Plug the SD in your Mac.

In the Terminal, as root, use diskutil to identify your SD.
Generally it’s the last in the list, if you’ve just plugged in.

root:~ # diskutil list

You will see something like this:
diskutil_list_pi_sd

In my case, the SD is /dev/disk4. For this reason, I run the following to unmount the whole disk.

root:~ # diskutil umountDisk /dev/disk4
Unmount of all volumes on disk4 was successful

Once done, you can create the backup using dd utility, but make sure to change the device from /dev/diskX to /dev/rdiskX, adding the “r“.

root:~ # dd if=/dev/<span style="color: #ff0000;">rdisk4</span> of=/path/to/mypibackup.img bs=1m

To restore, of course… invert if (input file) with of (output file)… 🙂

root:~ # dd if=/path/to/mypibackup.img of=/dev/rdisk4 bs=1m

ESXi host on D945GCLF2 Intel Atom mainboard, with NFS storage attached running on RAID1

I’ve used this procedure to create a ESXi host on D945GCLF2 Intel Atom mainboard, with RAID1 storage built in, attached to itself 😉

On that, I have at the moment 3 VMs running (minimal Debian with NFS, FreePBX machine, Debian server with a little LAMP server, SAMBA and web based torrent client)…and more resources available.

How? 🙂

“Simply”, I needed:

HARDWARE

  • D945GCLF2 Intel Atom mainboard
  • 2GB or RAM DDR2 (667 or 533) in a single module
  • IDEtoSD adapter
  • 4GB SD card
  • 2 SATA Hard Drives – same capacity (I’ve used 2×2.5″ 160GB – It’s all installed in a little case)
  • spare SATA CD-ROM and a empty CD-ROM to burn the ESXi ISO (I had issues using a USB stick and utilities like unetbootin or similar… so I ended up with the old fashion but working systems)

SOFTWARE

  • ESXi 4.1 ISO – I couldn’t find a way to patch most recent ISOs. Patch is required to add support for the integrated NIC. Also 4.1 has all the required functions for this project.
  • Here the drivers and script to patch the ISO.
  • Debian net-install iso for the NFS vm.
  • vSphere client installed on your machine, to be able to connect to the host and copy the Debian ISO and manage the HOST.

Procedure

  1. Patch the ISO and burn it on your blank CD.
  2. Connect the IDEtoSD card to the single IDE channel, with the SD. This will be our “main IDE hard drive”.
  3. Make sure to have enabled Hyper Threading Technology in the BIOS.
  4. Connect (temporary) the SATA CD-ROM to one of the two SATA channels, with the ESXi CD in, and complete the installation on the “4GB IDE hard drive” present on the system.
  5. Turn off the host, remove the SATA CD-ROM and connect the two hard drives to the SATA connectors.
  6. Boot up, and create a local datastore with the remaining space of the SD (if this hasn’t been created already automatically) and call it “SD_local“. Here we will store our NFS machine which will provide NFS storage to the host.
  7. Create the RDM devices for our minimal Debian NFS machine follow the below instructions (ensure to make a minimal/basic installation, plus ssh, initramfs-tools, mdadm, nfs-kernel-server, nfs-common, portmap. No graphic interface, no extra packages!).
  8. Create the Debian NFS vm, share the storage using NFS, attach it to the host, and you are ready to go! 😉 The host will be ready to have VMs up and running, with their virtual hard drives stored on a redundant storage.

The scope of this is to allow the Debian NFS VM, which will be stored on the local storage called “SD_local“, to directly access the physical SATA hard drives, create a software RAID1 with them, and using NFS protocol, share the space to the ESXi host and use it to store VMs/ISOs etc.

Of course, this Debian NFS VM, and in particular the SD card, are the single point of failure of this project. But theoretically, a dd of the SD once all is configured can be a good “backup” in case of problems (and a spare 4GB SD home as well 🙂 )

ESXi – How to create a Physical RDM and attach it to a VM

1. Determine the VML ID for the SATA disks

# ls /dev/disks/ -l
-rw------- 1 root root 4041211904 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_
-rw------- 1 root root 939524096 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:1
-rw------- 1 root root 3097493504 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:2
-rw------- 1 root root 4177920 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:4
-rw------- 1 root root 262127616 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:5
-rw------- 1 root root 262127616 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:6
-rw------- 1 root root 115326976 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:7
-rw------- 1 root root 299876352 May 19 20:18 t10.ATA_____Memory_Card_Adapter_______________________________________0_:8
-rw------- 1 root root 160041885696 May 19 20:18 t10.ATA_____ST9160821AS_____________________________5MA57R13____________
-rw------- 1 root root 160041885696 May 19 20:18 t10.ATA_____ST9160821AS_________________________________________5MA8PT4Q
lrwxrwxrwx 1 root root 72 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:1 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:1
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:2 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:2
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:4 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:4
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:5 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:5
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:6 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:6
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:7 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:7
lrwxrwxrwx 1 root root 74 May 19 20:18 vml.010000000020202020202020202020202020202020202030204d656d6f7279:8 -> t10.ATA_____Memory_Card_Adapter_______________________________________0_:8
lrwxrwxrwx 1 root root 72 May 19 20:18 <span style="color: #ff0000;">vml.0100000000202020202020202020202020354d413850543451535439313630</span> -> t10.<span style="color: #0000ff;">ATA_____ST9160821AS</span>_________________________________________5MA5SS2A
lrwxrwxrwx 1 root root 72 May 19 20:18 <span style="color: #ff9900;">vml.0100000000354d413537523133202020202020202020202020535439313630</span> -> t10.<span style="color: #0000ff;">ATA_____ST9160821AS</span>_____________________________5MA43W02____________

2. Find the two hard drives

Highlighted in red and orange (in blue I’ve highlighted the serial number which helps to identify them as well).

3. Check the volumes available

# ls -l /vmfs/volumes drwxr-xr-x 1 root root 8 Jan 1 1970 ed0aa47f-f157c36d-0295-b6663f811221 drwxr-xr-x 1 root root 8 Jan 1 1970 e2f7c177-db75edcf-defa-90346375bdf2 drwxr-xr-x 1 root root 8 Jan 1 1970 2da668ef-40e5d96b-90bf-855ddb9c5547 drwxr-xr-t 1 root root 1.4k May 19 21:29 4fb7f163-a1959434-4766-001cc07e74e5 lrwxr-xr-x 1 root root 35 May 19 23:16 SD_local -> 4fb7f163-a1959434-4766-001cc07e74e5 lrwxr-xr-x 1 root root 35 May 19 23:16 Hypervisor3 -> 2da668ef-40e5d96b-90bf-855ddb9c5547 lrwxr-xr-x 1 root root 35 May 19 23:16 Hypervisor2 -> ed0aa47f-f157c36d-0295-b6663f811221 lrwxr-xr-x 1 root root 35 May 19 23:16 Hypervisor1 -> e2f7c177-db75edcf-defa-90346375bdf2

4. Use one of the available to create a subfolder that will contain the VMDK information for the RDM disks (using SD_local)

# cd /vmfs/volumes/SD_local/
/vmfs/volumes/4fb7f163-a1959434-4766-001cc07e74e5 # mkdir RDMs
/vmfs/volumes/4fb7f163-a1959434-4766-001cc07e74e5 # cd RDMs/

5. Create the devices

vmkfstools -z /vmfs/devices/disks/vml.0100000000202020202020202020202020354d413850543451535439313630 rmd_sata1.vmdk -a lsilogic
vmkfstools -z /vmfs/devices/disks/vml.0100000000354d413537523133202020202020202020202020535439313630 rmd_sata2.vmdk -a lsilogic

6. New RDM devices created and ready to be added to the VM

  • Edit the properties of an existing VM and click Add
  • Select Use an existing virtual disk and click Next >
  • Click Browse. You now need to navigate your local datastore ([SD_local]/RMSs) and select the VMDK’s that we created
  • Select Permanent / Persistent > Next..
  • You should now see your new Hard Disk’s in your VM and vSphere will correctly identify them as Mapped Raw LUN.

7. Run your linux VM and create Linux Raid auto (FD type)

8. Create the mdX device

# mdadm --create /dev/md0 --chunk=4 --level=0 --raid-devices=2 /dev/sda1 /dev/sdb1

9. Create the filesystem and add it to /etc/fstab

 

Sources
http://www.vm-help.com/esx40i/SATA_RDMs.php
http://blog.davidwarburton.net/2010/10/25/rdm-mapping-of-local-sata-storage-for-esxi/

Mac – Time Machine on a Raspberry Pi

Requirements

First of all, you need the following:

  • a raspberry pi installed with 1 USB port available,
  • 1 external USB drive (I’ve used a 3TB external USB drive), pre-formatted under your Mac in HSF+, labelled as TimeMachine
  • internet connection 🙂
  • …and some time to perform all the steps and the initial backup.

Installation of your pi

As root, run the following to upgrade the system and install the required packages:

apt-get update && apt-get upgrade && apt-get -y install hfsplus hfsutils hfsprogs avahi-daemon libavahi-client3 db-util libgcrypt11

Now all the required debian packages are installed. We will install netatalk from the source code, because the debian packages are very old.

Setup the hard drive

Create a mount point as root:

mkdir /TimeMachine

Connect your external USB drive to your pi and run as root the following:

blkid

The output should be something like this:

 # blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" UUID="xxxx-xxxx" TYPE="vfat"
/dev/mmcblk0p2: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" TYPE="ext4"
/dev/sda1: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" TYPE="ext3"
/dev/sdb1: LABEL="EFI" UUID="xxxx-xxxx" TYPE="vfat"
/dev/sdb2: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" LABEL="TimeMachine" TYPE="hfsplus"

Please take note of the UUID where you can see your hard drive installed and add the following line in your /etc/fstab file:

UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" /TimeMachine hfsplus rw,force,exec,auto,users 0 0

Now your drive will be automatically mounted at each reboot of the machine.

Install and configure Netatalk demon

Here you have 3 options:

  1. You can follow this guide if you want to create a .deb package which is easier manageable, especially on Debian;
  2. (For the lazy ones) download my precompiled deb file of version 3.1.1 from here, or 3.1.7 version from here, unzip and install it using dpkg -i
  3. Otherwise… just follow the next steps 🙂
Compile and install Netatalk

Download the latest stable code from here.
I’ve personally used version 3.0.4 for a while, and now I’ve upgraded to version 3.1.7.

Decompress the file, enter the folder and run the following:

./configure --with-init-style=debian --with-zeroconf

If no errors:

make

As root:

make install
cd /etc/init.d/
update-rc.d netatalk defaults

Configure afp.conf

Based on your version, you could have the configuration files in different locations.
Use the command afpd -v | grep "afp.conf"  to locate your afp.conf file.

Edit afp.conf based on your network configuration:

I’ve setup also an extra bit called [Homes] which shares the user /home directory using the same protocol. Quite handy to move around files 🙂 But this last part is NOT required for the scope of this post.

[Global]
mimic model = TimeCapsule6,106
; Global server settings
; Name of your computer in apple devices network
hostname = <your raspberry pi HOSTNAME>
; IP of your Pi
afp listen = <your raspberry pi IP>
hosts allow = <your network or the Mac's IP, for example 192.168.1.0/24>
; logging config
log file = /var/log/netatalk.log
log level = default:warn

[TimeMachine]
; Our Time Machine volume
path = /TimeMachine
cnid scheme = dbd
file perm = 0660
directory perm = 0770
time machine = yes

[Homes]
basedir regex = /home
cnid scheme = dbd
; Display each user home directory in this format
home name = Home $u

Now we can mount the drive and restart the services:

mount /TimeMachine && /etc/init.d/netatalk restart && /etc/init.d/avahi-daemon restart

Now the disk should be visible from your Mac and Time Machine application 🙂

First Time Machine backup

For the first Time Machine backup, I would really recommend to connect the external drive directly to the USB port of your Mac and follow these steps.

Before disconnect the drive from your pi, make sure to stop the services and unmount properly the disk:

/etc/init.d/avahi-daemon stop && /etc/init.d/netatalk stop && umount /TimeMachine && mount

Make sure the output does NOT show /TimeMachine mounted.

Create a sparsebundle manually

Connect the USB drive to your Mac and from the Terminal do the following:

cd /Volumes/TimeMachine/
hdiutil create -size 1500g -fs HFS+J -volname "TMachine" NAME_XXXXXXXXXXXX.sparsebundle

NAME is the hostname
XXXXXXXXXX is your MAC Address without “:”
200g means 1.5 TB (1500 GB). Please make sure it’s big enough to contain the first backup. After it will expand automatically. But if you set it less than the space required for the first backup, Time Machine might ignore it and create a normal folder structure, typical of USB hard drives.
Best practise is set about 80% of the capacity of your hard drive 😉

Start the first backup

Then, add this disk to Time Machine and let’s the backup start and finish.
For the fist backup, if it’s around 1Tb, be ready to leave the PC on all day.

Make sure that NO directories are created in the USB disk.
Just check the size of the sparsebundle file during the initial backup process. If it increases, it’s working! 🙂

I have to admit that I was doing something else when I’ve launched the backup and I’ve realised (I guess) that the sparsebundle file got renamed by Time Machine in a format like <hostname>.sparsebundle. Not sure why but… well, all worked so… from now on, I will use this new name for that file. :-p

If the backup doesn’t start automatically using the sparsebundle file, you can try to force it following these steps:

1) double click on your file sparsebunle to mount it
2) From Terminal, as superuser, run

tmutil setdestination /Volumes/TMachine/

3) Now force to run a new backup

Once completed, just take notes of the current permission of that file. You can check via terminal running ls -l /Volumes/TimeMachine/.
Now unmount the hard drive and reconnect it to your Raspberry Pi.

Final setup on the Raspberry Pi

Before mounting, do a quick check running the following (/dev/sdb2 is my Time Machine drive – please review the output of blkid if unsure):

fsck.hfsplus -f /dev/sdb2

If all is fine, you can mount the drive:

mount /TimeMachine/

And now, do a little trick to make sure to avoid permissions issues, and allow Time Machine to be able to write into the sparsebundle “file” (you will realise on Linux that it’s in fact a directory tree with files).

We’re going to create the same user and group that we have on the Mac on our Raspberry Pi.
Run a handy ls -l /TimeMachine and take note of the UID and GID.
If the group shows as numeric value, as root, you can run groupadd -g GID MACGROUP .

NOTE:GID is the value that you’ve seen with the previous command and MACGROUP is the name of the group that you saw running ls -l /Volumes/TimeMachine/ on you Mac Terminal.

Now, as root, create a new user that matches with the Mac user.

useradd -u UID -g GID MACUSER -m

NOTE: Same as before, UID is the value that you’ve seen with the previous command and MACUSER is the name of the user that you saw running ls -l /Volumes/TimeMachine/ on you Mac Terminal.

Now check again with ls -l /TimeMachine and you should see something like this: drwxr-xr-x 1 macuser staff 11 Apr 2 10:22 HOSTNAME.sparsebundle

NOTE: The group might be displayed as ‘dialout’ (or something else) instead of ‘staff’ as on your Mac. This is not a problem, as long as the numeric GID matches. If the group still shows as numeric value, it groupadd -g GID ‘staff’

All good? Then let’s restart netatalk:

/etc/init.d/netatalk restart

And now, we’re ready to:

  1. Add the remote disk “TimeMachine” to Time Machine;
  2. Initialise a second backup, just to make sure that all works fine (this will be probably less than 1GB);
  3. Have a drink as reward after all this work 🙂

Sources:
http://garmoncheg.blogspot.com.au/2012/11/time-capsule-for-25.html
http://administeria.com/?s=time+machine
http://buffalo.nas-central.org/wiki/Time_Machine_&_Time_Capsule_support_on_your_LinkStation

Mac – Upgrade rsync to version 3

Quick method:

change /private/etc/paths putting ahead /usr/local/...

<span style="color: #ff0000;">/usr/local/bin</span>
<span style="color: #ff0000;">/usr/local/sbin</span>
/bin
/usr/bin
/usr/sbin
/sbin

Then, unzip this precompiled rsync into /usr/local/bin

Restart the Terminal and run

rsync --version

This should be the output:

rsync version <span style="color: #ff0000;">3.0.9</span> protocol version 30
Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes

Mac/Linux – Terminal customisation .profile/.bashrc

For Mac, you need to create a .profile file in your home directory.

This is what I’ve done on mine…

For normal user:

user_bashrc

export PS1="\[\e[00;32m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;37m\]\h\[\e[0m\]\[\e[00;37m\]:\[\e[0m\]\[\e[00;33m\]\w\[\e[0m\]\[\e[00;37m\] \[\e[0m\]\[\e[00;32m\]\\$\[\e[0m\]\[\e[00;37m\] \[\e[0m\]"
# Customisation of 'ls' command
export CLICOLOR=1
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"
alias ls='ls -GF'

 

For root:

root_bashrc

export PS1="\[\e[00;31m\]\u\[\e[0m\]\[\e[00;37m\]:\[\e[0m\]\[\e[00;33m\]\w\[\e[0m\]\[\e[00;37m\] \[\e[0m\]\[\e[00;31m\]\\$\[\e[0m\]\[\e[00;37m\] \[\e[0m\]"
# Customisation of 'ls' command
export CLICOLOR=1
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"
alias ls='ls -GF'

Sources:
http://bashrcgenerator.com/
http://geekology.co.za/article/2009/04/how-to-enable-terminals-directory-and-file-color-highlighting-in-mac-os-x
http://apple.stackexchange.com/questions/33677/how-can-i-configure-mac-terminal-to-have-color-ls-output
http://osxdaily.com/2013/02/05/improve-terminal-appearance-mac-os-x/

Mac /Users partition on RAID1

This is what I’ve created:

  • Fresh new installation of Mac OS X Lion on a new 128SSD hard drive (this should work with Mavericks too);
  • Create a RAID1 with the 2 TB disks, and mounted in /Users;
  • Restored apps/confs/data from Time Machine using Migration Assistant.

Create RAID1

This is quite handy to have the user’s data safe.
I’ve simply created a RAID1 using Disk Utility and set this new device to auto mount in /Users folder 😉
Call the new device “Users“. I will use this name as reference in this guide.
Simply drop the hard drives in the Raid section and select Mirrored Raid Set – Mac OS Extended (journaled)
Once created, CMD+I on the new device and take note of Universal Unique Identifier the famous UUID

It might be interesting to follow this guide to create an encrypted logical volume on the RAID partition to save your data 😉

How to mount this new drive in /Users?

First of all you need to enable “root” user

Very easy… open Terminal, got superuser privilegies (sudo su - command) and once the prompt shows “#“, type passwd command.
Set a new password (it will ask to insert it twice).
Now, go to Users and Group and in Login Options select Show Input menu in login window (this can be rolled back once finished).
Logout (better if you do a full reboot).
Once the OS is up again you will have an “old fashion” login window, where you need to enter username and password.
Fantastic!
Insert root as username and the password is the one you’ve just set via Terminal: you will login as super user.

Second, copy the current data

Now… back to the Terminal!
Open it (and you will be already root user! ), have handy the UUID you’ve saved before and digit the following commands:

cd /
cp -a /Users/* /Volumes/Users/
cp -a /Users /Users.orig
rm -rf /Users/*
vifs

Now you need to press SHIFT+g
Then press o
Then insert the following, of course replacing the XXX with your UUID

UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX /Users hfs auto

Once finished, to save press these in sequence esc : wq

For more info check any vim editor guide.

What we’ve done is coping the full content of /Users in our new RAID device (called “Users” during the RAID setup).
Created a copy on the local drive as well (just to stay from the safe side 😛 )
Removed all the content of /Users and make it ready to get the new RAID1 device mounted inside (sounds a bit xxx but it’s not 😀 )
Edited /etc/fstab to auto mount the RAID1 device automatically at the boot.

Third… reboot and login

Now it’s all ready for the reboot and login with your normal user!
Once confirmed that all works, you can safely remove Users.orig folder and restore the original login window.

Forth (optional): restore from Time Machine

Now you can finally restore your data manually using Time Machine.
Migration Assistant will probably fail if the amount of data is bigger than the size of your main OS disks. The reason is that It’s not able to understand that there are extra 2TB of space under Users.
What I’ve done is restoring ALL my OS except the users, using Migration Assistant, and then, I’ve used Time machine and copied manually all the folders inside /Users … and all worked! 😉