Change a computer but preserve the OS (Arch Linux) and data

This is interesting. Previously, if I want to change a computer, I will (re-)install the OS and other software on the target computer. Then only move the data.

Since Arch Linux is a minimalistic distro, and installation only available with network connection. This will be exhaustive to install the OS on the target computer. Not only wasting time downloading, but also setup the configurations, such as web server, FTP server, hibernation, power save, etc. User’s configurations are easier, because I can just copy all the files in /home/$USER directory to the target computer. The only problem may be the differences of the owner ID and group ID. But that is not really a big deal. So, the main problem is the root (/).

Cloning the partition is not a good solution. Firstly, the target computer is different, I wish to preserve the original OS. If cloning the partition, the target computer needs to have extra space for the cloned partition. Secondly, configuration such as GRUB, fstab, and other partition related configuration will not work. To fix them, I need to find all these configurations, but how do I get them?

Luckily, Arch Linux is a minimalist distro, which has its great advantage. So, this is what I did.

Firstly, I get the latest installation ISO. Then, partition the target computer with SystemRescueCD. (I tried with LVM, but at the end failed, because the first partition is started at sector 63. Installing GRUB where the /boot is in the LVM requires larger partition space.)

Then, boot into the Arch Linux live media, and follow all the installation steps as in the official installation guide. As expected, the installation of the “base” requires network connection. It is around 100+ MB. (I really hope that, if it is possible, Arch Linux official installation ISO will contain at least “base” group, so that it is possible to install a minimal OS without network connection.)

After installing everything, I made sure that the original OS and Arch Linux are bootable through GRUB.

Then the essential part is transferring the whole data from old computer to new computer. Firstly, I need to transfer the data from old to an external harddisk. Thus, I used the following command in old computer (based on this page),

tar -czpvf backup.tar.gz --one-file-system --exclude=/backup.tar.gz \
--exclude=/dev --exclude=/tmp --exclude=/sys --exclude=/proc \
--exclude=/mnt --exclude=/media --exclude=/boot \
--exclude=/etc/{hostname,fstab,localtime,locale.conf,vconsole.conf} /
#exclude any folder that we don't want

Tar is the best solution (for me) to preserve all the file permission and ownership. Besides that, tar also allows to compress the data (with gz). If the size doesn’t matter, we can omit the “-z” flag and the file can be named as “backup.tar” without “.gz” suffix. So, several directories (folders) are excluded, because these may be computer dependent. The /boot must be excluded, because the partitions of the computers are different. And finally some files in /etc needs to be excluded. These files are actually the files which we need to edit during the installation of the Arch Linux, especially fstab. (That is why I said luckily Arch Linux is minimalistic.) Then, use the same method to backup the /home and any other data.

Next, to extract the data from the tar, I didn’t use the Arch Linux in the new computer itself. This is because I afraid that overwriting some of the files (especially the running process) are not allowed or causing damage of the system. Thus, I use SystemRescueCD and mount the root partition of Arch Linux, Then,

tar -xzpvf backup.tar.gz -C /mnt/arch --numeric-owner

Then, I also use the same way to extract other data.

Finally, restart. Everything work fine. The only thing I need to reconfigure is the /etc/suspend.conf from uswsusp-git because of the partition differences. Besides that, I also reset the pacman-key as mentioned here.

7 thoughts on “Change a computer but preserve the OS (Arch Linux) and data

  1. I could have sworn that Linux rebuilds the HAL every time it boots. I have Ubuntu on a portable USB drive and I’ve never had any problems booting it on other desktops, laptops, servers! Why the convoluted process on Arch Linux?

    1. @Anthony, because I am not using portable OS. I am installing Arch Linux to another computer different model, but I want to preserve all the configurations. Do you have any better way?

      1. When I get a new machine and as long as I want to keep my existing system as I’ve configured it, I simply remove the hard drive from old system and plug into new system. Since the HAL is built on each boot, the OS will simply detect the new changes and proceed; I’m yet to find a system where this USB drive will not boot – from Dell PowerEdge servers to Dell/Lenovo Laptops, they just boot! The only thing I normally have to change are the firewall and config files that reference the old MAC address. Other than that, it just works!

        The OS on the USB drive was actually my daily driver at one time (Ubuntu 8.04 LTS), its capacity was rather tiny so I relegated it to external SATA case and now use it as a recovery system/tool either for one of my other systems or when a friend comes calling.


  2. Also, since I have a spare hard drive in a case, I’ll install Arch Linux (something I’ve been intending to do) and see if I can replicate the success I’ve had with Hardy Heron booting on any system.

    I’ve recently installed Arch as a VM (VirtualBox) and I’ve got to say I like the simplicity!


    1. The problem is, the laptop is used, and non personal property. So, I cannot simply switch the hard drive. That is why I need to install everything to a new computer with new hard drive and preserve the default OS by partitioning the hard drive. For me, portable OS is not a good solution, because it is using FAT32.

      1. Remember, mine was not a portable OS; it was initially my laptop internal hard drive and when changed laptops, the new hdd was significantly bigger than old. As such, the now external USB drive is fully partitioned and using ext3 for /boot and ext4 for all other partitions (/, /opt, and /home).

        Another option for you – boot both new and old system using partedmagic live dvd, then use clonezilla to migrate the entire hard drive. As long as the new drive is bigger than the old, then all should be good. You can then use gparted to increase the partition sizes to fill up the new hard drive.


      2. Thanks. As I mentioned in the post, I want to preserve the OS of the hdd. Because of the partition is different, clonezilla cannot work in my case. Not only that, I want different size of partitions, what I want to preserve are only the installed packages and the configurations. Therefore, I don’t think your suggestion can solve my problem.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s