How can i move an encrypted home directory to another partition?

How can i move a enrypted home directory to another partition? Are there differences between moving an unencrypted home directory to another partition and an encrypted home directory?

Perhaps does Ubuntu installer offer an option to place your home directory on an other partition?


I am assuming you want to keep your data encrypted on the new partition.

First close all running applications, we don't want files being updated during the copy. Copy the encrypted data to the new partition:

ecryptfs-umount-private
chown $USER /new_mount_point/$USER
rsync -avP $HOME/.Private $HOME/.ecryptfs /new_mount_point/$USER
editor /etc/passwd # Change the user's home dir to point to the new location

Log-off Log-in

If you want to move/copy an encrypted home you only need to copy/move ~/.Private and the encryption keys (~/.ecryptfs). If you want to copy/move to an unencrypted location just copy everything except .Private and .ecryptfs.


After half a day of getting confused trying to move an encrypted home to a new drive with ubuntu 10.04 I eventually found this thread.

mount your new drive
make a new folder on it with your user name
make sure your the owner of it

chown $USER /new_mount_point/$USER

if your file structure under home looks like this

  • home/user/.Private
  • home/user/.ecryptfs
  • home/.ecryptfs

use this replacing $HOME and $USER otherwise try How can i move an encrypted home directory to another partition?

ecryptfs-umount-private
rsync -avP $HOME/$USER/.Private $HOME/$USER/.ecryptfs /new_mount_point/$USER
rsync -avP $HOME/.ecryptfs /new_mount_point

rename your home folder to something else "homeold"
make a new folder called home

Edit your fstab
mount the new drive to /home

Restart


There's another way to do this still:

Using the Ubuntu Help page found at https://help.ubuntu.com/community/Partitioning/Home/Moving

That tutorial will show you how to move an unencrypted partition, but the tweak I used for moving an encrypted partition was to follow that tutorial with the following difference in commands. My explanation for why I did it this way may need some corrections from someone who knows more than me, so please edit or comment if you have time.

  1. Create your partition in Gparted, and give it a label that you will easily recognize. Some of us have too many disks and partitions to remember by numbers.

  2. Before using rsync to copy the files over, unmount your encrypted home using ecryptfs-umount-private. The reason I did this was because rsync seemed to copy the mounted/unencrypted stuff AND the .Private ecryptfs thingies. You only need the .Private and .ecryptfs folders mentioned in the earlier posts.

  3. To copy the files, enter the command "sudo rsync -aVP /home/ /media/home/" instead of using " sudo rsync -aXS --exclude='/*/.gvfs' /home/. /media/home/. " as the tutorial says.


a note on the output from the command "sudo diff -r /home /media/home"

The diff command did report a long list of differences in my case, but I think that was because I was still using Firefox and opening a bunch of documents which changed bookmarks,history etc. I checked my files after completing all of the steps in the tutorial and didn't notice anything missing. After restarting, Firefox reopened a session with a bunch of tabs that I had closed long before copying the files over, hence my assumption about the output of the diff command.