Sync Howto

Syncing HomeDir with USB-Stick

Since I have a home computer as well as a office laptop I always had a synchronizing problem. My solution until now was to carry my laptop home with me every day. This is no adequate solution! The goal was to use an usb stick to transfer the home directory between the two locations.

1.  
First of all prepare the stick. It should preserve the permissions. Hence, change the fs to ext3 by running ‘mkfs.ext3 /dev/<usbdevice>’.

Note: If you want an encrypted filesystem on your stick do the following additional steps:
          � losetup -e aes /dev/loop0 /dev/<usbdevice>
          � enter passwd
          � mkfs.ext3 /dev/loop0
          � losetup -d /dev/loop0
2.  
Run ‘apt-get install unison-gtk gtkdialog’. There are two possible solutions to tell unison-gtk which folders he should synchronize. If you run it without arguments you can select a profile from a list. This implies that you have to configure a profile the first time you start unison-gtk. The second possibility is to add the two folders as parameters to the program call. In this case you have to change the call in ‘/home/joe/myscript’ (3.) accordingly. Moreover create the directory ‘/media/homestick/’.

3.  
Create the script that should be executed after inserting the stick in ‘/home/joe/myscript’:



Change the permissions of the file to 755.

Note: If you want an encrypted filesystem on your stick do the following additional step:
          � extend the call of "mount /media/homestick/" to "gtk-led-askpass | mount /media/homestick -p 0"

4.  
Now we need the serial of the stick. Run ‘sudo udevcontrol log_priority=debug’, insert the stick and search in ‘/var/log/syslog’ for an entry like

udevd-event[7930]: run_program: ‘/lib/udev/usb_id’ (stdout) ‘ID_SERIAL_SHORT=036857193650’

Copy the Serial_short value.

5.  
Since we want to use other usb sticks in the common way, the next step is to configure udev to run the synchronization routine only when our special device is attached. Create the file ‘/etc/udev/rules.d/66-homefolder-stick.rules’ and insert the following lines (substitude the serial_short value, the user and the script location):

This will create the device ‘/dev/homestick’ as soon as you insert the stick and executes the script ‘/home/joe/myscript’ as user joe. Now we have to tell udev that this special device should not be mounted as normal device. Otherwise this will be done additionally. Change ‘/etc/udev/rules.d/95-hal.rules’ such that the hal socket is only opened if the serial differs from our serial. My file looks like that:

6.  
Edit ‘/etc/fstab’ and insert the following line:

/dev/homestick /media/homestick auto users 0 0

Note: If you want an encrypted filesystem on your stick do the following additional step:
          � extend the option "users" to "users,loop,encryption=aes"

7.  
debugging:

sudo udevcontrol log_priority=debug
unison-gtk -debug verbose (in /home/joe/myscript)
less /var/log/syslog

8.  
Run 2.-6. on the other computer as well. Take care, that the user and the user id on both systems are equal. For this purpose have a look at ‘/etc/passwd’ and ‘/etc/group’. !!! Do not change those files unless you really know what you do. Otherwise you might have real trouble afterwards. !!!

* I decided to use the whole usb stick without any partitions. Alternatively you can use fdisk to generate partinitions. Then you have to modify some steps:

mkfs.ext3 /dev/sdaX

Run ‘blkid’. You will get some output like:

dev/sdaX: UUID="e4b5f706-be18-493c-b603-1b96802c8cfc" TYPE="ext2"

Use the UUID instead of ID_SERIAL_SHORT in ‘/etc/udev/rules.d/66-homefolder-stick.rules’ and add an %n to the devicename:

The same in ‘/etc/udev/rules.d/95-hal.rules’:

Finally you have to change ‘/etc/fstab’ such that the right partion is mounted.