Move Your /home to Another Computer

Posted: 16 Mar 2005

Having bought a new machine, I was looking for a cool program to migrate my user settings from my old box to the new one. I needed something that would keep all my tweaks to KDE, my Evolution email, and my GAIM settings. A simple thought from a Linux-savvy friend of mine brought me to the realization, "Hey! I don't need a special program to do this!"

If you need to back up your settings or migrate them to a new machine, this tutorial will help. My aim is to explain a quick, painless method of doing this.

For this exercise, 'old machine' refers to the computer that has the current user data on it. This is the machine whose data you are going to back up. Conversely, 'new machine' refers to the machine to which you are going to move and restore your data.

First, log out of your window manager, and go back to your login manager. In KDE, you can do this by clicking on the K Menu, and clicking LOGOUT. Click END CURRENT SESSION from the window that appears. You are then taken back to your login screen. In Gnome, click on the SYSTEM menu, then the LOGOUT [username] option. In the window that comes up, select the LOGOUT radio button, and click OK.

You should now be back at your LOGIN window. What we need to do now is invoke one of your command-line terminals. Press CTRL+ALT+F1. You should never, ever log in as root. However, because we cannot have our user logged into the system, at this time, we are going to log in as root:

Welcome to SuSE Linux 9.2 (i586) - Kernel 2.6.8-24.11-kefault (tty1).

linux login: root
password:
Last login: Fri Mar 11 09:28:24 on tty1
Have a lot of fun...
linux:~ #

At this point, it might be a good idea to make sure no other users than root are logged in. Type in 'who' and press ENTER:

linux:~ # who
root     tty1            Mar 14 14:45
linux:~ #

You should only see the 'root' user logged in. If other users are logged in here (especially the user whose data you are working with), the process will abort and throw errors at you.

Go to your /home directory:

linux:~ # cd /home
linux:/home # 

Next, create a gzipped tar archive of your home directory. Mine is called 'smorris', so that's what I'll use. Replace 'smorris' in the example with your own username:

linux:/home # tar -cjf home.tar.gz smorris

List the directory's contents to see your archive:

linux:/home # ls -lh
total 49M
drwxr-xr-x   5 root    root   136 Mar 14 14:55 .
drwxr-xr-x  27 root    root   632 Mar 14 11:39 ..
-rw-r--r--   1 root    root   49M Mar 14 14:55 home.tar.gz
drwxr-xr-x  30 smorris users 1.5K Mar 14 11:42 smorris

You now have a gzipped tar archive of your home directory. This archive will have most (if not all) of your preferences for the applications you have installed. It will probably have all of your email messages in it. IM chat logs can also be found in the archive. There are two things you can do from here. You can put it on a CD as a backup of personal data. Alternatively, you can copy it to another machine and unarchive it, restoring to that machine all of your preferences. It is the latter option that we will execute here.

Go over to the new machine to which you are going to copy the archive. On this machine, I will assume that you already have created a user with the same name as on the other machine. For example, my username is 'smorris'. I have this user on the old machine that I am backing up. I also have created this user on the new machine where I am restoring the backup. Log in as root (normally, this is not good practice, but is necessary here). You might want to do this in the same manner as you did with the old machine, above. Once you are logged in, make sure there is an ssh daemon running. To do this, open a terminal window. At the command prompt, type 'ps aux | grep sshd' and then press ENTER:

linux:/home # ps aux | grep sshd
root      4191  0.0  0.4  5144 2068 ?        Ss   12:30   0:00 /usr/sbin/sshd
root      6154  0.0  0.1  2604  704 pts/2    S+   16:21   0:00 grep sshd
linux:/home #

Look at the first line of the output. Over towards the right, you see '/usr/bin/sshd'. This is our ssh daemon.

If you do not see this, you'll want to run it. To run the ssh daemon, type '/etc/init.d/sshd start' and press ENTER:

linux:/home # /etc/init.d/sshd start
Starting SSH daemon                                     done
linux:/home #

You should see the ssh daemon starting up as in the above example.

Once you're sure the ssh daemon is running, we're ready to copy the file to the new machine. For this step, you will need to know the IP address of the new machine. Still at the new machine, type '/sbin/ifconfig' and press ENTER:

linux:/home # /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:6E:6C:66:62
          inet addr:137.65.68.1  Bcast:137.65.71.255  Mask:255.255.252.0
          inet6 addr: fe80::20c:6eff:fe6c:6662/64 Scope:Link
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:168221 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21408 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:35849611 (34.1 Mb)  TX bytes:2336595 (2.2 Mb)
          Interrupt:5 Base address:0x4000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:111 errors:0 dropped:0 overruns:0 frame:0
          TX packets:111 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:11519 (11.2 Kb)  TX bytes:11519 (11.2 Kb)

linux:/home #

There are two sections, 'eth0' and 'lo'. Completely disregard the 'lo' section. In the 'eth0' section, the second line starts with 'inet addr:' and has the IP address immediately after it. In my case, it is 137.65.69.1.

Go over to the old machine (the one with the home.tar.gz backup on it). You should still be at a terminal.

On this machine, initiate the file transfer. Type 'scp home.tar.gz root@137.65.69.1:' and press ENTER. Remember to replace the IP in this example with the IP of your new machine. Note the trailing colon. It is required:

linux:/home # scp home.tar.gz root@137.65.68.1:
The authenticity of host '137.65.68.1 (137.65.68.1)' can't be established.
RSA key fingerprint is bd:8c:a0:98:e5:0f:22:74:27:fb:b0:cb:ef:c7:6e:4f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '137.65.68.1' (RSA) to the list of known hosts.
Password:
home.tar.gz                                100%   49MB  12.2MB/s   00:04
linux:/home #

Now, head back over to the new machine. Move the archive from the /root directory to the /home directory, and then go to that directory:

linux:~ # mv /root/home.tar.gz /home
linux:~ # cd /home
linux:/home #

Before we go any further, let's just make sure noone else is logged into the machine:

linux:/home # who
root     tty1            Mar 14 14:45
linux:/home #

The 'root' user should be the only one logged in.

Next, let's rename the folder that already exists for the user. That way, we can restore it later if something goes awry:

linux:/home # mv smorris smorris.1
linux:/home #

Now, unarchive the file:

linux:/home # tar -xjvf /home.tar.gz

You'll see a ton of stuff scroll up the screen.

When it finishes, you have restored your user's settings to that computer.

Once again, let's just make sure you have a user account that uses that directory as their home directory. You can check this by running the following command. Remember to replace 'smorris' with your username:

linux:/home # cat /etc/passwd|grep smorris
smorris:x:1000:100:Scott Morris:/home/smorris:/bin/bash
linux:/home #

You can see that there is a user 'smorris' that uses '/home/smorris' as its home directory.

Now, you can reboot the machine (type 'shutdown -r now' and press ENTER). When your machine reboots and the login manager comes back up, log in as your user (not root). When you run applications, they should already have all of the preferences and settings that you had on your old system. Some programs will even have items in the 'most recently used' menus that you had open on your old machine.

If you want a quick and dirty way to make backups, this will do it. If you want to migrate your user data, preferences, settings, email, etc., from one computer to another, this will get it done. In any case, this is a nice tool for your toolbelt.



Informacja z serwisu http://www.djack.com.pl