Itâs bound to happen that you have an awesome Linux setup ⦠until the latest and greatest new processor comes out. But donât worry, with a Linux installation you can move the things you want to keep to your new machine, and get a fresh installation on the things you donât.
Preparation
Since youâll essentially be backing up then restoring your files, youâll need to get your backup media ready. There are a couple of things youâll want to keep in mind before you do so:
- When backing up ânormalâ files, such as those from your home folder, youâll typically be importing them into a new home folder. In this case, the ownership of those files will be set to your default permissions (which are your username as both the owner and group, e.g. âuser:userâ), But when migrating system files, youâll need to make sure that the ownership remains intact.
- Likewise with the permissions (to get a rundown on Linux permissions, take a look at MTEâs primer on the subject). This means youâll need to back these files up to a Linux filesystem that supports the same ownership and permission structure.
- It may be difficult to back these files and directories up while the machine is running. There may be programs or processes that are constantly updating them â" some may even be locked. You may need to turn the machine of and boot using a Live CD or USB drive in order to get the data you need.
Selecting Your Backup Files
When moving your existing Linux set-up to new hardware, there are some directories youâ ll want to include:
- /home/ â" Of course, youâll want to make sure you take your working files (documents, e-mail, media, and all the application settings you spent so long tweaking). Fortunately, Linux keeps all these under the â/home/[user's name]/ directory for each user. You can just grab the whole â/homeâ directory to back this up for all users.
- /etc/ â" This directory contains global configurations. Configurations such as web server settings, service definitions (e.g. when that web server starts automatically at boot, itâs a file in â/etc/init.d/â that defines this), and some default configurations (i.e. if you install a new program, the settings that are created for you the first time you run it).
- /root/ â" Any files you create after a âsudoâ command will be stored here by default. This directory doesnât get used much in Ubuntu (the âsudoâ command saves you from actually having to log in as root), but better safe than sorry.
- /var/ â" Data generated and maintained by system programs such as daemons is stored within the /var/ directory. Mail (if you run your own mail server) and server data (like web files for Apache) are two examples.
If youâre moving to a machine with the same architecture (i.e. âi386? for 32-bit processors, or âamd64? for 64-bit), you may also want to add the following⦠they might be empty, but then it doesnât cost you anything!
- /opt: Completely âoptionalâ software may be installed here, e.g. applications packaged for your distribution that are not included in any official repositories.
- /usr/local/: Custom software, particularly software you compile from source code, can be installed in this directory. Other types of programs are those that you simply extract from an archive (such as a âtar.gzâ file).
Backing Up Your Applications
You may look at the list of files above and think, âWhat about all my packages?!?â Donât worry; thereâs a way to grab a list of all those applications that will allow you to reinstall them all with a single command. This is a good way to save you from having to transfer tens of gigabytes of files to your backup media, only to have to transfer them back again.
With the above prepared, letâs move that Linux!
The Migration Process
1. As noted above, itâs a good idea to shut your machine down and boot using a live distro.
2. Once youâre there, mount the hard drive containing the old Linux installation. Weâll call this path â/mount/path/to/installâ below.
3. First, grab that list of all the packages you installed with the following command:
sudo dpkg --get-selections > /mount/path/to/install/home/[your user name]/packagelist.txt |
This will place the text-file list of packages in your home directory, which weâll back up right now.
4. The next step is to back up your files. Itâs best to do this as root, since thatâs who will own some of the files youâre backing up. By the same token, be sure that any settings or flags will be set to preserve both ownership and permissions. You can either use a command-line program like rsync or GUI program such as Backintime
5. Now, get Linux installed on your new machine.
6. Once the in stallation is done, reboot, but back into a live distro.
7. Now, restore all the files you backed up above. Again, you may need to be root to make sure all the permissions and ownership are preserved.
8. Almost done⦠run the following commands to restore all the packages you had previously in one shot:
sudo dpkg --set-selections < /mount/path/to/install/home/[your user name]/packagelist.txt |
All the packages you had before are now set for installation, but not yet installed. The last step is the following command to install them:
sudo apt-get -u dselect-upgrade |
No comments:
Post a Comment