Moving home folder to new installation of Ubuntu
Solution 1:
Yes. I have done many times. rsync has a mode "-a" which preserves ownership, file times, everything. Can send files across network. Or you can copy to an ext4 formatted external disk and restore with rsync. Just remember don't copy with the ordinary drag and drop, use rsync and preserve the archive of all properties ("-a").
Suppose my.old.computer has your account "myuser".
Set up new computer my.new.computer. Create "myuser" there. if you are fastidious, get the user ID and group ID from old system and assign them when you create the user account. That may reduce problems, but I think I only do it because I'm old fashioned and this went wrong once in 2005. Know what I mean about uid and gid? Numbers of the user account. On the old system run "id myuser" , then when you create the new user on new computer, you assign same uid and gid.
Create some other account on both of these systems, we don't want to try to copy a user folder for "myuser" when that user is logged in, since a session depends on files you destroy. Repeat: Must not log in as myuser when you want to copy files for the myuser account. On either system.
On new system, as root, move the default user directory out of way (be safe, don't delete!), then create new directory
sudo mv /home/myuser /home/myuser.orig
sudo mkdir /home/myuser
sudo chown myuser.myuser /home/myuser
You need that last step so that your ordinary user account can rsync
the files in. We don't want to do that as root
Then copy the folder /home/myuser
from old to new, using the rsync
flags -rav
.
Can send files from old system to new system. On the old system
cd /home
rsync -e ssh -ravn myuser [email protected]:/home
Where:
-
-r
: recursive -
-a
: archive mode -
-v
: verbose mode. You can leave that out, it will go faster. But with less reassurance. -
-n
: don't actually make any changes
I put the -n
flag because I want a test run; if there are errors we will find out. After testing, run same command with no -n
flag.
This will only work if your user account has permissions to copy and write the files in /home/myuser. I'm not entirely sure how to do that without being root, but I used to know, and I bet somebody here knows what to do.
Or if you are in new system, can copy from other
cd /home
rsync -e ssh -rav my.old.computer:/home/myuser .
Period .
means the current working directory. Run with the -n
first to see what's wrong.
I've done this many times. The manual setting of the uid and the gid really should not be necessary, since the combination of ssh and rsync should assign the new files correctly. However, I got this wrong once and all the new files turned up as used by the wrong user. Where you expect to see ls -la output like this:
rw------- 1 myuser myuser 174 Aug 4 22:43 .Xauthority
you see user numbers, like
rw------- 1 504 50004 174 Aug 4 22:43 .Xauthority
or, worse, some other user's name. It happens because the uid and gid really determine file ownership; the human-readable name is superficial.
You can usually fiddle your way out of that with chown
, but you'll not see if if you line up the uid and gid.
Do not worry too much if the copy over fails once, or does something you don't expect, because you can always run over again. You are not destroying the old computer, and the new computer is, well, blank slate.
I think some tar lovers will say that the best way is to tar up the old thing, move the tar.gz file, then expand that. In 2003 or so, that seemed vital to us, but lately the rsync method has worked fine.
By the way, if one is interested in learning about rsync
, the man rsync
is one of the best, most helpful man pages ever. It is human readable with a ton of examples and it is one of the reasons I cling to rsync
like a life raft in system maintenance.